blufix79 Posted February 20, 2017 Share Posted February 20, 2017 Goodmorning They are grappling with the ordering of categories using webservices. I expected it to work on passing "position" the value of the position which I would assume the law category. Instead it always moved as the last. Checking the code, I noticed that the update method always performs a addPosition when called via service. This happens even if not explicitly the step position value, but keep the one currently set in the category. Anyone have any idea why there is this logic? Here is the part of the update code, the PrestaShop version 1.6.1.4, but this behavior have also been found in successive versions. // If the parent category was changed, we don't want to have 2 categories with the same position if (!isset($changed)) { $changed = $this->getDuplicatePosition(); } if ($changed) { if (Tools::isSubmit('checkBoxShopAsso_category')) { foreach (Tools::getValue('checkBoxShopAsso_category') as $id_asso_object => $row) { foreach ($row as $id_shop => $value) { $this->addPosition((int)Category::getLastPosition((int)$this->id_parent, (int)$id_shop), (int)$id_shop); } } } else { foreach (Shop::getShops(true) as $shop) { $this->addPosition((int)Category::getLastPosition((int)$this->id_parent, $shop['id_shop']), $shop['id_shop']); } } } I would like to manage the ordering of the category among the categories appertenenti at the same level. Eg: ParentCategory |-Subcategory1 - position 1 |-Subcategory2 - position 2 |-Subcategory3 - position 3 |-Subcategory4 - position 4 |-Subcategory5 - position 5 I would like to move the category with position 2 instead of 3, but via webservices category is always moved to the end and I find myself in this situation: ParentCategory |-Subcategory1 - position 1 |-Subcategory3 - position 2 |-Subcategory4 - position 3 |-Subcategory5 - position 4 |-Subcategory2 - position 5 This behavior occurs even if I change only the name of the category, for example, or even though the reference as well as the recovery, without changing anything. It is always moved to last. Does anyone know why this logic? Thank you Link to comment Share on other sites More sharing options...
Bao NGUYEN Posted December 8, 2020 Share Posted December 8, 2020 hello, i just want change category name by webservice I dont want change position but when i change name or set position Webservice is set position category modified at botton of list my code look like this $opt = [ 'resource' => 'categories', 'id' => $id, ]; $xml = $this->webService->get($opt); $resources_categ = $xml->children()->children(); unset($resources_categ->position); // set or unset doesn't workd unset($resources_categ->level_depth); //must remove because webservice return 400 level_depth not writable. Please remove this attribute of this XML unset($resources_categ->nb_products_recursive);// must remove $resources_categ->doNotRegenerateNTree = true;// it doesn't work $resources_categ->name->language[0][0] = $name; //change new name $resources_categ->link_rewrite->language[0][0] = Tools::str2url($name); $return = $this->webService->edit([ 'resource' => 'categories', 'id' => $id, 'putXml' => $xml->asXML(), ]); I look for in class Category.php // If the parent category was changed, we don't want to have 2 categories with the same position if (!isset($changed)) { $changed = $this->getDuplicatePosition(); } if ($changed) { if (Tools::isSubmit('checkBoxShopAsso_category')) { ............... } else { foreach (Shop::getShops(true) as $shop) { $this->addPosition((int)Category::getLastPosition((int)$this->id_parent, $shop['id_shop']), $shop['id_shop']); } } } variable $changed is always = true because when we change the name or change position, it will have the same position so the position category is modified to the last position of the same parent. There is a way to change the name of the category by web service without changing position? and change position in the category with recalculate all siblings 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