Jump to content

Products sorting problem- Position inside category


Recommended Posts

I'm facing a problem using Prestashop - Version 1.3.6.0

I want to sort my products manually.

I have set in the backoffice Default order by:"Position inside category"

Default order way: "Ascending"

I know I can move the products by pressing the "UP" or "Down" button.
Depending on the browser I use I can also "Drag" and "Drop" to the position I want.

Now here comes my problem.

I "Drag and Drop" my products to the positions I want them to be.

But some positions does not seem to be saving.
I have spend hours to set them right, but they seem to be mixing anyway.

first screenshot, I have dragged al the items to the position I want.
refreshing will result in a mixup without any logic.

Anyone with an idea that can help me, please send in your comments

42891_alN2zgW4Qt4l8ji9Po8N_t

42892_fnhu5VLQJIr4mrHUYJb1_t

Link to comment
Share on other sites

I just tried at my demo site, it seems work fine.
I only have a few products (sample product from PrestaShop), seem no problem.

I am guessing, maybe you have many products and you move them very fast, before thay are refected, you refreshed the page. (depends your server performance and your connection, in some cases, it takes a little bit time).
try to do it slowly to see if it changes.

  • Sad 1
Link to comment
Share on other sites

I have PS 1.4.0.17 and I also have this problem. I opened a thread about this problem, but now I have found this thread, and I'm kind a glad not to be only one with this problem ... So could somebody help us with this?? Is very annoying that we could not sort products in the way we want ...

Link to comment
Share on other sites

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

inveostore.com, thank you for your work. If I just want the product sorting problem fixed, which file do I have to replace? I don't want to overwrite all the PS files, I'm using 1.3.7.

Or is there any other solution to the sorting problem?

Link to comment
Share on other sites

This problem with the jumping products inside the category is complete BS. I've spent way too much time juggling them around until they settle in an order close to what I want. I don't want to change my PS version. Can someone please provide a fix for this?

Link to comment
Share on other sites

  • 3 weeks later...

No I can't upgrade to another version.<br/><br/>I have a custom made multishop-, multilanguage en multi currency websites that hangs all together.<br/><br/>Updating will bring me allot more trouble then a simple fix for repositioning the items.

Link to comment
Share on other sites

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

Hi, I'm using 1.43 and getting the same problem with newly added categories only. Im not sure when the problem started, the only thing I can think of, is that I added the Quick Access Module about 6 weeks ago.

 

Found this information from which I was able to resolve the problem, but do not know why it occured in the first place.

http://forge.prestashop.com/browse/PSCFI-1596

Link to comment
Share on other sites

I found the root cause and a fix.

 

 

In file admin/ajax.php search for ajaxProductsPositions and find

 

 $product = new Product($id_product);
 if (Validate::isLoadedObject($product))
 { 

 

and just after this line add the following:

 

   // modification start
   $product->cleanPositions( $id_category );
   if( isset($positions[$position +1]) ) {
       $pos = explode('_', $positions[$position +1]);
       $to_product = $pos[2];
       $offset = 0;
   } else if ( isset($positions[$position -1]) ) {
       $pos = explode('_', $positions[$position -1]);
       $to_product = $pos[2];
       $offset = 1;
   }     
   $position = 0;

   if( $to_product) {
     $result = Db::getInstance()->ExecuteS('SELECT `position`
			FROM `'._DB_PREFIX_.'category_product`
			WHERE  id_product = '. pSQL($to_product) .
			' AND id_category = '. pSQL($id_category) .'');
     $position = $result[0]['position'] + $offset;
   }
   // modification end

 

Root cause of wrong product sort is that the new position was based on the position on the html page and not based on the position within the database.

[1] when you have al lot of products and show the products 50 till 100 then if you move product 62 to 61 then it would become 11 (or 10 I forgot)

[2] when you delete products then the sort sequence is not in line, so you cannot just count the products on the page.

[3] I think with cloning a product it will also clone the position to be identical to original part. I didnt test but noticed identical positions and using the product clone option.

 

I've added code to check the new position based on the sort id of the next product. And if no next product then based on the previous +1 and if this one doesnt exists ( so the product is the only product of the category) then it will get new position 0 (probably this cannot occure but anyway).

 

Hope this will help you as even with 1.4.4 I needed to correct this (also on 1.3.6).

  • Like 1
Link to comment
Share on other sites

Thank you Shopimport for the modification, and thanks twister for the heads up.

 

I made the change in the ajax.php file, having tried to position a product immediately before and it wouldn't hold the position. After the change I was able to change the position of the same product in the same way and it kept the new position. For a minute every product whose position I changed maintained the new position. Then I noticed that some products still jump around. It seems that the modification works for some products and not others, in any case the sorting is more manageable than before. I'll do some more testing.

Link to comment
Share on other sites

Hi Dan1, after reviewing my code I found a possible situation for which it could go wrong and maybe you experienced that one :-)

 

