且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

覆盖Magento中的购物车价格规则

更新时间:2023-11-29 21:39:46

我认为您不需要为此编辑任何代码.使用一些数学技巧.

I don't think you need to edit any code for that. Use some math tricks.

您想给予10%的折扣,但折扣不超过1000美元.

You want to give a 10% discount but no discount bigger than 1000$.

创建2条规则:

  1. 如果购物车总额少于10,000 $,可享受10%的折扣
  2. 如果购物车总额大于10,000 $,可享受1000 $的折扣

编辑-由于您只需要一个规则

  1. 将该限制字段移至"Magento配置"部分.请参阅 http://inchoo.net/ecommerce/magento/create -配置您的magento扩展/以获取详细信息.如果将其与规则表分开,会容易得多.
  2. 使用以下命令在模块中扩展app/code/core/Mage/SalesRule/Model/Validator.php. app/code/local/Namespace/Module/etc/config.xml

  1. Move that limit field into the Magento Configuration section. See http://inchoo.net/ecommerce/magento/create-configuration-for-your-magento-extension/ for details. It's a lot easier if you separate it from the rules form.
  2. Extend the app/code/core/Mage/SalesRule/Model/Validator.php in your module using: app/code/local/Namespace/Module/etc/config.xml

<global>
    <models>
        <salesrule>
            <rewrite>     
                <validator>Namespace_Module_Model_Validator</rule_collection>
            </rewrite>
        </salesrule>
    </models> 

app/code/local/Namespace/Module/Model/Validator.php

app/code/local/Namespace/Module/Model/Validator.php

<?php
Namespace_Module_Model_Validator extends Mage_Core_Model_Validator {
... //place your updated method here