I'm trying to create grouped product and attach simple one to it. In admin section both of them are available, but in frontend available only simple product.
If I enter into product edit mode in admin panel (indifferent simple or grouped) and just save it without changing anything, grouped product will appear in frontend.
I can't figure out where is a problem.
// create grouped product
$product = Mage::getModel('catalog/product');
$product->setTypeId( 'grouped' );
$product->setAttributeSetId( 13 );
$product->setSku( 'K101596245' );
...
$product->setVisibility( 4 );
$product->setStatus( 1 );
$product->setTaxClassId( 0 );
$product->setStockData(array(
'is_in_stock' => 0,
));
$product->save();
unset($product);
// create simple product
$simpleProduct = Mage::getModel('catalog/product');
$simpleProduct->setData( 'type_id', 'simple' );
...
$simpleProduct->setData( 'status', 1 );
$simpleProduct->setData( 'price', $values['retailPrice'] );
$simpleProduct->setData( 'special_price', $values['price'] );
$simpleProduct->setData( 'stock_data', array(
'is_in_stock' => 1,
'qty' => 9,
));
$simpleProduct->save();
// attach simple to grouped
Mage::getModel('catalog/product_link_api')->assign("grouped", $product->getId(), $simpleProduct->getId());
The same result with:
// attach simple to grouped
$relation_data = array();
$relation_data[ $simpleProduct->getId() ] = array('qty' => 9, 'position' => 0);
$product->setGroupedLinkData($relation_data);
$product->save();