0

Im currently writing a export tool for Mage1 in order to export products from Mage1 to Mage2.

I thereby want to determine if a product in the collection is part of a configurable product.

My current collection is set up this way:

$_productCollection = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->setPageSize(500)
                        ->setCurPage(1)
                        ->addAttributeToSort('sku', 'ASC')
                        ->addAttributeToFilter('type_id', array('eq' => 'simple'))
                        ->addAttributeToSelect('*')
                        ->load();

First, I request only simple products right now. If I delete this line, I get every products in the shop in the collection, but In the code every product is handled like a simple product currently.

Now, following is happening:

I request the script and get my information for all simple products. In the store I use to test there are configurable products AND bundle products. I know want to know how I could determine if a product is part of a configurable or bundle article and how I could assign those "simple" products to the respective configurable products?

I generate a CSV which I can upload in Mage2 successfully, but as I already said, it only imports simple products (as desired so far).

I googled a little (https://www.google.de/search?q=get+assigned+simple+products+for+a+configurable+product&ie=utf-8&oe=utf-8&gws_rd=cr&ei=b3i8VuD6BIevswGWtbGACw) but I'm still clueless. :/ Hopefully someone here can help me with this matter.

Also, I checked this thread: Checking if a Magento product is a child of a configurable product - but I don't get what to do with the respective name. Maybe this is already the right guess?

Thanks, Max

Community
  • 1
  • 1
Atr_Max
  • 269
  • 1
  • 4
  • 20

1 Answers1

1

Yes there is a way of doing so. Have a look at the model class Mage_Catalog_Model_Product_Type_Configurable, there is a function called getParentIdsByChild.

Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($productId);

It will return an empty array if no parents id's have been found.

André Ferraz
  • 1,511
  • 11
  • 29
  • Great! Any idea how I could connect those results with the original configurable product? The snippet already works as I expected it... Babysteps from now on. – Atr_Max Feb 11 '16 at 15:15