2011-12-22 6 views
2

Magentoイベントcheckout_cart_product_add_afterのオブザーバーがあります。今私は例えば、Tシャツのサイズが私のカスタムモジュールのMagentoに与えたものと同じかどうかを確認する必要があります。私の観察者の中でそれらの製品の属性を取得するにはどうすればいいですか?イベントの商品属性を取得するcheckout_cart_product_add_after

class Company_ModuleSizes_Model_Sizes_Observer extends Mage_Core_Model_Abstract 
{ 

    public function check_sizes($observer) 
    {  
     // Get quote item 
     $event = $observer->getEvent(); 
     $quoteItem = $event->getQuoteItem(); 

     // How can I get product attributes from $quoteItem ? 

     return $this; 
    } 

} 
+2

をホープ;' – benmarks

+0

また、あなたのイベントの観察者が/必要としないべきではありません'Mage_Core_Model_Abstract'を拡張します。 – benmarks

答えて

4

これを試してみてください。

$_options = $quoteItem->getProduct()->getData('your-attribute'); 
0
<?php 
class Company_ModuleSizes_Model_Sizes_Observer extends Mage_Core_Model_Abstract 
{ 
    public function check_sizes($observer) 
    {  
     // Get Quote Item 
     $event = $observer->getEvent(); 
     $quoteItem = $event->getQuoteItem(); 
     $product = $event->getProduct(); 

     // The options provided by the customer is available using the following statement 
     $_optionsQuoteItem = $quoteItem->getProduct()->getData('your-attribute'); 

     // The options which are available for the product in general is available using the following statement 
     $_optionsProduct = $product->getData('your-attribute'); 

     // Now you can process your required logic in here, with the above two variables 

     return $this; 
    } 
} 

はそれがお役に立てば幸いです。

+0

'$ product-> getData( 'your-attribute');'はオプションのリストを返しません。このコンテキストでは、選択された構成可能なプロダクトオプションに対して常に「null」を返します。 – benmarks

0

私はこのコードを使用してObserver.phpの製品属性を取得しています。これはあなたが `$ quoteItem = $ observer-> getQuoteItem()すなわち、観測者から直接オブジェクトインスタンスquote_item /販売を要求することができ、誰か

$product->getResource()->getAttribute('selling_type')->getFrontend()->getValue($product); 
関連する問題