php – 在Magento自动创建购物车价格规则

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 在Magento自动创建购物车价格规则脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我想创建一个购物车价格规则,当用户在Magento网站上完成一个流程时,给用户10%的订单.

一个@L_360_5@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

脚本宝典总结

以上是脚本宝典为你收集整理的php – 在Magento自动创建购物车价格规则全部内容,希望文章能够帮你解决php – 在Magento自动创建购物车价格规则所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。