自定義 Mage_Sales_Model_Quote_Address_Total_Abstract 計算兩次:帳單和送貨地址 (Custom Mage_Sales_Model_Quote_Address_Total_Abstract calculate twice: billing&shipping address)


問題描述

自定義 Mage_Sales_Model_Quote_Address_Total_Abstract 計算兩次:帳單和送貨地址 (Custom Mage_Sales_Model_Quote_Address_Total_Abstract calculate twice: billing&shipping address)

I intended to make a custom credit module which can use our store's credits for discount. After looking into some examples, I successfully added a checkout step to the onepage checkout. And then I extends Mage_Sales_Model_Quote_Address_Total_Abstract to have a custom collector to calculate total. Currently I hard coded some discount value to see how it works:

public function collect(Mage_Sales_Model_Quote_Address $address) {
        parent::collect ( $address );
        //if($address‑>getData('address_type')=='billing') return $this;

        try {

            $this‑>_setAmount ( ‑10 )‑>_setBaseAmount ( ‑10 );

        } catch ( Exception $e ) {
            Mage::throwException ( $e‑>getMessage () );

        //do nothing.    
        }
        return $this;
    }

    public function fetch(Mage_Sales_Model_Quote_Address $address) {
        parent::fetch ( $address );
        //if($address‑>getData('address_type')=='billing') return $this;
        $title = Mage::helper ( 'sales' )‑>__ ( 'Credittest' );
        $address‑>addTotal ( array ('code' => $this‑>getCode (), 'title' => $title, 'value' => ‑10 ) );
        return $this;
    }

The section in config.xml looks like this:

<sales>
    <quote>
        <totals>
            <credittest>
                 <class>sales/quote_address_total_credit</class>
                 <after>tax_subtotal,subtotal,freeshipping</after>
                 <before>grand_total</before>
            </credittest>
        </totals>
    </quote>
</sales> 

However the result comes out with ‑20 deducted. after some debug tracing, my custom collector are called twice, once the address type is "billing" and another is "shipping". So I added the commented code above to calculate only when shipping address comes in. But i'm not sure if this is the right way to go.

Why other class in  Mage_Sales_Model_Quote_Address won't calculate twice? They are actually invoked twice according to my tracing. And what's right way solve my issue?

Thank you in advance.

‑‑‑‑‑

參考解法

方法 1:

Take a look @ Magento Add Fee or Discount to Order Totals

(by HooYaoMagePal Extensions)

參考文件

  1. Custom Mage_Sales_Model_Quote_Address_Total_Abstract calculate twice: billing&shipping address (CC BY‑SA 3.0/4.0)

#module #e-commerce #checkout #magento






相關問題

如何在內核源文件中包含 math.h #include <math.h>? (How to include math.h #include <math.h> on kernel source file?)

根據服務器配置指令初始化 nginx 模塊的共享內存 (Initialize an nginx module's shared memory depending on a server configuration directive)

選擇安裝 python 模塊的位置 (Choosing where to install python module)

如何從 CLI 中查找 php 中內置模塊的版本號 (how to find the version numbers of built in modules in php from the CLI)

java.lang.SecurityException:無法為受信任的 CA (JBoss AS 7) 設置證書 (java.lang.SecurityException: Cannot set up certs for trusted CAs (JBoss AS 7))

自定義 AngularJS 過濾器忽略我的參數並接收其他一些 scope.data (custom AngularJS filter ignores my parameter and receive some other scope.data)

具有“插件”能力的 ASP.NET 內網應用程序 (ASP.NET intranet application with "plug-in" ability)

VBscript 有模塊嗎?我需要處理 CSV (Does VBscript have modules? I need to handle CSV)

自定義 Mage_Sales_Model_Quote_Address_Total_Abstract 計算兩次:帳單和送貨地址 (Custom Mage_Sales_Model_Quote_Address_Total_Abstract calculate twice: billing&shipping address)

Ocaml 函子、模塊和子模塊 (Ocaml Functors, Modules and Submodules)

類的 Python 模塊結構 (Python module structure for classes)

我想使用 HPC 的 gpu 並嘗試 module add CUDA ...但出現錯誤。錯誤是“Lmod 檢測到以下錯誤: (I want to use the gpu of the HPC and try module add CUDA... But errors occurs. The error is "Lmod has detected the following error:)







留言討論