$newProduct = Mage::getModel('catalog/product');
$newProduct->setSku('testsku');
$newProduct->setPrice(100);
$newProduct->setAttributeSetId(4);
$newProduct->setCategoryIds(array(3,4));
$newProduct->setTypeId("grouped");
$newProduct->setName('Product Name');
$newProduct->setDescription('The Product Description');
$newProduct->setShortDescription('Brief Description');
$newProduct->setStatus(1);
$newProduct->setTaxClassId('2');
$newProduct->setCreatedAt(strtotime('now'));
$newProduct->save();
但我不知道如何将关联产品添加到我的新Grouped产品中。 我试过这段代码:
$new_product = Mage::getResourceModel('catalog/product_type_grouped')
->setUsedProducts($newProduct->getId(), array(7390));
这是不正确的。我希望有人可以帮助我。
问候,Rapi
答案 0 :(得分:1)
最近我需要这个用于magento的可配置产品。也许这会有所帮助:
$loader = Mage::getResourceModel('catalog/product_type_configurable')->load($configurableProduct, NULL);
$children = $configurableProduct->getTypeInstance()->getUsedProductIds(); // actual list of children
$children[] = $product->getId(); // some simple product id
$children = array_unique($children);
$loader->saveProducts($configurableProduct, array_values($children)); // save new list of children to configurable product