Our price rules are used for discounts. Some of our orders come in via the API. Our API orders must not have any discount applied. How can I achieve this?

At the moment, price rules are applied to orders created via the API the same way as to orders created via the shop frontend.


You can try this by setting applied_rule_ids field as null in quote table. You need to create a preference of Magento\Quote\Model\Quote.php and create function as

public function setAppliedRuleIds(null)
    $this->setData('applied_rule_ids', null);
    return $this;

Make sure you defined preference in webapi_rest folder's di.xml so that it will work for rest api only.

Its only suggestion so I am not sure it will work for you as I haven't tried this. Let me know if you face any issue.

  • Thank you @ramkishan. I tried, but it did not work. In src/vendor/magento/module-sales-rule/Model/Validator.php, firstly the rulesApplier->applyRules is used, before the setAppliedRuleIds method sets the ids. Commenting out the setAppliedRuleIds did not have any impact. I was more successful returning an empty array from the function _getRules in the same file; I think I could write a plugin for that. Now just not sure about how to access order-level properties / attributes from that plugin...
    – hey
    Oct 9 '18 at 2:23

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.