I want to add a Cart Price Rule in Magento2, which is negative:

  • Actions: Fixed amount discount
  • Discount amount: -2

However, when I save it says:

Please choose a valid discount amount.

How can I remove the 'negative discount amount check'?

Additional explanation: I want to add $2 (instead of discount) in some cases, depending on product attributes.

  • You can not provide negative Discount amount as the keyword itself defines discount. it will show error at all, at which scenario you need to do negative discount!!!!! Mar 6 '20 at 11:55
  • @YashPanchal when you want to make the price higher for some products. That's when you would need it. Mar 6 '20 at 12:12
  • In some cases (depending on product attributes) I want to add $2 to the price....
    – Joris
    Mar 6 '20 at 14:07
  • 1
    You need to change in method "beforeSave" located in "\Magento\Rule\Model\AbstractModel" using Preference or what you prefer but it works "if ((int)$this->getDiscountAmount() < 0)" change this condition, You can save negative discount amount. Mar 9 '20 at 6:11

The discount amount, not define -2 remove "-" minus sign


Answered by Yash Panchal:

Commenting out function:

// Check if discount amount not negative
    //if ($this->hasDiscountAmount()) {
    //    if ((int)$this->getDiscountAmount() < 100) {
    //        throw new \Magento\Framework\Exception\LocalizedException(__('Please choose a valid discount amount.'));
    //    }

At line 141 of file vendor/magento/module-rule/Model/AbstractModel.php.

Of course it's better to make custom plugin at app/code instead of editing core code!

  • I'm not having any luck with this solution. Seems the JS validation still prevents you from saving with a negative value
    – codestr
    Jun 26 '20 at 17:51

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.