tidjean Posted April 4, 2013 Share Posted April 4, 2013 (edited) Hello, 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->save(); create_product_image($Image_Large,$object->id); $object->updateCategories($object->category, TRUE); $object->update(); Edited April 4, 2013 by tidjean (see edit history) Link to comment Share on other sites More sharing options...
tidjean Posted April 4, 2013 Author Share Posted April 4, 2013 I think it is something about with Context::getContext() ... maybe. Link to comment Share on other sites More sharing options...
tidjean Posted April 5, 2013 Author Share Posted April 5, 2013 (edited) [sOLVED] I found it, I should set the context with the code bellow before saving my product : if (Shop::isFeatureActive()){ Shop::setContext(Shop::CONTEXT_ALL); } Edited April 5, 2013 by tidjean (see edit history) Link to comment Share on other sites More sharing options...
tidjean Posted April 5, 2013 Author Share Posted April 5, 2013 (edited) Now I have another probleme, I need to manage different prices for my shops. So when I create a product I do this : $object->save(); create_product_image($Image_Large,$object->id); $object->updateCategories($object->category, TRUE); $object->update(); $shops_all = Shop::getContextListShopID(); foreach($shops_all as $s){ Shop::setContext(Shop::CONTEXT_SHOP,$s); $object->price = formule_price($FNET_Wholesale_Price,$s); $object->save(); } //set the context to use all shops. Shop::setContext(Shop::CONTEXT_ALL); 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); $product->save(); foreach($result as $r){ Shop::setContext(Shop::CONTEXT_SHOP,$r); $product->price = formule_price($product->wholesale_price,$r); $product->save(); } Shop::setContext(Shop::CONTEXT_ALL); return $result; } But my function does not work. I do not understand why. Any sugestion? Edited April 5, 2013 by tidjean (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now