小编Eva*_*uch的帖子

以编程方式在Magento中创建自动生成的优惠券代码?

基于其他stackoverflow帖子,我已经能够使用以下代码以编程方式在Magento中生成个人购物车价格规则优惠券.

如何以编程方式调用"自动生成优惠券"功能,为我制定的每个定价规则创建100个独特的优惠券?谢谢!

$coupon = Mage::getModel('salesrule/rule');
$coupon->setName($_coupon['name'])
       ->setDescription('this is a description')
       ->setFromDate(date('Y-m-d'))
       ->setCouponType(2)
       ->setCouponCode($_coupon['code'])
       ->setUsesPerCoupon(1000)
       ->setUsesPerCustomer(100)
       ->setCustomerGroupIds(array(1)) //an array of customer groupids
       ->setIsActive(1)
       //serialized conditions.  the following examples are empty
       ->setConditionsSerialized('a:6:{s:4:"type";s:32:"salesrule/rule_condition_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";}')
       ->setActionsSerialized('a:6:{s:4:"type";s:40:"salesrule/rule_condition_product_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";}')
       ->setStopRulesProcessing(0)
       ->setIsAdvanced(1)
       ->setProductIds('')
       ->setSortOrder(0)
       ->setSimpleAction('by_percent')
       ->setDiscountAmount(100)
       ->setDiscountQty(null)
       ->setDiscountStep('0')
       ->setSimpleFreeShipping('0')
       ->setApplyToShipping('0')
       ->setIsRss(0)
       ->setWebsiteIds(array(1));      
$coupon->save();
Run Code Online (Sandbox Code Playgroud)

例如,使用在管理面板中手动创建价格规则时可用的功能,此一个定价规则可能具有自动生成的优惠券代码(htgf-7774,htgf-2345等)的完整列表.

编辑:

我已经靠近了,使用下面的代码.仍然不知道如何专门指定自动生成模式

->setName('Name')
->setDescription('this is a description')
->setFromDate('2013-03-06')
->setToDate(NULL)
->setUsesPerCustomer('100')
->setIsActive('1')
->setConditionsSerialized('a:6:{s:4:"type";s:32:"salesrule/rule_condition_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";}')
->setActionsSerialized('a:6:{s:4:"type";s:40:"salesrule/rule_condition_product_combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_processed";N;s:10:"aggregator";s:3:"all";}')
->setStopRulesProcessing('0')
->setIsAdvanced('1')
->setProductIds(NULL)
->setSortOrder('0')
->setSimpleAction('by_percent')
->setDiscountAmount('100.0000')
->setDiscountQty(NULL)
->setDiscountStep('0')
->setSimpleFreeShipping('0')
->setApplyToShipping('0')
->setTimesUsed('1')
->setIsRss('0')
->setCouponType('2')
->setUseAutoGeneration('1')
->setUsesPerCoupon('1000')
->setCustomerGroupIds(array('1',))
->setWebsiteIds(array('1',))
->setCouponCode(NULL)
Run Code Online (Sandbox Code Playgroud)

magento coupon

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

coupon ×1

magento ×1