Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
M
mydressin-cart-service
Gestion
Activité
Membres
Labels
Programmation
Tickets
0
Tableaux des tickets
Jalons
Wiki
Jira
Code
Requêtes de fusion
0
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Service d'assistance
Analyse
Données d'analyse des chaînes de valeur
Contributor analytics
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
mydressin
mydressin-cart-service
Validations
1f825fc4
Valider
1f825fc4
rédigé
il y a 7 mois
par
chaimaa hassoune
Parcourir les fichiers
Options
Téléchargements
Plain Diff
Merge branch 'develop' into 'feature/
MYD-655
'
# Conflicts: # CHANGELOG.md
parents
2c1e9c79
3efa2415
Branches
feature/MYD-655
1 requête de fusion
!76
calculate THEORETICAL_TURNOVER
Pipeline
#8310
réussi avec les étapes
in 1 minute et 3 secondes
Modifications
1
Pipelines
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
src/main/java/com/marketingconfort/mydressin/services/impl/PromoCodeUtilServiceImpl.java
+53
-19
53 ajouts, 19 suppressions
...ort/mydressin/services/impl/PromoCodeUtilServiceImpl.java
avec
53 ajouts
et
19 suppressions
src/main/java/com/marketingconfort/mydressin/services/impl/PromoCodeUtilServiceImpl.java
+
53
−
19
Voir le fichier @
1f825fc4
...
...
@@ -45,12 +45,23 @@ public class PromoCodeUtilServiceImpl implements PromoCodeUtilService {
return
cartDTO
;
}
List
<
PromoCodeDTO
>
promoCodeDTOList
=
externalApiService
.
getPromoCodesByIds
(
cartDTO
.
getPromoCodeIds
());
boolean
containsOnlyGiftCards
=
cartDTO
.
getItems
().
stream
()
.
allMatch
(
item
->
item
.
getProductType
()
==
ProductType
.
GIFT_CARD
);
if
(
containsOnlyGiftCards
)
{
logger
.
info
(
"Cart contains only Gift Cards. No promo code will be applied."
);
return
cartDTO
;
}
List
<
PromoCodeDTO
>
promoCodeDTOList
=
externalApiService
.
getPromoCodesByIds
(
cartDTO
.
getPromoCodeIds
());
double
finalTotalCartDiscount
=
0.0
;
for
(
PromoCodeDTO
promoCodeDTO
:
promoCodeDTOList
)
{
long
acceptedItemsCount
=
cartDTO
.
getItems
().
stream
()
.
filter
(
item
->
isItemIncludedOrExcluded
(
item
,
promoCodeDTO
))
.
count
();
double
promoCodeTotalCartDiscount
=
0.0
;
switch
(
promoCodeDTO
.
getPromoCodeType
())
{
...
...
@@ -58,11 +69,13 @@ public class PromoCodeUtilServiceImpl implements PromoCodeUtilService {
promoCodeTotalCartDiscount
=
applyDiscountPerCart
(
promoCodeDTO
,
cartDTO
);
if
(
promoCodeTotalCartDiscount
>
0
)
{
for
(
ItemCartDTO
item
:
cartDTO
.
getItems
())
{
double
itemDiscount
=
promoCodeTotalCartDiscount
/
cartDTO
.
getItems
().
size
();
if
(
itemDiscount
>
0
)
{
double
newTotalPrice
=
item
.
getTotalPrice
()
-
itemDiscount
;
item
.
setTotalPrice
(
Math
.
max
(
newTotalPrice
,
0.0
));
item
.
setPromoCodeDiscounts
(
item
.
getPromoCodeDiscounts
()
+
itemDiscount
);
if
(
item
.
getProductType
()
!=
ProductType
.
GIFT_CARD
)
{
double
itemDiscount
=
promoCodeTotalCartDiscount
/
acceptedItemsCount
;
if
(
itemDiscount
>
0
)
{
double
newTotalPrice
=
item
.
getTotalPrice
()
-
itemDiscount
;
item
.
setTotalPrice
(
Math
.
max
(
newTotalPrice
,
0.0
));
item
.
setPromoCodeDiscounts
(
item
.
getPromoCodeDiscounts
()
+
itemDiscount
);
}
}
}
}
...
...
@@ -71,11 +84,13 @@ public class PromoCodeUtilServiceImpl implements PromoCodeUtilService {
promoCodeTotalCartDiscount
=
applyPercentagePerCart
(
promoCodeDTO
,
cartDTO
);
if
(
promoCodeTotalCartDiscount
>
0
)
{
for
(
ItemCartDTO
item
:
cartDTO
.
getItems
())
{
double
itemDiscount
=
promoCodeTotalCartDiscount
/
cartDTO
.
getItems
().
size
();
if
(
itemDiscount
>
0
)
{
double
newTotalPrice
=
item
.
getTotalPrice
()
-
itemDiscount
;
item
.
setTotalPrice
(
Math
.
max
(
newTotalPrice
,
0.0
));
item
.
setPromoCodeDiscounts
(
item
.
getPromoCodeDiscounts
()
+
itemDiscount
);
if
(
item
.
getProductType
()
!=
ProductType
.
GIFT_CARD
)
{
double
itemDiscount
=
promoCodeTotalCartDiscount
/
acceptedItemsCount
;
if
(
itemDiscount
>
0
)
{
double
newTotalPrice
=
item
.
getTotalPrice
()
-
itemDiscount
;
item
.
setTotalPrice
(
Math
.
max
(
newTotalPrice
,
0.0
));
item
.
setPromoCodeDiscounts
(
item
.
getPromoCodeDiscounts
()
+
itemDiscount
);
}
}
}
}
...
...
@@ -139,6 +154,11 @@ public class PromoCodeUtilServiceImpl implements PromoCodeUtilService {
@Override
public
boolean
isItemIncludedOrExcluded
(
ItemCartDTO
item
,
PromoCodeDTO
promoCodeDTO
)
{
if
(
item
.
getProductType
()
==
ProductType
.
GIFT_CARD
)
{
logger
.
info
(
"Item with ID {} is a gift card and excluded from promo code."
,
item
.
getProductId
());
return
false
;
}
boolean
isExcluded
=
false
;
boolean
isIncluded
=
false
;
...
...
@@ -229,10 +249,12 @@ public class PromoCodeUtilServiceImpl implements PromoCodeUtilService {
totalPriceAfterDiscount
=
totalPriceBeforeDiscount
-
discount
;
if
(
discount
>
0
)
{
for
(
ItemCartDTO
item
:
cart
.
getItems
())
{
double
itemDiscount
=
discount
/
cart
.
getItems
().
size
();
item
.
setTotalPrice
(
item
.
getTotalPrice
()
-
itemDiscount
);
item
.
setPromoCodeDiscounts
(
item
.
getPromoCodeDiscounts
()
+
itemDiscount
);
totalPriceAfterDiscount
+=
itemDiscount
;
if
(!(
item
.
getProductType
().
equals
(
ProductType
.
GIFT_CARD
)))
{
double
itemDiscount
=
discount
/
cart
.
getItems
().
size
();
item
.
setTotalPrice
(
item
.
getTotalPrice
()
-
itemDiscount
);
item
.
setPromoCodeDiscounts
(
item
.
getPromoCodeDiscounts
()
+
itemDiscount
);
totalPriceAfterDiscount
+=
itemDiscount
;
}
}
}
}
...
...
@@ -241,10 +263,12 @@ public class PromoCodeUtilServiceImpl implements PromoCodeUtilService {
totalPriceAfterDiscount
=
totalPriceBeforeDiscount
-
discount
;
if
(
discount
>
0
)
{
for
(
ItemCartDTO
item
:
cart
.
getItems
())
{
double
itemDiscount
=
discount
/
cart
.
getItems
().
size
();
item
.
setTotalPrice
(
item
.
getTotalPrice
()
-
itemDiscount
);
item
.
setPromoCodeDiscounts
(
item
.
getPromoCodeDiscounts
()
+
itemDiscount
);
totalPriceAfterDiscount
+=
itemDiscount
;
if
(!(
item
.
getProductType
().
equals
(
ProductType
.
GIFT_CARD
)))
{
double
itemDiscount
=
discount
/
cart
.
getItems
().
size
();
item
.
setTotalPrice
(
item
.
getTotalPrice
()
-
itemDiscount
);
item
.
setPromoCodeDiscounts
(
item
.
getPromoCodeDiscounts
()
+
itemDiscount
);
totalPriceAfterDiscount
+=
itemDiscount
;
}
}
}
}
...
...
@@ -274,6 +298,11 @@ public class PromoCodeUtilServiceImpl implements PromoCodeUtilService {
@Override
public
double
applyDiscountPerProduct
(
PromoCodeDTO
promoCodeDTO
,
ItemCartDTO
item
)
{
if
(
item
.
getProductType
()
==
ProductType
.
GIFT_CARD
)
{
logger
.
info
(
"Item with ID {} is a gift card and excluded from discount."
,
item
.
getProductId
());
return
0.0
;
}
if
(!
isItemIncludedOrExcluded
(
item
,
promoCodeDTO
))
{
logger
.
info
(
"Item with ID {} is not eligible for discount."
,
item
.
getProductId
());
return
0.0
;
...
...
@@ -298,6 +327,11 @@ public class PromoCodeUtilServiceImpl implements PromoCodeUtilService {
@Override
public
double
applyDiscountPerCart
(
PromoCodeDTO
promoCodeDTO
,
CartDTO
cart
)
{
if
(
cart
.
getItems
().
stream
().
anyMatch
(
item
->
item
.
getProductType
()
==
ProductType
.
GIFT_CARD
))
{
logger
.
info
(
"Cart contains gift cards, which are excluded from discount."
);
return
0.0
;
}
if
(
promoCodeDTO
.
getMinAmount
().
compareTo
(
BigDecimal
.
valueOf
(
cart
.
getTotalPrice
()).
setScale
(
2
,
RoundingMode
.
HALF_UP
))
>
0
)
{
logger
.
info
(
"Cart total does not meet the minimum required amount for discount."
);
return
0.0
;
...
...
This diff is collapsed.
Click to expand it.
Aperçu
0%
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter