Jluis Posted December 16, 2018 Share Posted December 16, 2018 Hi , I have a remark that I wish to share with you ; I created associated products for my product, in front office I have a precise display, afterwards I wanted to reorder the associated products according to the importance so that they are displayed in front again according to the desired order, I used the following code js to make drug and drop for the associated products of the back office. This works but when I register the product in question it disappeared. for the file C:\wamp64\www\prestashop_1.7.4.4\admin116caruwq\themes\default\js\bundle\product , i made that change : $( function() { $( "#form_step1_related_products-data" ).sortable(); $( "#form_step1_related_products-data" ).disableSelection(); } ); How could i manage realted products from backoffice in order to manipulate its orders in front ? any idea , suggestion is appreciated Link to comment Share on other sites More sharing options...
Jluis Posted January 8, 2019 Author Share Posted January 8, 2019 Now i get the result 😃 I made the modifications below : adding an access_order field at the ps_accessory table . 2. adding the code below in /data/www/clients/client1/web2/web/adminxxxx/themes/default/js/bundle/product/product-related.js $('#form_step1_related_products-data').sortable({ axis: 'y', update: function (event, ui) { var data = $(this).sortable('serialize'); var product_orders = []; $('#form_step1_related_products-data li').each(function() { product_orders.push( $(this).find('input[type="hidden"]').val()); }); var formData = new FormData(); formData.append("datajsonorder", JSON.stringify(product_orders)); var request = new XMLHttpRequest(); request.open("POST", "/ReorderAccessories.php"); request.send(formData); } }); 3. le fichier ReorderAccessories.php <?php include('config/config.inc.php'); include('init.php'); //var_dump($_POST); $product_order = json_decode($_POST['datajsonorder']); //var_dump($product_order);die(); $i = 1; foreach ($product_order as $value) { // Execute statement: // UPDATE [Table] SET [Position] = $i WHERE [EntityId] = $value $query = "UPDATE `"._DB_PREFIX_."accessory` SET access_order= $i WHERE id_product_2 = $value "; //var_dump( $query);die(); Db::getInstance()->Execute($query); $i++; } ?> 4- set ORDER BY acc.`access_order` in getAccessories($id_lang, $active = true) function (Product.php) the only concern is when I refresh the product page of the BO the order of accessories returns to the original order, but the resulat of the front is the desired result and the order in the database. Any idea to reach this issue ?? Any suggestion Link to comment Share on other sites More sharing options...
conhelrad Posted November 17, 2020 Share Posted November 17, 2020 Hello @Jluis if you're still looking for the answer to your last question 2 after 2 years : you have to add "ORDER BY `access_order`'" to the function getAccessoriesLight in Product.php too to make it work in the backoffice. Link to comment Share on other sites More sharing options...
jean7373 Posted March 2, 2023 Share Posted March 2, 2023 (edited) On 11/17/2020 at 6:34 PM, conhelrad said: Hello @Jluis if you're still looking for the answer to your last question 2 after 2 years : you have to add "ORDER BY `access_order`'" to the function getAccessoriesLight in Product.php too to make it work in the backoffice. hi, where exactly to put ORDER BY `access_order` in function getAccessoriesLight? I have done: WHERE `id_product_1` = ' . (int) $id_product . ' ORDER BY `access_order` ' When i save the product, in access_order column is set to 0 again..... and order is lost If i change the order, in front is ok, if i refresh the page in backend, withoud click to save, is ok.... if i click save and refresh page, all is set to 0 and the order is lost Edited March 2, 2023 by jean7373 (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