Configurable Product – Add One Associated Product to Multiple Configurable Products

associate-productsconfigurable-product

here is an explanation of what we have:

multiple simple products for each t-shirt, we use an attribute set with color, size and sex.

The end product is a designed t-shirt, it has a pattern image and must take the t-shirts from the inventory (that's why we use a configurable product)

So, we have around 100 different simple products – but even more configurable products (each pattern gets it's own so the number is huge).

But what when we create a new simple product – let's say a blue t-shirt L sized which we didn't have prior to creating the configurable products. Is there a way to add the associated product to multiple configurable products at once – and not have to go into all products to add it?

Best Answer

So what you need is the way to add the simples to the configurable?

// $newids is of form:
$newids = array($id => 1, $id2 => 1);
// $configurableProduct = Mage::getModel('catalog/product);

Mage::getResourceModel('catalog/product_type_configurable')
  ->saveProducts($configurableProduct, array_keys($newids));

Then you can hook into saving of a product. Before save you check wether an ID is given, if not, add a flag. In after_save you check for the flag, if it is set, you load loop over all configurable products and add the new simple one.

Related Topic