Jump to content

script add product multishop


Recommended Posts



I create a module that add product in PHP. But now my prestashop is multishop. So my module need multishop function, but I cannot find any documentation about multi shop programming. Could you help?


 $defaultLanguage = new Language((int)(Configuration::get('PS_LANG_DEFAULT')));
 $object = new Product();
 $object->price = formule_price($FNET_Wholesale_Price);
//   $object->id_supplier = $SKU;
 $object->id_tax_rules_group = 0;
 $object->name = array(1=> $Name,5=>translate_name($Name,'fr'));
//   $object->id_manufacturer = $SKU;
 $object->quantity = 0;
 $object->reference =$SKU;
 $object->minimal_quantity = 1;
 $object->additional_shipping_cost = 0;
 $object->wholesale_price = 0;
 $object->ecotax = 0;
 $object->width = 0;
 $object->height = 0;
 $object->depth = 0;
 $object->weight = 1;
 $object->out_of_stock = 0;
 $object->active = 1;
 $object->id_category_default = $default_category;
 $object->category = $categories;
 $object->available_for_order = 1;
 $object->show_price = 1;
 $object->on_sale = 0;
 $object->meta_keywords = $Name;

 $object->description_short = array(1 => $Product_Descriptions,5 => translate_description($Product_Descriptions,'fr'));
 $object->link_rewrite = array(1 => fix_string($Name,'url'),5 => fix_string($Name,'url'));
 $object->description = array(1 => $Product_Descriptions,5 => translate_description($Product_Descriptions,'fr'));
 //save the product
 $object->updateCategories($object->category, TRUE);

Edited by tidjean (see edit history)
Link to comment
Share on other sites

Now I have another probleme, I need to manage different prices for my shops. So when I create a product I do this :


 $object->updateCategories($object->category, TRUE);

 $shops_all = Shop::getContextListShopID();
 foreach($shops_all as $s){
  $object->price = formule_price($FNET_Wholesale_Price,$s);

 //set the context to use all shops.

 set_log('product created:'.$object->id);

 return $object->id;

This code works perfectly. but I also need to add my products that are already created to all shop. For now, all my products are in the default shop, but I also want them to all of them. Here is my code:


function product_exits_all_shops($product_id){
//get all shop's id where the product is.
$shops_with_product = Product::getShopsByProduct($product_id);

//reformat the array to be abble to compare it.
$shops_var = array();
foreach($shops_with_product as $s){
 $shops_var[] = $s['id_shop'];
$shops_with_product = $shops_var;

//Get all shop available.
$shops_all = Shop::getContextListShopID();

//compare this two list of shop's ids.
$result = array_diff($shops_all, $shops_with_product);
$product = new Product($product_id);

foreach($result as $r){
 $product->price = formule_price($product->wholesale_price,$r);


return $result;


But my function does not work. I do not understand why. Any sugestion?

Edited by tidjean (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...