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
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.
-
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