-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Cart price rules - Incorrect discount percent calculation when applying 2 and more sales rules by percent #37591
Comments
Hi @3dWaRdeJ. Thank you for your report.
Join Magento Community Engineering Slack and ask your questions in #github channel. |
Hi @engcom-Dash. Thank you for working on this issue.
|
@magento give me 2.4-develop instance |
Hi @engcom-November. Thank you for your request. I'm working on Magento instance for you. |
Hi @engcom-November, here is your Magento Instance: https://936ec08db9548742a54d651f4086fd5e.instances-prod.magento-community.engineering |
Hi @engcom-Hotel. Thank you for working on this issue.
|
Hello @dmrkato, Thanks for the report and collaboration! We tried to reproduce the issue in the 2.4-develop branch and it seems the issue is reproducible for us. Please find below the screenshot for reference: We have created a custom module in order to reproduce the issue. Please find below the same: Hence confirming the issue. Thanks |
✅ Jira issue https://jira.corp.adobe.com/browse/AC-9120 is successfully created for this GitHub issue. |
✅ Confirmed by @engcom-Hotel. Thank you for verifying the issue. |
Does anyone work on this issue? |
I don't know, in the task description I wrote a possible solution in the Addition information section Need to write fix for calculation formula in Magento\SalesRule\Model\Rule\Action\Discount\ByPercent P.S. @mcspronko thx for your videos on YouTube helped me a lot |
I can write a solution |
@dmrkato that would be great. |
Preconditions and environment
Steps to reproduce
1.1 Go to the admin panel
1.2 Go to Store -> Attributes -> Product
1.3 Find the SKU product attribute and edit it
1.4 Select Use for Promo Rule Conditions field to Yes value
1.5 Save
2.1 Go to Marketing -> Promotions -> Cart Price Rules -> Add New Rule
2.2 In Rule information section
2.2.1 For Coupon field select No coupon value
2.2.2 For Priority input 0 value
2.3 In Actions section
2.3.1 For Apply field select Percent of product price discount
2.3.2 For Discount Amount field set 50 value
2.3.3 Switch Discard subsequent rules to No value (need to apply few sales rules)
3. Create a second sales rule which applies 50% discount for specific cart item by using coupon code
3.1 Go to Marketing -> Promotions -> Cart Price Rules -> Add New Rule
3.2 In Rule information section
3.2.1 For Coupon field select Specific coupon value
3.2.2 Set Coupon code field 1234
3.2.3 For Priority input 1 value
3.3 In Actions section
3.3.1 For Apply field select Percent of product price discount
3.3.2 For Discount Amount field set 50 value
3.3.3 Fill Apply the rule only to cart items matching the following conditions to apply discount for specific product by SKU
<type name="Magento\Weee\Block\Item\Price\Renderer"> <plugin name="test_plugin_add_discount_amount_and_percent" type="Test\Test\Plugin\Tax\Block\Item\Price\RendererPlugin"/> </type>
`<?php
declare(strict_types=1);
namespace Test\Test\Plugin\Tax\Block\Item\Price;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Quote\Model\Quote\Item\AbstractItem as QuoteItem;
use Magento\Tax\Block\Item\Price\Renderer;
class RendererPlugin
{
public function __construct(
private readonly PriceCurrencyInterface $priceCurrency
) {
}
}`
Expected result
On product applies 2 discount rules each have 50% discount so in general in must be 75%
Actual result
Discount amount calculate correct - 750$
but Discount % calculate incorect it is 100%
Additional information
I find a possible solution for this issue
Need to update method _calculate in class Magento\SalesRule\Model\Rule\Action\Discount\ByPercent on 71 line
now code calculating $discountPercent just simply add a discount percent
$discountPercent = min(100, $item->getDiscountPercent() + $rulePercent);
and if update this line to
$discountPercent = min( 100, $item->getDiscountPercent() > 0 ? $item->getDiscountPercent() + (1-$item->getDiscountPercent()) * $_rulePct : $rulePercent );
the calculation will be correct
so method code must be like
`protected function _calculate($rule, $item, $qty, $rulePercent)
{
/** @var \Magento\SalesRule\Model\Rule\Action\Discount\Data $discountData */
$discountData = $this->discountFactory->create();
Release note
No response
Triage and priority
The text was updated successfully, but these errors were encountered: