作为一般原则,您应该能够执行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();
原文地址:https://www.jb51.cc/php/138196.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。