The situation is when the product was located in more than one category. It might have selected the position of the other category.

 

I have modified my code above so this situation should also be fixed.

 

For the insiders... the line I have added:

' AND id_category = '. pSQL($id_category) .'');

Link to comment
Share on other sites

Thanks.

 

In my case the products in question are only in one category. After applying the latest code they still jump around. But they appear to be more manageable than before the fix. Before the fix I could be there for half an hour moving the products around until by chance they settle in an order that's close to what I want. Now it seems to take only a few tries.

Link to comment
Share on other sites

  • 3 weeks later...

Any news on this yet?

 

The code fix mentioned above must be from an older version as my admin/ajax.php did not have the exact line shopimport.nl said to look for. I'm using 1.4.4.0.

 

Here is the code from my file. Where should I add the code fix? Thanks!

 

/* Modify product position in catalog */
if (array_key_exists('ajaxProductsPositions', $_POST))
{
$way = (int)(Tools::getValue('way'));
$id_product = (int)(Tools::getValue('id_product'));
$id_category = (int)(Tools::getValue('id_category'));
$positions = Tools::getValue('product');
if (is_array($positions))
 foreach ($positions AS $position => $value)
 {
  // pos[1] = id_categ, pos[2] = id_product, pos[3]=old position
  $pos = explode('_', $value);
  if ((isset($pos[1]) AND isset($pos[2])) AND ($pos[1] == $id_category AND (int)$pos[2] === $id_product))
  {
if ($product = new Product((int)$pos[2]))
 if (isset($position) && $product->updatePosition($way, $position))
  echo "ok position $position for product $pos[2]\r\n";
 else
  echo '{"hasError" : true, "errors" : "Can not update product '. $id_product . ' to position '.$position.' "}';
else
 echo '{"hasError" : true, "errors" : "This product ('.$id_product.') can t be loaded"}';
break;
  }
 }
}

Link to comment
Share on other sites

  • 3 months later...
Any news on this yet? The code fix mentioned above must be from an older version as my admin/ajax.php did not have the exact line shopimport.nl said to look for. I'm using 1.4.4.0. Here is the code from my file. Where should I add the code fix? Thanks!
 /* Modify product position in catalog */ if (array_key_exists('ajaxProductsPositions', $_POST)) { $way = (int)(Tools::getValue('way')); $id_product = (int)(Tools::getValue('id_product')); $id_category = (int)(Tools::getValue('id_category')); $positions = Tools::getValue('product'); if (is_array($positions)) foreach ($positions AS $position => $value) { // pos[1] = id_categ, pos[2] = id_product, pos[3]=old position $pos = explode('_', $value); if ((isset($pos[1]) AND isset($pos[2])) AND ($pos[1] == $id_category AND (int)$pos[2] === $id_product)) { if ($product = new Product((int)$pos[2])) if (isset($position) && $product->updatePosition($way, $position)) echo "ok position $position for product $pos[2]\r\n"; else echo '{"hasError" : true, "errors" : "Can not update product '. $id_product . ' to position '.$position.' "}'; else echo '{"hasError" : true, "errors" : "This product ('.$id_product.') can t be loaded"}'; break; } } } 

 

 

I have same prohlem, i have 1.4.4. version and have other code. Like kallym

Link to comment
Share on other sites

hey guys... not sure if this is still a problem, but I'm on 1.3.x and I have fixed this issue. it appears that the homefeatured.php was sorting things by date added instead of by position. so....

 

in modules/homefeatured.php look for:

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10), 'DATE_ADD', 'DESC');

 

and change it to

$products = $category->getProducts(intval($params['cookie']->id_lang), 1, ($nb ? $nb : 10), 'position', 'ASC');

 

that should now sort the products by position and ASC... so it looks like the way thing look in the back office... home that helps!

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

hi, i've the same problem with version 1.4.5.1 with the same code of others 1.4 versions

