Add simple configurable automatically

I have a code like this:

$product_config = new Mage_Catalog_Model_Product_Type_Configurable();
$product_config->setProduct($product_grouped);
$assigned_products = $product_config->getUsedProducts();

      

So, I create a new configuration, install the product and get all the products in use.

Here's my problem: I want to add another product to the "List" of "Used Products", so when I save the product later, the new product should also be added as a new "custom option" with a new price.

It was very easy with Grouped Products, but I can't seem to find a way to do it also with a custom product :(

Thanks for the help!

+3


source to share


1 answer


You can use the resource model of a custom product type to add a simple product to a custom one, for example:



$configurableId = 135;
$simpleId = 91;
$configurableProduct = Mage::getModel('catalog/product')->load($configurableId);

$simples = $configurableProduct->getTypeInstance('configurable', $configurableProduct)
    ->getUsedProductIds();
$simples[] = $simpleId;

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

      

0


source







All Articles