Magento - как установить связанные продукты, когда я добавляю новый сгруппированный продукт - PullRequest
1 голос
/ 10 марта 2011
$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();

Но я не знаю, как добавить Ассоциированные продукты в мой новый сгруппированный продукт. Я попробовал этот код:

$new_product = Mage::getResourceModel('catalog/product_type_grouped')
        ->setUsedProducts($newProduct->getId(), array(7390));

Это не правильно. Я надеюсь, что кто-нибудь может мне помочь.

Привет, Рапи

1 Ответ

1 голос
/ 06 мая 2014

В последнее время мне это нужно для настраиваемых продуктов в 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
...