Jump to content

prestashop 1.7 order related products from backoffice


Jluis
 Share

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 

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

  • 1 year later...

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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More