The issue is reproduced on Magento CE 2.3.1.
To reproduce, we need two rules with coupon applied and another without coupon.
because of the Smile\MultiCoupon\Model\Quote\Discount, the rule without coupon is applied twice.
Two solutions I see :
Either we change the way to apply several coupons.
Or we check when applying a rule that the rule is not already applied.
I coded the second solution because faster, but not sure that it is the best solution.
`<?php
namespace Smile\MultiCoupon\Plugin\Model;
use Magento\Quote\Model\Quote\Address;
use Magento\SalesRule\Model\Rule;
use Magento\SalesRule\Model\Utility as Subject;
class Utility
{
/**
After can process rule.
Check if the rule has already been applied.
@param Subject $utility
@param $result
@param Rule $rule
@param Address $address
@return bool
@SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterCanProcessRule(Subject $utility, $result, $rule, $address)
{
return $result && !$this->isRuleAlreadyApplied($rule, $address);
}
/**
Is rule already applied ?
@param Rule $rule
@param Address $address
@return bool
*/
protected function isRuleAlreadyApplied($rule, $address)
{
$rulesIds = explode(',', $address->getAppliedRuleIds());
return in_array($rule->getRuleId(), $rulesIds);
}
}
`
Tell me what do you think ?
Thanks,
Pierre
Hi,
The issue is reproduced on Magento CE 2.3.1. To reproduce, we need two rules with coupon applied and another without coupon. because of the Smile\MultiCoupon\Model\Quote\Discount, the rule without coupon is applied twice. Two solutions I see : Either we change the way to apply several coupons. Or we check when applying a rule that the rule is not already applied. I coded the second solution because faster, but not sure that it is the best solution. `<?php namespace Smile\MultiCoupon\Plugin\Model;
use Magento\Quote\Model\Quote\Address; use Magento\SalesRule\Model\Rule; use Magento\SalesRule\Model\Utility as Subject;
class Utility { /**
@SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterCanProcessRule(Subject $utility, $result, $rule, $address) { return $result && !$this->isRuleAlreadyApplied($rule, $address); }
/**