Home » Magento20 June 2011

Magento: Create Shopping Cart Price Rule Programmatically

This article will show you how to create shopping cart price rule in Magento through code.

Shopping Cart Price Rules are applied when the customer reaches the shopping cart.

To create a Shopping Cart Price Rule from Admin Panel, we go to Promotions -> Shopping Cart Price Rules and select Add New Rule.

Basically, there are three main parts for Shopping Cart Price Rule, i.e. Rule Information, Conditions, and Actions.

Here is the code to create Shopping Cart Price Rule. In this code example, I have created Shopping Cart Price Rule with the following information:-

– The rule is applied to particular product with the particular SKU (in our case: ‘chair’)
– The rule is applied as Percentage Discount By certain percent (in our case: by 10 percent) of currency amount

A new Shopping Cart Price Rule with the name “My Shopping Cart Price Rule” has been created. You can view the rule from Promotions -> Shopping Cart Price Rules in admin.

Hope this helps. Thanks.


Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Luca

    How can i create a shopping cart rule programmaticaly with conditions on the cart subtotal ?

  • samir amrutya

    Hello Mukesh,

    I have done some customize code in adding items to shopping cart. I have some special requirement to add same products as new separate entry in cart.

    Now, I have one shopping cart rule for a specific product SKU. When I apply that coupon code to shopping cart it will apply for each separate items of same products.

    Instead of apply for each items of same products, I want to apply coupon code only one item. Other items of same products will not be affected by coupon code

    Is there any way to do like this, Please help me.

  • Rahil28288

    How can i add new cart attribute like “Grand total” to shopping cart price rules

  • Pradeep Panwar

    How can apply coupon discount on subscription product (I have install subscription product extension )please help me…….

  • Immaculate Xavier

    Very Useful Post… Really it worked for me… also made some additional codes to set coupon code. Thanks a lot…

  • Sanjeev Kumar Sharma

    Where I need to write above code, please let us know the location

  • Dharmendra

    Showing error Invalid method Mage_SalesRule_Model_Rule::applyAll(Array ( ) )