Jump to content

Change Related Products Sort Order


refloblu

Recommended Posts

hello guys,
i need a little help, in my products page it shows "related products" but in the related products box it shows the oldest ones i added in the same category, how can i make appear the most recent instead of the oldest?

 

i think the change should be made in productscategory.tpl

 

{if count($categoryProducts) > 0 && $categoryProducts !== false}
<div id="blockproductscategory" class="clearfix">
<h2 class="bordercolor">{$categoryProducts|@count} {l s='other products in the same category:' mod='productscategory'}</h2>
<div id="{if count($categoryProducts) > 5}productscategory{else}productscategory_noscroll{/if}">
{if count($categoryProducts) > 5}<a id="productscategory_scroll_left" title="{l s='Previous' mod='productscategory'}" href="javascript:{ldelim}{rdelim}">{l s='Previous' mod='productscategory'}</a>{/if}
<div id="productscategory_list">
<ul {if count($categoryProducts) > 5}style="width: {math equation="width * nbImages - 20" width=144 nbImages=$categoryProducts|@count}px"{/if}>
{foreach from=$categoryProducts item='categoryProduct' name=categoryProduct}
{if count($categoryProducts) < 6}style="width: {math equation="width / nbImages" width=94 nbImages=$categoryProducts|@count}%"{/if}
<li class="bordercolor{if $smarty.foreach.categoryProduct.last} item_last{/if}">
<a href="{$link->getProductLink($categoryProduct.id_product, $categoryProduct.link_rewrite, $categoryProduct.category, $categoryProduct.ean13)}" class="lnk_img" title="{$categoryProduct.name|htmlspecialchars}"><img class="bordercolor" src="{$link->getImageLink($categoryProduct.link_rewrite, $categoryProduct.id_image, 'medium_default')}" alt="{$categoryProduct.name|htmlspecialchars}" /></a>
<h5><a class="product_link" href="{$link->getProductLink($categoryProduct.id_product, $categoryProduct.link_rewrite, $categoryProduct.category, $categoryProduct.ean13)}" title="{$categoryProduct.name|htmlspecialchars}">{$categoryProduct.name|truncate:0:'...'|escape:'htmlall':'UTF-8'}</a></h5>
{if $ProdDisplayPrice AND $categoryProduct.show_price == 1 AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
<p><span class="price pricecolor">{convertPrice price=$categoryProduct.displayed_price}</span></p>
{/if}
</li>
{/foreach}
</ul>
</div>
{if count($categoryProducts) > 5}<a id="productscategory_scroll_right" title="{l s='Next' mod='productscategory'}" href="javascript:{ldelim}{rdelim}">{l s='Next' mod='productscategory'}</a>{/if}
</div>
<script type="text/javascript">
$('#productscategory_list').trigger('goto', [{$middlePosition}-3]);
</script>
</div>
{/if}
 
can someone help me with what change the code to? 
Link to comment
Share on other sites

Here is an old solution applied in ver 1.4 of Prestashop,

 

https://www.prestashop.com/forums/topic/89260-accessories-on-producttpl-sorted-by-price/

 

I took a look at the code in, classes/product.php and it is the same, so it looks like you could give it a try. I do hope you have made a copy of your web site to experiment with. 

Link to comment
Share on other sites

Right  :)

 

That is module productscategory.

 

You will find it here, modules\productscategory\productscategory.php
 
I haven't tried this so make a backup,
 
Change 
 
$category_products = $category->getProducts($this->context->language->id, 1, 100); /* 100 products max. */
 
To
 
$category_products = $category->getProducts($this->context->language->id, 1, 100,'position','DESC'); /* 100 products max. */
 
Remember to clear all cache after.
  • Thanks 1
Link to comment
Share on other sites

  • 4 years later...
  • 2 months later...
On 12/12/2015 at 3:08 PM, Bill Dalton said:

Right  :)

 

That is module productscategory.

 

You will find it here, modules\productscategory\productscategory.php
 
I haven't tried this so make a backup,
 
Change 
 
$category_products = $category->getProducts($this->context->language->id, 1, 100); /* 100 products max. */
 
To
 
$category_products = $category->getProducts($this->context->language->id, 1, 100,'position','DESC'); /* 100 products max. */
 
Remember to clear all cache after.

I tried this and it works!

It now shows product in descending order by ID product.

what if I wanted it to show related products in descendig order by date add/modified?

Thank you!

Link to comment
Share on other sites

2 minutes ago, Bill Dalton said:

For related products I would suggest looking for a module that allowed you to add related products with options you need. For example I sell clothing, so color match on related items is awesome.

thank you for your answer. yes, color match or undercategory match would be also nice (I sell shoes)

So, there is no other way than with a module? If I purchased a module for any option I wanted...my Prestashop would crash 🙂

 

Link to comment
Share on other sites

Yes, I seldom buy a module that works on install. It's one very frustrating thing that I dislike about Prestashop. You will almost always need to contact the module author. It is so stupid. You then need to create a FTP login and give Backoffice access, and wait for this person to make time. And they even want you to give them a good review for what? Fixing something you just paid for?

But enough of that rant. Mapping related products will always require humans, but the modules can help with placement and presentation. But to get exactly what you want may also require hiring professional help. It is best to make a list of things that can't be solved any other way and wait until all other things are up and running. Then get quotes for these type of items as one job. It may save money and you should hopefully end up exactly where you want. Keeping in mind, life is a compromise. 

Link to comment
Share on other sites

you are right, I have the same problem, especialy when the assistance expires and I have to pay again... Very frustrating. but I think it is the price to pay for a opn source software, in the hads of professionals it allows a freedom that we don't have with other platforms.

Anyway after looking here and there I solved the issue, I write it here, in case it is useful for other people. To have related products of the same category but ordered for date added, descent order, I changed

$category_products = $category->getProducts($this->context->language->id, 1, 100); /* 100 products max. */

to

$category_products = $category->getProducts($this->context->language->id, 1, 100,'date_add','DESC'); /* 100 products max. */

and that works.

 

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