Jump to content

prestashop 1.7 order related products from backoffice


Jluis

Recommended Posts

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

  • 4 weeks later...

Now i get the result 😃 I made the modifications below :

  1.  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

  • 1 year later...
  • 2 years later...
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 by jean7373 (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...