2012-03-29 93 views
1

我正在尋找一種方法將價值添加到可配置產品的價格後所有必需的選項都被選中。我需要匹配所選簡單產品的全部SKU,所以每個選項價格不適合更改可配置產品的價格

我已經構建了一個JSON與SKU - 價格對,現在正在尋找一個JS事件乾淨地完成任務,並保留新的價格過程中添加到購物車及結帳階段

預先感謝任何見解

回答

4

您可以使用一個觀察者類聽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

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 and maybe your json object to determine the correct price 

     return $price; 
    } 

} 

這將處理來自後端的價格變化。至於javascript,我很抱歉,但我不太確定!

+0

接受你的答案,因爲我設法實現JS部分:) 雖然有一個問題 - 更新自定義價格,當匿名客戶添加產品到購物車,然後登錄到商店,所以價格必須重新計算,你有任何關於這個的想法? – Zifius 2012-04-06 20:58:23

+0

你是怎麼做JS的?我很想看看你的解決方案是什麼。至於登錄問題,客戶登錄時是否重置價格?也許有一個更好的事件要聽,或者你可以觀察登錄事件並迭代每個項目。 – 2012-04-12 01:36:10

+0

我已在'sales_quote_merge_after'事件中解決了定價問題,這是匿名客戶購物車轉換爲登錄客戶的地方。至於JS,我已經爲管理員值對創建了一個完整的選項ID JSON,收集了完整簡單的SKU併爲最終價格增加了價值(同樣來自JSON) – Zifius 2012-04-13 08:11:37

相關問題