简体   繁体   English

在事件checkout_cart_product_add_after中获取产品属性

[英]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.

相关问题 如何在Magento事件checkout_cart_product_add_after中获取客户详细信息? - How can I get customer details in Magento event checkout_cart_product_add_after? 添加到购物车并侦听“ checkout_cart_product_add_after”事件时,如何获取产品数据 - how do I get product data when adding to cart and listening for the “checkout_cart_product_add_after” event Woocommerce 在购物车和结帐时打印简单的产品属性,如变量属性 - Woocommerce print simple product attributes on cart and checkout, like variable attributes 结帐购物车中的可选产品(/结帐/购物车/) - Optional product in a Checkout Cart (/checkout/cart/) Woocommerce-在页面加载时,将产品添加到购物车并自动进行结帐 - Woocommerce - On page load, add product to cart and proceed to Checkout automatically 在 Woocommerce 结帐页面中将产品添加到购物车的复选框字段 - Checkbox field that add to cart a product in Woocommerce checkout page 添加产品后,添加到购物车不起作用 - After Append Product` add to cart` is not working 添加产品尺寸后,添加到购物车不起作用 - Add to cart not working after adding product dimensions 其他Woocommerce产品“添加到购物车”按钮,可重定向到结帐 - Additional Woocommerce product Add To Cart button that redirect to checkout Woocommerce添加到购物车重定向到Checkout不适用于具有变体的产品 - Woocommerce Add To Cart redirect to Checkout not working for product with variants
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM