Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Stores’ ids not saved when creating a product
 
Capitaine Commerce
Member
 
Avatar
Total Posts:  68
Joined:  2007-09-01
Lille, France
 

Hi !
I developed a import module for Magento.
Everything works fine, except for the stores’ ids that are not saved.
For example :

$my_product Mage::getModel('catalog/product');
$stores = array(1);
$my_product->setPostedCategories($categories);
[....]
$my_product
->save();
I also add a lot of others parameters of course but this lines seem to be ineffectives and indeed in the catalog_product_store table of the Magento database, products bound to the desired store don’t appear. I must execute an SQL query “manually” to get it right, but that is pretty painful and I really would like to automate it.
So, does anyone have an idea about this ?
 
Magento Community Magento Community
Magento Community
Magento Community
 
Capitaine Commerce
Member
 
Avatar
Total Posts:  68
Joined:  2007-09-01
Lille, France
 

I found this in the productController

$product->setStoreId((int) $storeId)
                   ->
addData($data['product'])
                ->
setStoreId((int) $storeId)
                ->
setPostedStores($stores)
                ->
setPostedCategories($categories)
                ->
setRelatedProducts($relatedProducts)
                ->
setSuperAttributes($superAttributes)
                ->
setSuperLinks($superLinks)
                ->
setUpSellProducts($upSellProducts)
                ->
setCrossSellProducts($crossSellProducts);

Why do you have to setStoreId twice ?
Where does the setPostedStores function stand ???

Thanks a lot for your help

 
Magento Community Magento Community
Magento Community
Magento Community
 
Capitaine Commerce
Member
 
Avatar
Total Posts:  68
Joined:  2007-09-01
Lille, France
 

Ok, ok, reply to myself, but that can help someone else too.
To insert products into multiple stores, you have to create an array with the stores id in it.
Exemple :

$stores = array(0,0);
Which means that products will be inserted in the store with id=0 and the store with the id=1.
Products from the store 1 wille be copied from the store with id=0.
I hope this is quite clear....
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top