-
Posts
17 -
Joined
-
Last visited
Profile Information
-
Location
World
-
Activity
Web development agency
tidjean's Achievements
Newbie (1/14)
2
Reputation
-
Hello everyone I am trying to get the categories through the web-service. This is working well, now i want to sort them by position to get the same order than the website with &sort=[position_ASC] here my request : https://www.lespinards.com/api/categories?output_format=JSON&display=[name,id,id_parent]&filter[active]=1&filter[level_depth]=[2,3]&sort=[position_ASC] sadly, I got an SQL error : {"errors":[{"code":97,"message":"[SQL Error] Column 'position' in order clause is ambiguous. From ObjectModelCore->getWebserviceObjectList() Query was : \n\t\tSELECT DISTINCT main.`id_category` FROM `ps_category` AS main\n\t\t LEFT JOIN `ps_category_shop`\n\t\t\t\t\t\t\t\t\t\tAS `multi_shop_category`\n\t\t\t\t\t\t\t\t\t\tON (main.`id_category` = `multi_shop_category`.`id_category`) \n\t\tWHERE 1 AND `multi_shop_category`.id_shop = 1 AND `main`.`active` LIKE \"1\"\n AND `main`.`level_depth` BETWEEN \"2\" AND \"3\"\n\n\t\t ORDER BY ``.`position` ASC\n\n\t\t"}]} Looks like the table category_shop and category have both the field position. I think we should be able to sort by position from the webservice, do you have any idee how to do it?
-
Hello guy, I found a way to fix this issue. In my file admin/filemanager/dialog.php it was something like : <?php if (@opendir($R5BE2189EB2A912678F23F2073A3BC854.$RA4BFDF845AF4F7BD4D840F616BDC06E7.$R72B348B27FF345F641BA18E350517021) === false){ ?> <br/> <div class="alert alert-error">There is an error! The upload folder there isn't. Check your config.php file. </div> <?php } ... so I remove the complet file and replace by the one from prestashop zip. This one contain this: <?php if (@opendir($current_path.$subfolder.$subdir) === false) { ?> <br/> <div class="alert alert-error">There is an error! The upload folder there isn't. Check your config.php file. </div> <?php } ... And now it's working. Good luck!! Tidjean
-
Hello, first you must add a "install fonction" to you module.php's code. Then you can have into your module directory /modules/yourmodules/controllers/admin/foo.php Here my exemple code : class Routines extends Module{ public function __construct(){ $this->name = 'routines'; $this->tab = 'scripts'; $this->version = 1.0; $this->author = 'Tidev'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Routines'); $this->description = $this->l('Scripts to manage orders and products.'); } public function install(){ if( (parent::install() == false)||(!$this->_createTab()) ) return false; return true; } public function uninstall(){ if (!parent::uninstall() || !$this->uninstallModuleTab('Stksupplier') || !$this->uninstallModuleTab('reorder') || !$this->uninstallModuleTab('AdminMainNewTab')) return false; return true; } private function _createTab(){ $parent_tab = new Tab(); $parent_tab->class_name = 'AdminMainNewTab'; $parent_tab->id_parent = 0; $parent_tab->module = $this->name; $parent_tab->name[(int)Configuration::get('PS_LANG_DEFAULT')] = 'Routines'; $parent_tab->add(); $this->installModuleTab('Stksupplier', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>'STK'), $parent_tab->id); $this->installModuleTab('reorder', array((int)(Configuration::get('PS_LANG_DEFAULT'))=>$this->l('Re-Order')), $parent_tab->id); // if(!$test) return false; return true; } private function installModuleTab($tabClass, $tabName, $idTabParent){ // $idTab = Tab::getIdFromClassName($idTabParent); $idTab = $idTabParent; $pass = true ; @copy(_PS_MODULE_DIR_.$this->name.'/logo.gif', _PS_IMG_DIR_.'t/'.$tabClass.'.gif'); $tab = new Tab(); $tab->name = $tabName; $tab->class_name = $tabClass; $tab->module = $this->name; $tab->id_parent = $idTab; $pass = $tab->save(); return($pass); } private function uninstallModuleTab($tabClass){ $pass = true ; @unlink(_PS_IMG_DIR_.'t/'.$tabClass.'.gif'); $idTab = Tab::getIdFromClassName($tabClass); if($idTab != 0) { $tab = new Tab($idTab); $pass = $tab->delete(); } return($pass); }
-
Thank you, I will try that!
- 2 replies
-
- context shop
- set context
-
(and 3 more)
Tagged with:
-
Bonjour je suis en train d'ecrire mon module pour un site prestashop multistore et j'ai un soucis. J'essaie au de changer le context afin de change de store. echo Context::getContext()->shop->id; Shop::setContext(Shop::CONTEXT_SHOP, 2); echo "\n".Context::getContext()->shop->id; die(); Mais ceci me retourne : 1 1 quel est mon soucis? Merci de votre aide.
-
- context shop
- context shop id
-
(and 3 more)
Tagged with:
-
hello , I have a problem, I need to change my shop-> from the context. if I do this : echo Context::getContext()->shop->id; Shop::setContext(Shop::CONTEXT_SHOP, 2); echo "\n".Context::getContext()->shop->id; die(); This return : 1 1 But i have five shops on my multistore prestashop, maybe i do something wrong... I don't know. Thanks for your helping.
- 2 replies
-
- context shop
- set context
-
(and 3 more)
Tagged with:
-
Remove all products from the database
tidjean replied to sideone's topic in Ecommerce x PrestaShop [ARCHIVE BOARD]
To run it, you can use phpmyadmin, then you have to choices: Copy and paste the code into a file on your cumputer "script.sql". Select your prestashop database and clique to "import". You select the file "script.sql". You clique on "sql" and copy and paste the code. WIthout phpmyadmin: Copy and paste the code into a file on your cumputer "script.sql". If you can connect to your database with a terminal mysql -u admin -p -h host database < script.sql Sure there is more option to do it, but phpmyadmin is very friendly. -
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?
-
[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); }
-
I think it is something about with Context::getContext() ... maybe.
-
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();
-
[SOLVED] Category::add more and more long to execute
tidjean replied to tidjean's topic in Core developers
[sOLVED] Hello, I found the problem, it's because the system rebuild my tree category. So I add this line before save my category : $object->doNotRegenerateNTree =1; So my function is : (No more timestamp) function create_category($name, $parent_id = false){ if($name && $name != ''){ $object = new Category(); $object->name = $name; if (!$parent_id){ $parent_id = Configuration::get('PS_HOME_CATEGORY'); } $object->id_parent = $parent_id; $object->link_rewrite = array((int)(Configuration::get('PS_LANG_DEFAULT')) => fix_string($name,'url')); $object->doNotRegenerateNTree =1; //add product $object->add(); $object->id_category = $object->id; $object->id_category_default = $object->id; $object->update(); return $object; } }