I have using Magento\SalesRule\Model\RulesApplier Plugin. Using aroundApplyRules method need to get current cart subtotal. I have need customisation to validate condition for cart subtotal with cart price rule subtotal. But getting every time previous quote subtotal.

When add to cart product first time then getting subtotal 0 after second time add to cart product then getting previous cart subtotal. But not getting every time current cart total.


<type name="Magento\SalesRule\Model\RulesApplier">
        <plugin name="curent_cart_subtotal_collection"
                type="Custom\Module\Plugin\SalesRule\Model\RulesApplier" sortOrder="1"/>


public function aroundApplyRules( 
    SalesRulesApplier $subject,
    Closure          $proceed,
) {

 public function __construct(        
        \Magento\Checkout\Model\Cart $cart,
        \Magento\Checkout\Model\Session  $checkoutSession
    ) {
        $this->cart            = $cart;
        $this->checkoutSession = $checkoutSession;

    $subTotal = $this->checkoutSession->getQuote()->getSubtotal();
   // $subTotal = $this->cart->getQuote()->getSubtotal();

    return $proceed($item, $rules, $skipValidation, $couponCode);

  • if you have an around plugin and you don't execute the original method first, you won't get the new subtotal. try calling $proceed(...) first and see what happens
    – Marius
    Commented Mar 1, 2023 at 9:03
  • @Marius yes I am calling $proceed(...) method return $proceed($item, $rules, $skipValidation, $couponCode); I have updated in code. Commented Mar 1, 2023 at 9:09
  • not sure what the problem is here...you say you get the subtotal before the rules are applies? this is normal behavior, I think. You first get the subtotal and then you apply the original method. it's normal to get a wrong sutotal initially
    – Marius
    Commented Mar 1, 2023 at 11:14
  • First time add to cart product subtotal is getting 0. I need subtotal every time when product add to cart with correct subtotal. I have updated details, Please read my question again. Commented Mar 3, 2023 at 11:01


Your Answer

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

Browse other questions tagged or ask your own question.