does anybody found a solution???

I've to reorder a lot of product and order can be modified only by clicking on arrows and...it's very boring and slow

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 weeks later...
  • 3 months later...

I have the same issue with 1.4.0.17... any ideas anybody ?

I also have PS 1.4.0.17 and had same problem. However, when I used shopimport.nl script, it got better. I could not say, that it works for 100%. But I am able to order products in 3-4 attempts. In origin version I had not been able to move some product even if I had move it 100 times.

 

So progress. I also tied new version 1.4.8 and it runs OK in this version. I tired it on same serves as my old version 1.4.0.17.

Link to comment
Share on other sites

  • 8 months later...
  • 3 weeks later...

I thought product sort in admin was broken but actually it's not. After rearranging products in "Home" category in admin it didn't show the products rearrange in the front office. It only sorted home feature products accordingly to what I rearranged. It turns out "EACH" category/subcategory in admin has to be rearranged separately to what you want not just Home category. For this to work in ALL categories you have created... you have to open "EACH" category/subcategory that you created in Admin and rearrange products with-in each. Hope this helps.

 

Make sure in Admin you have "Default order by:" set to "Position inside category" under Preference tab and in "Products" link.

Link to comment
Share on other sites

  • 4 months later...

I have the same problem in 1.5.4.1. I have sorted all products in each category and set Default order by to Position inside category etc. The problem started for me when I first used the drag and drop sorting feature in version 1.4.6.2. I had hoped that upgrading would fix the problem, but it hasn't.

 

Is there a fix going around for 1.5.4.1?

Link to comment
Share on other sites

I have the same problem in 1.5.4.1. I have sorted all products in each category and set Default order by to Position inside category etc. The problem started for me when I first used the drag and drop sorting feature in version 1.4.6.2. I had hoped that upgrading would fix the problem, but it hasn't.

 

Is there a fix going around for 1.5.4.1?

 

 

Hi mowax, when you use the arrows to change the category position, the changes do not reflect on your Front Office?

Link to comment
Share on other sites

Hi Benjamin, that's right. Both the arrow sorting and drag-drop features have no affect on Front office. Also if I remove the products from the category and re-add them, they reappear in the same position as before and cannot be repositioned.

 

I've noticed this only is a problem in some categories. I think the categories that are affected are the ones I used the drag-drop sorting method on which I believe is what caused it.

Link to comment
Share on other sites

Hi Benjamin, that's right. Both the arrow sorting and drag-drop features have no affect on Front office. Also if I remove the products from the category and re-add them, they reappear in the same position as before and cannot be repositioned.

 

I've noticed this only is a problem in some categories. I think the categories that are affected are the ones I used the drag-drop sorting method on which I believe is what caused it.

 

 

Make sure to have a backup and take a look at this fix. You will have to change one line http://forge.prestashop.com/browse/PSCFV-10263

Link to comment
Share on other sites

Thanks for the suggestion, I have applied the change but it had no affect unfortunately.

 

A further observation is that the categories affected are all parent categories. In some cases, products located by default in the subcategories are displayed in the parent category in the Front office, even though they are not listed in the Back office. For example this category: http://www.duratex.co.uk/24-door-mats. In the back-office, this category is empty (apart from subcategories). All these products are from the subcategories and have been populated and sorted randomly. If I add these products to the parent category in the back-office, I cannot reposition them.

 

Hope I'm making sense :wacko:

Edited by mowax (see edit history)
Link to comment
Share on other sites

Thanks for the suggestion, I have applied the change but it had no affect unfortunately.

 

A further observation is that the categories affected are all parent categories. In some cases, products located by default in the subcategories are displayed in the parent category in the Front office, even though they are not listed in the Back office. For example this category: http://www.duratex.co.uk/24-door-mats. In the back-office, this category is empty (apart from subcategories). All these products are from the subcategories and have been populated and sorted randomly. If I add these products to the parent category in the back-office, I cannot reposition them.

 

Hope I'm making sense :wacko:

 

Can you do me a favor and toggle the option in Preferences>Products>Default order way (ascending or descending) and see if either way works for you. 

Link to comment
Share on other sites

