Wednesday, 8 July 2015

Programmatically coupon code created in magento

                  $couponCode=Mage::helper('core')->getRandomString(16);
               
              
                $coupon = Mage::getModel('salesrule/rule');
                $coupon->setName("Coupon for ".$customer_mail." on ".date('Y-m-d H:i:s'))
               ->setDescription(null)
               ->setFromDate(date('Y-m-d'))
               ->setCouponType(2)
               ->setCouponCode($couponCode)
               ->setUsesPerCoupon(1)
               ->setUsesPerCustomer(1)
               ->setCustomerGroupIds(array(1,2,3,4))
               ->setIsActive(1)
               ->setStopRulesProcessing(0)
               ->setIsAdvanced(1)
               ->setProductIds('')
               ->setSortOrder(0)
               ->setSimpleAction('by_fixed')
               ->setDiscountAmount(250)
               ->setDiscountQty(null)
               ->setDiscountStep('0')
               ->setSimpleFreeShipping('0')
               ->setApplyToShipping('0')
               ->setIsRss(0)
               ->setWebsiteIds(array(1));
                $coupon->loadPost($coupon->getData());
                $coupon->save();

No comments:

Post a Comment