-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MinimumPrice] Handle minimum price cart #13291
Conversation
f920173
to
1607091
Compare
src/Sylius/Component/Core/Promotion/Action/UnitDiscountPromotionActionCommand.php
Outdated
Show resolved
Hide resolved
And probably you missed scenario with distributing discount on the product with minimum price and without it. |
...s/promotion/applying_promotion_rules/receiving_discount_with_minimum_price_specified.feature
Outdated
Show resolved
Hide resolved
...s/promotion/applying_promotion_rules/receiving_discount_with_minimum_price_specified.feature
Outdated
Show resolved
Hide resolved
...s/promotion/applying_promotion_rules/receiving_discount_with_minimum_price_specified.feature
Outdated
Show resolved
Hide resolved
...s/promotion/applying_promotion_rules/receiving_discount_with_minimum_price_specified.feature
Outdated
Show resolved
Hide resolved
...romotion/receiving_discount/receiving_discounts_with_product_minimum_price_specified.feature
Show resolved
Hide resolved
src/Sylius/Component/Core/Promotion/Action/UnitDiscountPromotionActionCommand.php
Outdated
Show resolved
Hide resolved
src/Sylius/Component/Core/Promotion/Action/UnitDiscountPromotionActionCommand.php
Outdated
Show resolved
Hide resolved
...romotion/receiving_discount/receiving_discounts_with_product_minimum_price_specified.feature
Outdated
Show resolved
Hide resolved
...romotion/receiving_discount/receiving_discounts_with_product_minimum_price_specified.feature
Outdated
Show resolved
Hide resolved
...res/promotion/applying_promotion_coupon/applying_promotion_coupon_with_minimum_price.feature
Outdated
Show resolved
Hide resolved
...romotion/receiving_discount/receiving_discounts_with_product_minimum_price_specified.feature
Show resolved
Hide resolved
...romotion/receiving_discount/receiving_discounts_with_product_minimum_price_specified.feature
Outdated
Show resolved
Hide resolved
1dcd250
to
9696f75
Compare
...romotion/receiving_discount/receiving_discounts_with_product_minimum_price_specified.feature
Show resolved
Hide resolved
src/Sylius/Bundle/CoreBundle/Resources/config/services/promotion.xml
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/CoreBundle/Resources/config/services/promotion.xml
Outdated
Show resolved
Hide resolved
src/Sylius/Component/Core/Promotion/Action/UnitFixedDiscountPromotionActionCommand.php
Outdated
Show resolved
Hide resolved
src/Sylius/Component/Core/spec/Promotion/Applicator/UnitsPromotionAdjustmentsApplicatorSpec.php
Outdated
Show resolved
Hide resolved
...romotion/receiving_discount/receiving_discounts_with_product_minimum_price_specified.feature
Outdated
Show resolved
Hide resolved
...romotion/receiving_discount/receiving_discounts_with_product_minimum_price_specified.feature
Show resolved
Hide resolved
src/Sylius/Component/Core/Promotion/Action/UnitDiscountPromotionActionCommand.php
Outdated
Show resolved
Hide resolved
582b879
to
735aea2
Compare
...romotion/receiving_discount/receiving_discounts_with_product_minimum_price_specified.feature
Outdated
Show resolved
Hide resolved
} | ||
|
||
$splitPromotion = $this->proportionalDistributor->distribute($itemsTotals, $promotionAmount); | ||
$this->distributeWithMinimumPrice($splitPromotion, $itemsTotals, $minimumPrices); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we put this logic inside of proportionalDistributor with an additional, third argument? Part of me also is thinking about VO slowly :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i didnt really wanted to touch this place, this is just another implementation, just additional step which handles all minimum price tasks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue with this implementation is that it won't work out-of-the-box for any existent and new implementation if we won't remember about this method. Relaying on dev knowledge and memory is a route downhill. I would vote for adjusting the namespace or introducing a new one and implement here both of them with bc layer and deprecation of the old usage
|
||
$minimumPrice = $variant->getChannelPricingForChannel($channel)->getMinimumPrice(); | ||
|
||
$adjustment->setAmount($this->calculate($unit->getTotal(), $minimumPrice, -$amount)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if this should not be extracted logic - assigning/calculating amount of x or variants minimal price
@@ -82,4 +90,13 @@ private function addAdjustment(PromotionInterface $promotion, OrderItemUnitInter | |||
|
|||
$unit->addAdjustment($adjustment); | |||
} | |||
|
|||
private function calculate(int $itemTotal, int $minimumPrice, int $promotionAmount): int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And now, I'm 100% sure it should be separated service
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i had different service to handle calculations, but @GSadee said its a BC break so i decided to leave it in private methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at your PR and #13325 it appears to me, that some extraction of this logic would be beneficial. Even in your PR it is present twice and has exactly same reason to exist and change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that extraction would be recommended, but in what way to avoid breaking a BC promise?
...Sylius/Component/Core/spec/Promotion/Action/PercentageDiscountPromotionActionCommandSpec.php
Outdated
Show resolved
Hide resolved
src/Sylius/Component/Core/spec/Promotion/Action/UnitFixedDiscountPromotionActionCommandSpec.php
Outdated
Show resolved
Hide resolved
aaaa365
to
0837e4d
Compare
a5f3dac
to
0b4ba14
Compare
0b4ba14
to
4cf2f27
Compare
$splitPromotion = array_merge($distributionData['distributedPromotion'], $splitPromotion); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Sylius/Component/Core/Promotion/Action/FixedDiscountPromotionActionCommand.php
Outdated
Show resolved
Hide resolved
src/Sylius/Component/Core/Promotion/Action/DiscountPromotionActionCommand.php
Outdated
Show resolved
Hide resolved
src/Sylius/Component/Core/Promotion/Action/DiscountPromotionActionCommand.php
Outdated
Show resolved
Hide resolved
src/Sylius/Component/Core/Promotion/Action/FixedDiscountPromotionActionCommand.php
Outdated
Show resolved
Hide resolved
729d98b
to
cf9c86c
Compare
cf9c86c
to
d064dd0
Compare
src/Sylius/Component/Core/Promotion/Action/FixedDiscountPromotionActionCommand.php
Outdated
Show resolved
Hide resolved
} | ||
|
||
return array_values(array_map( | ||
function (array $processedOrderItem): int { return $processedOrderItem['promotion']; }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably we could use arrow functions here and below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, we could use it here but it could be done in other PR as part of refactor.
db86ccc
to
5a6c9d0
Compare
@@ -16,6 +16,11 @@ Please note that those priorities are being executed in ascending order. You can | |||
Be aware that if those priorities were customized, this would lead to problems. | |||
You should check and adjust priorities on your application. | |||
|
|||
### Minimum price & Promotions | |||
|
|||
We added MinimumPrice to channelPricings entity, this price should be taken into account when customizing any promotions in Sylius. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We added MinimumPrice to channelPricings entity, this price should be taken into account when customizing any promotions in Sylius. | |
We added minimum price to the ChannelPricing entity, this price should be taken into account when customizing any promotions in Sylius. |
Thank you, @SirDomin! 🥇 |
Based on: #13266