1

I am a beginner with Magento 2 and need some help with creating a new rule for cart price rules. The rule should check if any discount or previously set cart price rule was already applied to the cart items and if it was, next rule should be excluded (not applied to the cart).

1 Answer 1

1

You can check this using below code.

public function __construct(
        ...
        \Magento\Checkout\Model\Session $session
        ...
    ) {
        ...
        $this->session = $session;
        ...
    }

public function yourFunction()
{
    if($this->session->getQuote()->getAppliedRuleIds()) {
       echo "rule applied";
    } else {
       echo " no rule applied"
    }
}

let me know if you need further help.

1
  • Good info, do you know how to check the amount is Discount in cart ? or if I can getBaseGrandTotal including discount as I $this->getQuote()->getBaseGrandTotal() is giving me discounted Commented Mar 4, 2020 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.