![](/img/trans.png)
[英]How can I get customer details in Magento event 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.