Jump to content

Comment changer le positionnement des produits phares ?


Recommended Posts

  • 2 weeks later...
  • 3 weeks later...

I hit this problem.

Using phpmyadmin look in ps_catgeory_product. For each category, there should be a set of id_product and position pairs, e.g. for id_category = 1, I had 6 entries with values of (id_product, position) of (10,0), (13,3), (14,4), (12,2), (11,1) and (15,4).

If the positions are not in strict monotonic sequence, e.g. 0,1,2,3,4,5... I think the updatePosition code cannot reorder the products and you get the error message.

I corrected it to read (10,0), (13,1), (14,5), (12,4), (11,3) and (15,2), and then I could reorder the products OK.

I assume the update code was interrupted at some time before it could complete an update operation. It should really detect the invalid position values and correct them as best it can [in this example by updating to (10,0), (13,3), (14,4), (12,2), (11,1) and (15,5)]. At least then the user could correct the order.

Hope this helps,
Brian

Link to comment
Share on other sites

  • 1 month later...

I have a fast patch for this bug:

Open the file classes/Product.php, find for this piece of code (about line 286):

       if (!$res = Db::getInstance()->ExecuteS('
       SELECT cp.`id_product`, cp.`position`, cp.`id_category` 
       FROM `'._DB_PREFIX_.'category_product` cp
       WHERE cp.`id_category` = '.intval(Tools::getValue('id_category')).' 
       ORDER BY cp.`position` '.(intval($way) ? 'ASC' : 'DESC')))



And reemplace for:

$valor = Tools::getValue('id_category');

     if ($valor==0)
      $valor = 1;

       if (!$res = Db::getInstance()->ExecuteS('
       SELECT cp.`id_product`, cp.`position`, cp.`id_category` 
       FROM `'._DB_PREFIX_.'category_product` cp
       WHERE cp.`id_category` = '.intval($valor).' 
       ORDER BY cp.`position` '.(intval($way) ? 'ASC' : 'DESC'))) 



The problems is that id_category is always 0 when is home and the select don't return rows because the home category is 1.

Backup your database before of testing this patch, for me work like a charm.

Link to comment
Share on other sites

I have a fast patch for this bug:

Open the file classes/Product.php, find for this piece of code (about line 286):

       if (!$res = Db::getInstance()->ExecuteS('
       SELECT cp.`id_product`, cp.`position`, cp.`id_category` 
       FROM `'._DB_PREFIX_.'category_product` cp
       WHERE cp.`id_category` = '.intval(Tools::getValue('id_category')).' 
       ORDER BY cp.`position` '.(intval($way) ? 'ASC' : 'DESC')))



And reemplace for:

$valor = Tools::getValue('id_category');

     if ($valor==0)
      $valor = 1;

       if (!$res = Db::getInstance()->ExecuteS('
       SELECT cp.`id_product`, cp.`position`, cp.`id_category` 
       FROM `'._DB_PREFIX_.'category_product` cp
       WHERE cp.`id_category` = '.intval($valor).' 
       ORDER BY cp.`position` '.(intval($way) ? 'ASC' : 'DESC'))) 



The problems is that id_category is always 0 when is home and the select don't return rows because the home category is 1.

Backup your database before of testing this patch, for me work like a charm.



[solved]
I'm going to be a little cheeky and mark this as solved because I tried the patch and it worked perfectly! Many thanks to Juanparati for the simple fix.
Link to comment
Share on other sites

  • 3 weeks later...
I have a fast patch for this bug:

Open the file classes/Product.php, find for this piece of code (about line 286):

       if (!$res = Db::getInstance()->ExecuteS('
       SELECT cp.`id_product`, cp.`position`, cp.`id_category` 
       FROM `'._DB_PREFIX_.'category_product` cp
       WHERE cp.`id_category` = '.intval(Tools::getValue('id_category')).' 
       ORDER BY cp.`position` '.(intval($way) ? 'ASC' : 'DESC')))



And reemplace for:

$valor = Tools::getValue('id_category');

     if ($valor==0)
      $valor = 1;

       if (!$res = Db::getInstance()->ExecuteS('
       SELECT cp.`id_product`, cp.`position`, cp.`id_category` 
       FROM `'._DB_PREFIX_.'category_product` cp
       WHERE cp.`id_category` = '.intval($valor).' 
       ORDER BY cp.`position` '.(intval($way) ? 'ASC' : 'DESC'))) 



The problems is that id_category is always 0 when is home and the select don't return rows because the home category is 1.

Backup your database before of testing this patch, for me work like a charm.



it works so good, tks!!!! :)
Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...
  • 5 weeks later...

Thank you

Pour ceux qui ne comprennent pas du tout l'anglais il faut faire une modification du fichier product.php qui se trouve dans le dossier classes
changer à partir de la ligne 286 ou si c'est comme moi c'est à partir de la ligne 293

if (!$res = Db::getInstance()->ExecuteS('
       SELECT cp.`id_product`, cp.`position`, cp.`id_category` 
       FROM `'._DB_PREFIX_.'category_product` cp
       WHERE cp.`id_category` = '.intval(Tools::getValue('id_category')).' 
       ORDER BY cp.`position` '.(intval($way) ? 'ASC' : 'DESC')))



par

$valor = Tools::getValue('id_category');

     if ($valor==0)
      $valor = 1;

       if (!$res = Db::getInstance()->ExecuteS('
       SELECT cp.`id_product`, cp.`position`, cp.`id_category` 
       FROM `'._DB_PREFIX_.'category_product` cp
       WHERE cp.`id_category` = '.intval($valor).' 
       ORDER BY cp.`position` '.(intval($way) ? 'ASC' : 'DESC'))) 



et cela fonctionne très bien.

Link to comment
Share on other sites

  • 4 months 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
×
×
  • Create New...