[英]Getting product attributes in event checkout_cart_product_add_after
I have observer for Magento event checkout_cart_product_add_after. 我有Magento事件checkout_cart_product_add_after的观察者。 Now I need to check if for example t-shirt size is same what user had given to Magento in my custom module.
现在,我需要检查例如T恤尺寸是否与用户在我的自定义模块中提供给Magento的尺寸相同。 How can I get those product attributes in my observer?
如何在观察者中获得这些产品属性?
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');
I am using this code to get the product attributes in the Observer.php
. 我正在使用此代码在
Observer.php
获取产品属性。 Hope this helps someone 希望这可以帮助某人
$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;
}
}
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.