How to Create Shopping Cart Price Rule programmatically

Here is the code snippet by wich we can create magento shopping cart price rule, i.e the rule
which is applide on shopping cart while customer add his/her product to shopping cart.

shopping cart price rule can be divided in 3 parts
1. Information of the rule
2. Condition that will be applied on the rule.
3. Action that will be taken.

$name = "cutom programmatically created rule"; // name of  Rule
$websiteId = 1;
$customerGroupId = 2;
$actionType = 'by_percent'; // discount by percentage(other options are: by_fixed, cart_fixed, buy_x_get_y)
$discount = 10; // percentage discount
$sku = 'RBT67'; // product sku
$shoppingCartPriceRule = Mage::getModel('salesrule/rule');
$skuCondition = Mage::getModel('salesrule/rule_condition_product')
try {
} catch (Exception $e) {

1 comment

  1. Thomas Parquier says:

    How to only create a condition usable in admin ui, based for example on previous orders ? I’d like administrators to be able to create new cart rules based on these new conditions (product types previously bought, number of products in previous orders, or so).

    TIA, Thomas

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>