在事件checkout_cart_product_add_after中获取产品属性

时间:2011-12-22 13:55:59

标签: php magento magento-1.4

我有Magento事件checkout_cart_product_add_after的观察员。现在我需要检查一下T恤的大小是否与用户在我的自定义模块中给予Magento的大小相同。如何在观察者中获得这些产品属性?

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;
    }

}

3 个答案:

答案 0 :(得分:4)

试试这个:

$_options = $quoteItem->getProduct()->getData('your-attribute');

答案 1 :(得分: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;
    }
}

希望它有所帮助。

答案 2 :(得分:0)

我正在使用此代码获取Observer.php中的产品属性。希望这有助于某人

$product->getResource()->getAttribute('selling_type')->getFrontend()->getValue($product);