2015-09-08 28 views
0

我有一個觀察者(checkout_cart_product_add_after)並希望獲得選定的自定義選項數組。如何在Observer.php中調用getItem()&getOptionList() - Magento

我已經找到了兩個元素我需要:

app/design/frontend/MY-THEME/default/template/checkout/cart/item/default.phtml

它們是:

 
1. $_item = $this->getItem(); 
2. $_options = $this->getOptionList(); 

我只是不知道如何讓他們以觀察員即還有什麼我要打電話。

在此先感謝!

回答

0

請訪問以下網址

http://inchoo.net/magento/updating-options-of-configurable-product-that-is-already-in-the-cart/

感謝

0

觀察家總是開始返回從他們各自的 「事件」 的數據。

所以你的情況,你必須使用下面一行的第一個拿到收銀臺,報價物體在觀察者的功能代碼:

$quote = $observer->getEvent()->getQuote(); 

然後你可以從像下面的報價獲得物品收集每個項目的自定義選項:

$quoteItems = $quote->getAllItems(); 
$helper = Mage::helper('catalog/product_configuration'); 
foreach ($quoteItems as $item) { 
    $product = $item->getProduct(); 
    $options = $helper->getCustomOptions($item); 
    //do anything with $options. 
} 

試試這個。希望能幫助到你。

也有你已經提到下面的鏈接?

https://magento.stackexchange.com/questions/16804/get-the-object-of-the-whole-quotation-in-observer

https://magento.stackexchange.com/questions/63752/get-products-final-price-with-its-selected-custom-option-on-add-to-cart

https://magento.stackexchange.com/questions/6368/how-to-get-selected-custom-options-on-onepage

相關問題