简体   繁体   English

添加到购物车并侦听“ 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

I am a developer stuck on an interesting problem, I am trying to retrieve the stock data for a simple product as it is added to the cart. 我是一个陷入一个有趣问题的开发人员,我正尝试检索添加到购物车中的简单产品的库存数据。 The simple product is added from the product page of a configurable product. 简单产品是从可配置产品的产品页面添加的。 When I look at the properties of $observer->getEvent()->getProduct(), it appears as though the product data is that of the configurable product and not the simple product, which makes no sense to me. 当我查看$ observer-> getEvent()-> getProduct()的属性时,似乎产品数据是可配置产品的数据,而不是简单产品的数据,这对我来说毫无意义。 Any suggestions? 有什么建议么?

This is just what runs through my mind but there might be more elegant ways: 这就是我的想法,但是可能会有更优雅的方式:

$productId = $configurableProduct->getOptionByCode('simple_product')->getProductId();
$simple = Mage::getModel('catalog/product')->load($productId);

暂无
暂无

声明:本站的技术帖子网页,遵循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中获取产品属性 - Getting product attributes in event checkout_cart_product_add_after 将产品添加到购物车后,用户刷新页面,然后如何显示添加到购物车中的数据 - after adding the product in the cart and the user refreshes the page then how can I display the data which is added in the cart 添加产品尺寸后,添加到购物车不起作用 - Add to cart not working after adding product dimensions 如果我单击已在购物车中的产品的“添加到购物车”按钮,如何重定向到购物车页面 - How do I redirect to the cart page if I click on the 'Add to cart' button for a product that's already in cart 产品添加到购物车时如何获取类别名称 - When Product adding to cart how to get category name 将特定产品添加到购物车时如何删除特定的购物车项目? - How to remove a specific cart item when adding to cart a specific product? 使用php将产品添加到购物车后如何更改添加到购物车按钮 - how to change add to cart button after adding product to the cart using php 将产品添加到购物车后如何隐藏/删除 Woocommerce 中的添加到购物车按钮 - How to hide / remove add to cart button in Woocommerce after adding the product to the cart 结帐购物车中的可选产品(/结帐/购物车/) - Optional product in a Checkout Cart (/checkout/cart/)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM