dongxu0690 2012-05-14 11:58
浏览 24
已采纳

获取与分组产品关联的简单产品的parent_item_id

I need to get the name of the Grouped Product in my Magento Cart. The problem is, what you add to the cart is the Simple Product, the Grouped Product only contains the images, title, and description. It's then associated to simple products (in most cases there are more than one) that contains some custom attributes. Another problem is that Simple Products can at times be associated with more than one Grouped Product. In this case I'd like to retrieve whichever one.

Here's what I have at the moment:

$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach($items as $item) {
    $product = Mage::getModel('catalog/product')->load($item->getProductId());
    var_dump($item);
    var_dump($product);
}

$product gives me the custom attributes I need to pull. $item gives me the quantity in the cart (which I need in this case)

The dump on $item retrieves this:

'parent_item_id' => null

Which is no good. I need it to have the id of the Grouped Product this Simple Product is associated to.

Any ideas?

  • 写回答

1条回答 默认 最新

  • duanchuang6978 2012-05-14 16:02
    关注

    Take a look at Mage_Catalog_Model_Product_Type_Grouped::getParentIdsByChild(). Pass in your simple product ID and you'll get back an array of parent IDs for grouped products.

    $grouped_product_ids = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($simple_product_id);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?