hi stottycabanas, thank you for your suggestion, I didn't get it to work though. I have this:

 

        {if $products}
            {if !isset($subcategories)}
            <div class="content_sortPagiBar">
                {include file="$tpl_dir./pagination.tpl"}
                <div class="sortPagiBar clearfix">
                    {include file="./product-sort.tpl"}
                    {include file="./product-compare.tpl"}
                    {include file="./nbr-product-page.tpl"}
                </div>
            </div>
            {/if}

 

Does it look correct? I cleared all caches but there is no change

Link to comment
Share on other sites

mowax, the closing {\if} needs to be lower down, I meant after the final <\div> in the whole file. Red text below denotes the additions.

{if $products}
  {if !isset($subcategories)}
    <div class="content_sortPagiBar">
      {include file="$tpl_dir./pagination.tpl"}
      <div class="sortPagiBar clearfix">
        {include file="./product-sort.tpl"}
        {include file="./product-compare.tpl"}
        {include file="./nbr-product-page.tpl"}
      </div>
    </div> 


    {include file="./product-list.tpl" products=$products} 


    <div class="content_sortPagiBar">
      <div class="sortPagiBar clearfix">
        {include file="./product-sort.tpl"}
        {include file="./product-compare.tpl"}
        {include file="./nbr-product-page.tpl"}
      </div>
      {include file="./pagination.tpl"}
    </div>
  {/if}
{/if}

Hope that's OK, Dave.

  • Like 1
Link to comment
Share on other sites

thanks stottycabanas, it works. it would be still good to be able to choose which products appear in the parent category, and be able to sort them manually. I will use your method for the time being, as it is better than having a jumbled mess of products.

Link to comment
Share on other sites

  • 1 month later...

Any news on this yet?

 

The code fix mentioned above must be from an older version as my admin/ajax.php did not have the exact line shopimport.nl said to look for. I'm using 1.4.4.0.

 

Here is the code from my file. Where should I add the code fix? Thanks!

 

/* Modify product position in catalog */
if (array_key_exists('ajaxProductsPositions', $_POST))
{
$way = (int)(Tools::getValue('way'));
$id_product = (int)(Tools::getValue('id_product'));
$id_category = (int)(Tools::getValue('id_category'));
$positions = Tools::getValue('product');
if (is_array($positions))
  foreach ($positions AS $position => $value)
  {
   // pos[1] = id_categ, pos[2] = id_product, pos[3]=old position
   $pos = explode('_', $value);
   if ((isset($pos[1]) AND isset($pos[2])) AND ($pos[1] == $id_category AND (int)$pos[2] === $id_product))
   {
	if ($product = new Product((int)$pos[2]))
	 if (isset($position) && $product->updatePosition($way, $position))
	  echo "ok position $position for product $pos[2]\r\n";
	 else
	  echo '{"hasError" : true, "errors" : "Can not update product '. $id_product . ' to position '.$position.' "}';
	else
	 echo '{"hasError" : true, "errors" : "This product ('.$id_product.') can t be loaded"}';
	break;
   }
  }
}

 

similar with me. how to fix in prestashop vershion 1.4.6.2 ??

Link to comment
Share on other sites

Hello all, for v1.5.6 please remember that in order to change the Product Position Within a Category you need to go to 

 

Catalog>Products>Filter by Category>Select Category>Click the little black Arrows in Position tab (click twice if needed) > Now you can move up or down or drag your products to the desired position. 

 

Please let me know if this works with you

Link to comment
Share on other sites

  • 2 months later...

hi benj,

 

doing exactly as you said, filtering products by category and trying to reposition, with no luck. they keep reverting back to original positions.

 

1.5.6.2 here and the problem still persists. just as nowak's problem. products in certain categories cannot be re positioned. very frustrating. if anyone has a solution, please advise. thank you.

Edited by cagrie (see edit history)
Link to comment
Share on other sites

similar with me. how to fix in prestashop vershion 1.4.6.2 ??

 

Hi,

Just add:

$product->cleanPositions( $id_category );

After (~326 line):

if ($product = new Product((int)$pos[2])) {

Don't forget surround block with { } inside if :)

 

You don't have to do anything after that, just sort products in category. I had only messed up positions, like 1, 5, 14, 32 etc, but it should work if you have duplicate positions too.

 

Tried in PS v1.4.8.

 

Thanks shopimport.nl for initial code ;)

Edited by innercode (see edit history)
Link to comment
Share on other sites

  • 2 months later...

I have a version 1.4.8.2 of PS, my solution has been add a new line in admin/ajax.php at line 316:

 

