2011-09-01 92 views

回答

9

您可以使用一個觀察者類聽checkout_cart_product_add_after,並使用產品的「超級模式」設置自定義價格對報價項目。

在你/app/code/local/{namespace}/{yourmodule}/etc/config.xml:

<config> 
    ... 
    <frontend> 
     ... 
     <events> 
      <checkout_cart_product_add_after> 
       <observers> 
        <unique_event_name> 
         <class>{{modulename}}/observer</class> 
         <method>modifyPrice</method> 
        </unique_event_name> 
       </observers> 
      </checkout_cart_product_add_after> 
     </events> 
     ... 
    </frontend> 
    ... 
</config> 

然後在創建/應用/代碼觀察員類/本地/ {命名空間}/{} yourmodule /Model/Observer.php

<?php 
    class <namespace>_<modulename>_Model_Observer 
    { 
     public function modifyPrice(Varien_Event_Observer $obs) 
     { 
      // Get the quote item 
      $item = $obs->getQuoteItem(); 
      // Ensure we have the parent item, if it has one 
      $item = ($item->getParentItem() ? $item->getParentItem() : $item); 
      // Load the custom price 
      $price = $this->_getPriceByItem($item); 
      // Set the custom price 
      $item->setCustomPrice($price); 
      $item->setOriginalCustomPrice($price); 
      // Enable super mode on the product. 
      $item->getProduct()->setIsSuperMode(true); 
     } 

     protected function _getPriceByItem(Mage_Sales_Model_Quote_Item $item) 
     { 
      $price; 

      //use $item to determine your custom price. 

      return $price; 
     } 

    } 
+0

如果我添加使用觀察者設置自定義價格到購物車,然後我得到以電子郵件模板乘以項目數量的單位價格。 我該如何解決這個問題 app \ design \ frontend \ default \ rfg \ template \ email \ order \ items \ order \ default.phtml <?php echo $ _order-> formatPrice($ _ item-> getRowTotal())? > – Muk

+0

任何人都可以解釋從該行''setIsSuperMode' $用品 - > getProduct() - > setIsSuperMode(真);'?它有什麼作用? – mkutyba

+2

這裏是超模的explantion: 「報價超級模式標誌是什麼意思,我們與報價工作,不受任何限制」 例如:如果超級模式設置爲true,磁不會檢查該產品是否在目錄中可見 – Nidheesh

相關問題