简体   繁体   中英

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. 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM