2011-02-02 174 views
7

我需要打電話給第三方API才能在結帳過程的審覈階段獲取最新的國際運輸稅/稅。我準備好了API調用,但是我錯過了將返回的關稅和稅款添加到報價中的方法。Magento:在審覈期間在報價中添加關稅/稅款

有沒有內置的方法來做到這一點?

IM希望有類似

$quote->addCostComponent("Duties", 5.0); 
+0

是的,有。但我忘了如何。這會更好地在magento論壇上被問到嗎? – 2011-02-02 18:03:21

+4

@Joe,如果您在尋找代碼幫助,Magento論壇是一個荒地。由於這是一個與代碼相關的問題,因此這裏的觀衆似乎更適合。 – 2011-02-02 22:46:46

回答

15

您需要執行這些步驟:

  1. 所有你需要的,以顯示它們爲您的關稅/稅的屬性首先,不僅僅增加了總數。在網站貨幣中應該至少有兩個屬性值(用於付款捕獲,它應該有base_前綴)和一個以顯示貨幣表示的值(僅用於顯示客戶期望貨幣的金額)。應將這些屬性添加到具有財務部分的每個實體(quote_address,order,invoice)。例如,它應該是:帶有十進制類型的base_your_attribute_codeyour_attribute_code

  2. 然後你需要創建您總集熱模式,應該從Mage_Sales_Model_Quote_Address_Total_Abstract進行擴展並實現收集和在本例中取類似的方法:

    /** 
    * Your custom total model 
    * 
    */ 
    class Your_Module_Model_Total_Custom extends Mage_Sales_Model_Quote_Address_Total_Abstract 
    { 
        /** 
        * Constructor that should initiaze 
        */ 
        public function __construct() 
        { 
         $this->setCode('your_attribute_code'); 
        } 
    
        /** 
        * Used each time when collectTotals is invoked 
        * 
        * @param Mage_Sales_Model_Quote_Address $address 
        * @return Your_Module_Model_Total_Custom 
        */ 
        public function collect(Mage_Sales_Model_Quote_Address $address) 
        { 
         parent::collect($address); 
    
         // ... Some your api calls to retrive amount ... 
    
         // Set base amount of your custom fee 
         $this->_setBaseAmount($calculatedAmount); 
    
         // Set amount of your custom fee in displayed currency 
         $this->_setAmount(
          $address->getQuote()->getStore()->convertPrice($calculatedAmount, false) 
         ); 
    
         return $this; 
        } 
    
        /** 
        * Used each time when totals are displayed 
        * 
        * @param Mage_Sales_Model_Quote_Address $address 
        * @return Your_Module_Model_Total_Custom 
        */ 
        public function fetch(Mage_Sales_Model_Quote_Address $address) 
        { 
         // Display total only if it is not zero 
         if ($address->getYourAttributeCode() != 0) { 
          $address->addTotal(array(
           'code' => $this->getCode(), 
           'title' => 'My Custom Duty', 
           'value' => $address->getYourAttributeCode() 
          )); 
         } 
        } 
    } 
    
  3. 你之後收集模型創建你需要將它添加到配置:

    <config> 
        <global> 
         <sales> 
          <quote> 
           <totals> 
            <your_total_code> 
             <class>your_module/total_custom</class> 
             <before>grand_total</before> 
             <after>shipping</after> 
            </your_total_code> 
           </totals> 
          </quote> 
         </sales> 
        </global> 
    </config> 
    
    • 節點包含您的收集器型號的別名
    • 之前之後節點指示收集器的調用順序。
  4. 你需要添加你的總屬性進行實地集,將用於複製計算的數據轉換成訂單或發票:

    <config> 
        <global> 
         <fieldsets> 
          <!-- copies data from quote address to order during the order placement --> 
          <sales_convert_quote_address> 
           <base_your_attribute_code><to_order>*</to_order></base_your_attribute_code> 
           <your_attribute_code><to_order>*</to_order></your_attribute_code> 
          </sales_convert_quote_address> 
    
          <!-- copies data from order to invoice/shipment/creditmemo during their creation --> 
          <sales_convert_order> 
           <base_your_attribute_code><to_invoice>*</to_invoice><to_shipment>*</to_shipment><to_cm>*</to_cm></base_your_attribute_code> 
           <your_attribute_code><to_invoice>*</to_invoice><to_shipment>*</to_shipment><to_cm>*</to_cm></your_attribute_code> 
          </sales_convert_order> 
    
         </fieldsets> 
        </global> 
    </config> 
    
  5. 執行後,這個步驟,你就可以看到你的定製費總計