Magento Forum

   
Creating configurable product via Models
 
parkin_m
Jr. Member
 
Total Posts:  18
Joined:  2008-12-01
 

Ok so I can create a new model using a catalog_product model and saving it, no problems here.

$model Mage::getModel('catalog/product');
$model->save();

I can also set a load of properties of the object before saving such as price, sku, description etc.

'sku'                   => 'test-sku',
'store'                 => 0,
'type'                  => 'Simple Product'
'categories'        => '12,25',
'name'                => 'Test Product ',
'description'        => 'Here is the description of this product.',
'price'                 =>  '12.99'

Now I thought setting type to ‘Simple Product’ was doing just that, but on trying to change it to Configurable Product, configurable or any other type I am discovering that it is most likely this type isnt even used and the product is just defaulting to simple.

I had a look through the technical docs and came across Mage::getModel(’Catalog/Product/Type/Configurable’); and thought aha, maybe im using the wrong model type etc, this didn’t work either!

Other interesting methods I found were: setTypeId() and setTypeInstance() both of which i thought might change the type of product either by ID or by passing an object of the type but so far no luck.

Has anyone managed to create a configurable product using just models and not the product API or the magento importer?

 
Magento Community Magento Community
Magento Community
Magento Community
 
parkin_m
Jr. Member
 
Total Posts:  18
Joined:  2008-12-01
 

P.s to devs: there is a bug in magento Product API: line 144

$product->setStoreId($this->_getStoreId($store))

$store is never defined in this create method!

 
Magento Community Magento Community
Magento Community
Magento Community
 
parkin_m
Jr. Member
 
Total Posts:  18
Joined:  2008-12-01
 

Woo… database export text compare for the win! Why there is no documentation for this type of stuff is beyond me!

I exported the database and then created a configurable product by hand, then compared the SQL and found that type_id was being set to configurable..Ok so onto the code…

$model->setTypeId('configurable');

Easy! I hope this helps someone else!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top