Showing posts with label code code value change. Show all posts
Showing posts with label code code value change. Show all posts

Tuesday, 22 October 2013

Magento Create Coupon Programatically

Create coupon code programatically

<?php

ini_set('max_execution_time', 600);
ini_set('memory_limit', '1024M');

require 'app/Mage.php';
$app = Mage::app('');

$rule = Mage::getModel('salesrule/rule');
    $customer_groups = array(0, 1, 2, 3);
    $rule->setName(jaga)
      ->setDescription(jaga)
      ->setFromDate('')
      ->setCouponType(2)
      ->setCouponCode('jaga123')
      ->setUsesPerCustomer(1)
      ->setCustomerGroupIds($customer_groups) //an array of customer grou pids
      ->setIsActive(1)
      ->setConditionsSerialized('')
      ->setActionsSerialized('')
      ->setStopRulesProcessing(0)
      ->setIsAdvanced(1)
      ->setProductIds('')
      ->setSortOrder(0)
      ->setSimpleAction('cart_fixed')
      ->setDiscountAmount('5555')
      ->setDiscountQty(null)
      ->setDiscountStep(0)
      ->setSimpleFreeShipping('0')
      ->setApplyToShipping('0')
      ->setIsRss(0)
      ->setWebsiteIds(array(1));


    $rule->save();
?>