I have created a custom cart rule "Percent of product original price discount
"
I am checking If coupon discount is better deal than special price for the customer then to use the coupon discounted price
/** @var \Magento\SalesRule\Model\Rule\Action\Discount\Data $discountData */
$discountData = $this->discountFactory->create();
//If coupon discount is better deal than special price for the customer then to use the coupon discounted price
if ($itemPrice > $originalpricewithdiscount || $baseItemPrice > $originalbasepricewithdiscount) {
//Here i set discount
} elseif ($itemPrice == $itemOriginalPrice) { //Products with no special price
//Here i set discount
}
if ($discountData->getAmount() < 1){ //Here i check if dicount is 0 then throw exception. **(ISSUE - WHEN A COUPON IS APPLIED ON CART, THEN I TRY TO ADD PRODUCT WHICH IS NOT ELIGIBLE FOR DISCOUNT THEN DISCOUNT IS 0 & THAT'S WHY THIS EXCEPTION APPEARS ON ADD TO CART ALSO.)**
throw new \Magento\Framework\Exception\LocalizedException(__("The Gift Card or Promo Code couldn't be applied. Verify and try again"));
}
return $discountData;
(ISSUE - WHEN A COUPON IS APPLIED ON CART, THEN I TRY TO ADD PRODUCT WHICH IS NOT ELIGIBLE FOR DISCOUNT THEN DISCOUNT IS 0 & THAT'S WHY THIS EXCEPTION APPEARS ON ADD TO CART ALSO.)
Please advise me some thoughts on this to make it work