Zend certified PHP/Magento developer

Exclude product from cart rules if product have catalog rules

If there are 2 items in the cart (A, and B) and there are 2 discount
rules first is catalog price rules on product A which is 5% discount and
another one is the cart price rule which is 5% discount.

I want that cart price rule only applied on product B price and I want to exclude product A from this rule.

For That, I override this file vendor/magento/module-sales-rule/Model/RulesApplier.php

in this file I override this function setDiscountData

and here I added item check validation in function

protected function setDiscountData($discountData, $item)
    {
        $checkResult=$this->checkProductRule->getCatalogPriceRuleFromProduct(
            $item->getProduct()->getId(),
            $this->getCustomerGroupId()
        );
        if ($checkResult == 0) {               
            $item->setDiscountAmount($discountData->getAmount());
            $item->setBaseDiscountAmount($discountData->getBaseAmount());
            $item->setOriginalDiscountAmount($discountData->getOriginalAmount());
            $item->setBaseOriginalDiscountAmount($discountData->getBaseOriginalAmount());
        }
        return $this;
    }

If the catalog product discount is 0 then it will apply the cart price rule and it’s working fine. but When I come to the checkout page then it’s working as the default behavior.

On the checkout page for coupons, it’s calling API which has only applied coupon code.

Please let me know what I missing here.