Magento – Get Configurable Parent from simple product in quote when simple product has multiple parents

blockscartconfigurable-productmagento-1.9quoteitem

So I have a client that has about 14 Configurable products that are basically the same thing (logo item). Then they have created a simple product for each base color(Blue, Pink, Black)[3 total simple products]. They have then taken the 3 simple products and assigned each of them to the 14 configurable products so that the logo from the configurable products gets the base color simple product selected.

In their setup the configurable products house the images for these products. However, since you can only purchase the simple product the image that is being select is ALWAYS coming over as the image from product 1 of 20 (lowest product_id), no matter which selection is chosen.

The code im going to be trying to update is in a custom block that is being used on the checkout_onepage_index reference.

My question is:

From the sales/quote_item Model, how can I determine exactly which parent the
child item was selected from?

or

From the checkout/cart Model, can something be achieved?

Things I have already seen but are not really helpful.

Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId())

result

Array
(
    [0] => 45207
    [1] => 45209
    [2] => 45210
    [3] => 45211
    [4] => 45212
    [5] => 45213
    [6] => 45214
    [7] => 45215
    [8] => 45216
    [9] => 45217
    [10] => 45218
    [11] => 45219
    [12] => 45220
    [13] => 45222
)
  • This just returns an array of all parentIds for the child item. Which is great, but there is no indication of which Parent Product this simple product was selected from.

Best Answer

You Can set parent id in info buy request when you add an item to cart. Which is saved in sales_flat_quote_item_options. Below is the code which you use to add additional info to your item:

$params = array(
    'parent_id'=> (int)$parent_id
);
$request = new Varien_Object();
$request->setData($params);

$result = $quote->addProduct($product, $request);

To retrieve this information you can use the below code:

$options = $_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct());
print_r($options['info_buyRequest']['parent_id']);