I'm working on custom API collections for Magento 2.

i'm trying to add new feature that allow customer to use some coupons from Mobile Apps Only.

So i need to add new condition for Cart Price Rules, for example name it as "Source" with two options "Mobile Apps, Web".

and when creating new coupon with "Source as Mobile Apps".. the coupon will only work from REST API request, and it will not applied if the customer try it from the Magento 2 web version.

any idea how to do it?


1 Answer 1


Create a new module in Magento 2 for custom API collections.

Define a new condition class that extends the Magento\Rule\Model\Condition\AbstractCondition class. In this class, you can define the validate method to check if the condition is satisfied based on the source of the request.

In the validate method, you can check if the source of the request is from the Mobile App by checking the request header or any other identifiable parameter.

If the source of the request is from the Mobile App, return true to indicate that the condition is satisfied, otherwise return false.

In the Magento 2 admin panel, create a new Cart Price Rule and select your custom condition. Set the "Source" option to "Mobile Apps".

In your Mobile App, make a REST API request to apply the coupon code to the cart. The custom condition will be checked during the coupon validation process and the coupon will only be applied if the "Source" option is set to "Mobile Apps".

Overall, this approach allows you to create a custom condition for Cart Price Rules based on the source of the request and use it to limit the use of coupons to Mobile Apps only.

Your Answer

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

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