I have overridden the below function for business logic(Want to exclude a product from cart rule which has catalog rule applied on the product) and it's working fine on the cart page
vendor/magento/module-sales-rule/Model/RulesApplier.php
Function Name setDiscountData
$discountAmount=$catalogrulecheck->getCatalogPriceRuleFromProduct($item->getProduct()->getId(),$customerGroupId);
if($discountAmount ==0) {
$item->setDiscountAmount($discountData->getAmount());
$item->setBaseDiscountAmount($discountData->getBaseAmount());
$item->setOriginalDiscountAmount($discountData->getOriginalAmount());
$item->setBaseOriginalDiscountAmount($discountData->getBaseOriginalAmount());
return $this;
}
but when I come to the checkout page then it's loading functionality from the core file, not from the override module.
I tried to override applyRules
function from the same file
public function applyRules($item, $rules, $skipValidation, $couponCode)
{
$address = $item->getAddress();
$appliedRuleIds = [];
$this->discountAggregator = [];
/* @var $rule Rule */
foreach ($rules as $rule) {
if (!$this->validatorUtility->canProcessRule($rule, $address)) {
continue;
}
if (!$skipValidation && !$rule->getActions()->validate($item)) {
if (!$this->childrenValidationLocator->isChildrenValidationRequired($item)) {
continue;
}
$childItems = $item->getChildren();
$isContinue = true;
if (!empty($childItems)) {
foreach ($childItems as $childItem) {
if ($rule->getActions()->validate($childItem)) {
$isContinue = false;
}
}
}
if ($isContinue) {
continue;
}
}
$this->applyRule($item, $rule, $address, $couponCode);
$appliedRuleIds[$rule->getRuleId()] = $rule->getRuleId();
if ($rule->getStopRulesProcessing()) {
break;
}
}
return $appliedRuleIds;
}
it's also working in the cart but when I come to the checkout page that time it's loading from the core file
Below are the di.xml
file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/framework/ObjectManager/etc/config.xsd">
<preference for="Magento\SalesRule\Model\RulesApplier" type="[Vendor]\[Module]\Model\RulesApplier"/>
</config>
Please let me know what's wrong with this.