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
3efa2415
Valider
3efa2415
rédigé
il y a 7 mois
par
Mohamed Lemine BAILLAHI
Parcourir les fichiers
Options
Téléchargements
Plain Diff
Merge branch 'feature/
MYD-467
-v2' into 'develop'
changes in apply promo code to cart See merge request
!75
parents
e26e332f
a0d8a5c5
Branches
Branches contenant la validation
2 requêtes de fusion
!82
add gift card to cart delete and duplicate gift card in cart
,
!75
changes in apply promo code to cart
Pipeline
#8166
en échec avec les étapes
in 23 secondes
Modifications
2
Pipelines
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
CHANGELOG.md
+15
-0
15 ajouts, 0 suppression
CHANGELOG.md
src/main/java/com/marketingconfort/mydressin/services/impl/PromoCodeUtilServiceImpl.java
+53
-19
53 ajouts, 19 suppressions
...ort/mydressin/services/impl/PromoCodeUtilServiceImpl.java
avec
68 ajouts
et
19 suppressions
CHANGELOG.md
+
15
−
0
Voir le fichier @
3efa2415
## [1.0.57-RELEASE]
### Added
-
changes in apply promo code to cart.
### Changed
-
Changes in existing function.
### Deprecated
-
Soon-to-be removed features.
### Removed
-
Features that have been removed.
### Fixed
-
Any bug fixes.
## [1.0.56-RELEASE]
### Added
-
Add new conditions in apply promo code to cart.
...
...
This diff is collapsed.
Click to expand it.
src/main/java/com/marketingconfort/mydressin/services/impl/PromoCodeUtilServiceImpl.java
+
53
−
19
Voir le fichier @
3efa2415
...
...
@@ -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