2015-05-05 79 views
0

我想add some extra amount to Grand totalmagento。因此,在結帳頁面中,訂單審覈部分將如下所示:如何在Magento中使用觀察者更改總數?

enter image description here 這些額外費用將取決於一些條件。

我的問題是:如何在結帳頁面更改總計?爲此我做的是:我創建module。請看看我的代碼:

應用程序/代碼/本地/ Locwiseship/Customprice的/ etc/config.xml中

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Locwiseship_Customprice> 
      <version>1.0.10</version> 
     </Locwiseship_Customprice> 
    </modules> 


    <global> 

     <events> 
     <!-- Création éventuelle du lien de parrainage lors de la commande --> 
      <sales_quote_collect_totals_after> 
       <observers> 
        <set_custom_price_locwiseship> 
         <type>singleton</type> 
         <class>Locwiseship_Customprice_Model_Sales_Quote_Address_Total_Mytotal</class> 
         <method>collect</method> 
               <method>fetch</method> 
        </set_custom_price_locwiseship> 
       </observers> 
      </sales_quote_collect_totals_after>    

    </events> 

    </global> 


</config> 

應用程序/代碼/本地/ Locwiseship/Customprice /型號/ Observer.php

<?php 
/** 
* @category Locwiseship 
* @package Locwiseship_Customprice 
*/ 
class Locwiseship_Customprice_Model_Sales_Quote_Address_Total_Mytotal 
    extends Mage_Sales_Model_Quote_Address_Total_Abstract 
{ 
    public function __construct() 
    { 
     $this->setCode('mytotal'); 
    } 

    public function collect(Mage_Sales_Model_Quote_Address $address) 
    { 
     parent::collect($address); 

     foreach ($this->_getAddressItems($address) as $item) { 
      // These two lines represent whatever logic you're 
      // using to calculate these amounts 
      $baseAmt = 10; 
      $amt = 10; 

      // Set the item's total 
      $item->setBaseMytotalAmount($baseAmt); 
      $item->setMytotalAmount($amt); 

      // These methods automatically take care of summing 
      // "mytotal_amount" on the quote address 
      $this->_addBaseAmount($baseAmt); 
      $this->_addAmount($amt); 
     } 
     return $this; 
    } 

    public function fetch(Mage_Sales_Model_Quote_Address $address) 
    { 
     // Naturally, this exists on the quote address because "collect" ran already 
     $amt = $address->getMytotalAmount(); 

     if ($amt!=0) { 
      $address->addTotal(array(
        'code' => $this->getCode(), 
        'title' => Mage::helper('Locwiseship_Customprice')->__('My Total'), 
        'value' => $amt 
      )); 
     } 
     return $this; 
    } 
} 

應用的/ etc /模塊/ Locwiseship_Customprice.xml

​​

這就是我所有的代碼。但沒有發生..這是行不通的.. 我使用正確的方法?我怎樣才能使這個工作?我使用Magento的1.9.0.1

+0

http://excellencemagentoblog.com/blog/2012/01/27/magento-add-fee-discount-order-total/查看這個博客,它可能會幫助你。 –

回答