$way = (int)(Tools::getValue('way'));
$id_product = (int)(Tools::getValue('id_product'));
$id_category = (int)(Tools::getValue('id_category'));
Product::cleanPositions($id_category);
$positions = Tools::getValue('product');

Sorry for my English

Link to comment
Share on other sites

  • 4 months later...

I found that if some products have the same position number (even 0) then drag and drop position changing does not work. I think that qualifies as a bug.

 

I was using SQL to quickly add products to categories and setting the position to default (0), which wouldn't allow me to re-position them in the back office. I started using the id_product for the position to have unique positions, and then I could re-position in the back office; however, it's still not perfect.

 

If I have positions like 452, 784, 792, 810, etc., I can move 792 to the top and it will become 0, but the others will keep their number. Then, if I try to move something down the list below non-re-positioned products it won't work. For example, if I then try to move 452 to the bottom, it will just stay where it is. I'm guessing it would get the position 1 or something low, but the others are still 784 and 810.

Link to comment
Share on other sites

  • 1 month later...

Hi I have the same problem as you others have explained.

When I try to reposition in BO it does not completely take affect in front. Se below.

I tried moving back and forth, some will reposition, others wont.

 

I use PrestaShop 1.5.6.2

 

BO.JPG

front.JPG

Link to comment
Share on other sites

You can try product-sort from the free script Triple Edit (http://www.prestashop.com/forums/topic/185401-free-script-product-mass-edit-category-multi-edit-order-edit/). 

 

It is limited to 1000 articles per category (500 for Prestashop 1.4). 

 

As a bonus it will renumber your positions, so that they become a regular 0,1,2,3, etc. again - what enables future moving the BO.

Link to comment
Share on other sites

  • 9 months later...

I have the same problem in 1.6.0.14. I have set the product positions in Catalog > Products > Filter by Category, in every category (not just the Home category). In BO everything seems fine, but the problem is that the positions are not reflected in FO for the 2nd level categories.

 

For example:

- Home (positioning works fine)

-- 2nd Level Cat (doesn't work)

---- 3rd Level Cat (works)

 

Preferences > Products > Pagination is set to Position Inside Category, Ascending.

 

I'm using a custom theme. What files should I need to look into to sort this issue?

 

Many thanks for your replies.

Link to comment
Share on other sites

To answer my own question, the solution was to disable the "Layered navigation block" module for the affected categories. You do that by going to the module, click on Configure > Filters Templates > Edit and then deselect categories that are giving you problems.

 

I'm not sure why this module would affect default sorting (by Position Inside Category), though.

Link to comment
Share on other sites

  • 4 months later...

Hi,

For those who still have this problem and if you have blocklayered module activated on your store then here is what i did to fix the problem.
1- Go to blocklayered.php file
2- Go to getProductByFilters function
3- line 2013/2014 add this "AND cp.id_category = '.(int)$id_parent.'"

4- Save and enjoy  :)

 

Rachid Chihabi  ;)

Link to comment
Share on other sites

  • 3 weeks later...

Hi,

 

For those who still have this problem and if you have blocklayered module activated on your store then here is what i did to fix the problem.

1- Go to blocklayered.php file

2- Go to getProductByFilters function

3- line 2013/2014 add this "AND cp.id_category = '.(int)$id_parent.'"

4- Save and enjoy  :)

 

Rachid Chihabi  ;)

 

 

Could you specify where that line should go? Or attach your blocklayered.php? Our line numbering doesn't seem to match. :)

Link to comment
Share on other sites

  • 1 year later...

After trying all the multitudinous options people suggested, I figured out a simple thing that doesn't require coding, changing any additional settings beyond the 'position inside' one often mention, etc.

 

When looking at your product list in the back office, look just to the right of the word "Position" in the header row above the products.  There's an arrow up & down beside it...  click the UP ^ arrow, which causes them to change in the order of the position # letting you to be able to view them by "position" in the back office.  Therefore, when you re-sort/organize your products up & down, it 'sticks' because it's sorted by position, not ID, name or some other option. 

 

Be sure to click the radio box beside the product you're moving before using the cross-hairs to drag it up or down.  It doesn't work most of the time if you don't check that box.

 

When nothing else worked, this worked for me.  Hope it works for you too. 

 

P.S.  I use a WordPress site that does this same thing, and that's how I figured out to try it in Prestashop too. 

Link to comment
Share on other sites

×
×
  • Create New...