【问题标题】:How to put flat rate before subtotal at checkout time in magento如何在magento结帐时将统一费率放在小计之前
【发布时间】:2017-01-25 10:57:25
【问题描述】:

我想把统一费率放在小计之前,默认情况下低于小计。

【问题讨论】:

    标签: magento-1.9 checkout rate flat


    【解决方案1】:

    如何添加额外费用或折扣,或任何类型的费用来订购 magento 结帐流程的总额 在一个典型的订单中,订单总额通常包括小计、运费、税金、折扣,根据这些值计算总订单总额。 我们添加到总额中的这笔额外费用将反映在

    结帐页面订单总计, 购物车页面订单总计, 我的帐户订单查看页面, 打印订单 PDF, 订购电子邮件, 管理员订单视图/电子邮件/PDF, 管理员发票查看/电子邮件/PDF, 管理员信用备忘录查看/电子邮件/PDF。

    结帐页面总订单总基础知识 我们将看到如何仅将总计添加到结帐页面。结帐页面上显示的所有总计行项目均来自文件夹 Mage\Sales\Model\Quote\Address\Total 中的文件。

    在magento中,在下订单之前,所有订单数据都存储在报价对象中,下订单后,它会被传输到订单对象。报价总额遵循收集器模式,我们可以添加尽可能多的收集器类。要将收集器添加到我们的 config.xml 中的报价对象,我们添加行

    <global>
        <sales>
            <quote>
                <totals>
                    <fee>
                        <class>fee/sales_quote_address_total_fee</class>
                    </fee>
                </totals>
            </quote>
       </sales>
    

    这意味着每当计算报价的总数时,它也会调用这个类。

    从报价模型中的 collectTotals() 函数调用所有收集器。

    在我们的收集器类中,我们放入代码

    <?php class Excellence_Fee_Model_Sales_Quote_Address_Total_Fee 
    

    扩展 Mage_Sales_Model_Quote_Address_Total_Abstract{ 受保护的 $_code = '费用';

    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        parent::collect($address);
    
        $this->_setAmount(0);
        $this->_setBaseAmount(0);
    
        $items = $this->_getAddressItems($address);
        if (!count($items)) {
            return $this; //this makes only address type shipping to come through
        }
    
    
        $quote = $address->getQuote();
    
        if(Excellence_Fee_Model_Fee::canApply($address)){ //your business logic
            $exist_amount = $quote->getFeeAmount();
            $fee = Excellence_Fee_Model_Fee::getFee();
            $balance = $fee - $exist_amount;
            $address->setFeeAmount($balance);
            $address->setBaseFeeAmount($balance);
    
            $quote->setFeeAmount($balance);
    
            $address->setGrandTotal($address->getGrandTotal() + $address->getFeeAmount());
            $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseFeeAmount());
        }
    }
    
    public function fetch(Mage_Sales_Model_Quote_Address $address)
    {
        $amt = $address->getFeeAmount();
        $address->addTotal(array(
                'code'=>$this->getCode(),
                'title'=>Mage::helper('fee')->__('Fee'),
                'value'=> $amt
        ));
        return $this;
    }
    

    } 这里我们使用两个字段 fee_amount 和 base_fee_amount,其中包含我们的费用金额。我们将不得不看到将这两个字段保存到数据库中,因此在我们的模块安装程序文件中添加此代码

    ALTER TABLE  `".$this->getTable('sales/quote_address')."` ADD  `fee_amount` DECIMAL( 10, 2 ) NOT NULL;
        ALTER TABLE  `".$this->getTable('sales/quote_address')."` ADD  `base_fee_amount` DECIMAL( 10, 2 ) NOT NULL;
    

    订单页面 到目前为止,所有编写的代码都只针对引用对象完成。但是下订单后,我们需要将所有信息传递给订单对象。正如您在上面看到的,我们使用了两个字段 fee_amount 和 base_fee_amount,我们现在还需要将这两个字段存储在订单表中。要做到以上所有,我们需要做两件事。首先在 config.xml 文件中的全局选项卡内添加此代码,

    <fieldsets>
            <sales_convert_quote_address>
            <fee_amount><to_order>*</to_order></fee_amount>
            <base_fee_amount><to_order>*</to_order></base_fee_amount>
            </sales_convert_quote_address>
      </fieldsets>
    

    在我们的模块安装文件中

    ALTER TABLE  `".$this->getTable('sales/order')."` ADD  `fee_amount` DECIMAL( 10, 2 ) NOT NULL;
        ALTER TABLE  `".$this->getTable('sales/order')."` ADD  `base_fee_amount` DECIMAL( 10, 2 ) NOT NULL;
    

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-20
      • 1970-01-01
      • 1970-01-01
      • 2013-03-28
      • 1970-01-01
      相关资源
      最近更新 更多