0

I need to give Quote Item level manual Discount for selected cart items. After giving discount Cart Item row total will change. As can't modify the product price so custom price solution is also not working.

I tried with a new discount total but it gives a discount on the whole cart.

Anyone, please suggest the best approach for giving a discount on Cart item level without modifying product price.

  • hello @Panakj, got solution for it? – jafar pinjar Jul 30 at 10:52
0

You can create a plugin for Magento\SalesRule\Model\Validator::process -

    class Myplugin
       {

        protected $discountFactory;

        public function __construct(\Magento\SalesRule\Model\Rule\Action\Discount\DataFactory $discountFactory){
        $this->discountFactory = $discountFactory;
    }

    public function aroundProcess(
        \Magento\SalesRule\Model\Validator $subject,
        \Closure $proceed,
        $item,
        \Magento\SalesRule\Model\Validator $validator
    ){
        $returnValue = $proceed($item);

        $discountData = $this->discountFactory->create();

        $discountData->setAmount('[my_discount_amount]');
        $discountData->setBaseAmount('[my_discount_amount]');
        $discountData->setOriginalAmount('[my_discount_amount]');
        $discountData->setBaseOriginalAmount('[my_discount_amount]');

        $this->setDiscountData($discountData, $item);

        return $returnValue;
    }
}

Replace the [my_discount_amount] with your discount amount.

  • Thanks. I am getting Call to undefined method setDiscountData error. Any idea ? – Pankaj Pareek Jun 6 at 9:36
  • hello, @NoamN pls update full code, also this code sets the mannual discount on each quote item? – jafar pinjar Jul 30 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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