Skip to content
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

Merged
merged 17 commits into from
Dec 8, 2021

Conversation

SirDomin
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets
License MIT

Based on: #13266

@SirDomin SirDomin requested a review from a team as a code owner November 12, 2021 00:18
@probot-autolabeler probot-autolabeler bot added Admin AdminBundle related issues and PRs. API APIs related issues and PRs. labels Nov 12, 2021
@SirDomin SirDomin force-pushed the handle-minimum-price-cart branch 8 times, most recently from f920173 to 1607091 Compare November 17, 2021 12:38
@AdamKasp
Copy link
Contributor

And probably you missed scenario with distributing discount on the product with minimum price and without it.

@SirDomin SirDomin force-pushed the handle-minimum-price-cart branch 4 times, most recently from 1dcd250 to 9696f75 Compare November 22, 2021 15:40
@SirDomin SirDomin force-pushed the handle-minimum-price-cart branch 3 times, most recently from 582b879 to 735aea2 Compare November 24, 2021 15:20
src/Sylius/Behat/Context/Api/Shop/CartContext.php Outdated Show resolved Hide resolved
src/Sylius/Behat/Context/Api/Shop/CartContext.php Outdated Show resolved Hide resolved
src/Sylius/Behat/Context/Api/Shop/OrderContext.php Outdated Show resolved Hide resolved
}

$splitPromotion = $this->proportionalDistributor->distribute($itemsTotals, $promotionAmount);
$this->distributeWithMinimumPrice($splitPromotion, $itemsTotals, $minimumPrices);
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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));
Copy link
Member

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
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Member

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?

@SirDomin SirDomin force-pushed the handle-minimum-price-cart branch 4 times, most recently from aaaa365 to 0837e4d Compare November 24, 2021 23:02
@SirDomin SirDomin force-pushed the handle-minimum-price-cart branch 2 times, most recently from a5f3dac to 0b4ba14 Compare November 30, 2021 11:13
$splitPromotion = array_merge($distributionData['distributedPromotion'], $splitPromotion);
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

@probot-autolabeler probot-autolabeler bot added the Maintenance CI configurations, READMEs, releases, etc. label Dec 7, 2021
}

return array_values(array_map(
function (array $processedOrderItem): int { return $processedOrderItem['promotion']; },
Copy link
Member

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

Copy link
Contributor Author

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.

@@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@GSadee GSadee merged commit 57f9ac0 into Sylius:master Dec 8, 2021
@GSadee
Copy link
Member

GSadee commented Dec 8, 2021

Thank you, @SirDomin! 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Admin AdminBundle related issues and PRs. API APIs related issues and PRs. Maintenance CI configurations, READMEs, releases, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants