php – 在Magento自动创建购物车价格规则
发布时间:2020-12-13 13:39:29 所属栏目:PHP教程 来源:网络整理
导读:我想创建一个购物车价格规则,当用户在Magento网站上完成一个流程时,给用户10%的订单. 有一个方法here将规则直接插入数据库.这对我的口味有一点侵略性. 如何使用Magento方法呢? 作为一般原则,您应该能够执行Magento系统本身所做的任何事情,而无需编写单行SQ
我想创建一个购物车价格规则,当用户在Magento网站上完成一个流程时,给用户10%的订单.
有一个方法here将规则直接插入数据库.这对我的口味有一点侵略性. 如何使用Magento方法呢?
作为一般原则,您应该能够执行Magento系统本身所做的任何事情,而无需编写单行SQL.几乎所有的Magento数据结构都使用Magento Model类.
在某处运行以下代码来查看salesrule /规则模型的外观.这假设您在管理员中创建了一个ID为1的单个购物车价格规则 $coupon = Mage::getModel('salesrule/rule')->load(1); var_dump($coupon->getData()); 使用转储数据作为指导,我们可以使用以下方式编程创建模型 $coupon = Mage::getModel('salesrule/rule'); $coupon->setName('test coupon') ->setDescription('this is a description') ->setFromDate('2010-05-09') ->setCouponCode('CODENAME') ->setUsesPerCoupon(1) ->setUsesPerCustomer(1) ->setCustomerGroupIds(array(1)) //an array of customer grou pids ->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(10) ->setDiscountQty(null) ->setDiscountStep('0') ->setSimpleFreeShipping('0') ->setApplyToShipping('0') ->setIsRss(0) ->setWebsiteIds(array(1)); $coupon->save(); 对于任何好奇的人来说,上面是生成的代码,使用了所讨论的技术here (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |