簡體   English   中英

在事件checkout_cart_product_add_after中獲取產品屬性

[英]Getting product attributes in event checkout_cart_product_add_after

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

}

嘗試這個:

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

我正在使用此代碼在Observer.php獲取產品屬性。 希望這可以幫助某人

$product->getResource()->getAttribute('selling_type')->getFrontend()->getValue($product);
<?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;
    }
}

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM