on import I would like to add imported products as bundl开发者_开发知识库ed products to a list of bundle products.
I extended Mage_Catalog_Model_Convert_Adapter_Product and used this class in a custom Dataflow, before the imported row is saved the following code is executed:
//Load product model collection filtered by attribute set id
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('name')
->addFieldToFilter('attribute_set_id', 12);
// loop through products
foreach($products as $p){
// get product options
$options = $p->getTypeInstance(true)->getOptionsCollection($p);
}
What I need to do next is determine what is the right option (by title), and add the product as a selection to it.
$option->addSelection($selection);
But how do I get the option title and how do i create the selection from my product?
To get the option title i did:
$option->getData('default_title');
To create the selection i did:
$selection = new Mage_Bundle_Model_Selection();
$selection->addData(array(
'entity_id' => //bundle id,
'option_id' => $option->getId(),
'product_id' => //bundled item id,
'selection_price_value' => 0.00,
'selection_qty' => 1,
'selection_can_change_qty' => 0,
));
$selection->save();
to add the selection to the option i did:
$option->addSelection($selection);
$option->addData(array(
'store_id' => 1,
'title' => 'Abonnement'
));
$option->save();
I don't know why i have to set the title and store_id, because the option already exists so i think it shouldn't be necessary, but if i don't do this i get a "missing store_id" or "missing title" error.
I like Magento but it's huge, documentation should be better.
精彩评论