Sorting 如何在prestashop中根据价格对产品进行排序

Sorting 如何在prestashop中根据价格对产品进行排序,sorting,prestashop,Sorting,Prestashop,我需要根据产品价格高低进行分类 在下面的位置显示同一类别的其他产品 \modules\productscategory\productscategory.tpl {if count($categoryProducts) > 0 && $categoryProducts !== false} <div class="clearfix blockproductscategory"> <h2 class="productscategory_h2">{$ca

我需要根据产品价格高低进行分类

在下面的位置显示同一类别的其他产品

\modules\productscategory\productscategory.tpl

{if count($categoryProducts) > 0 && $categoryProducts !== false}
<div class="clearfix blockproductscategory">
<h2 class="productscategory_h2">{$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" width=107 nbImages=$categoryProducts|@count}px"{/if}>
{foreach from=$categoryProducts item='categoryProduct' name=categoryProduct}
<li {if count($categoryProducts) < 6}style="width:60px"{/if}>
<a href="{$link->getProductLink($categoryProduct.id_product, $categoryProduct.link_rewrite, $categoryProduct.category, $categoryProduct.ean13)}" class="lnk_img" title="{$categoryProduct.name|htmlspecialchars}"><img src="{$link->getImageLink($categoryProduct.link_rewrite, $categoryProduct.id_image, 'medium_default')}" alt="{$categoryProduct.name|htmlspecialchars}" /></a>
<p class="product_name">
<a href="{$link->getProductLink($categoryProduct.id_product, $categoryProduct.link_rewrite, $categoryProduct.category, $categoryProduct.ean13)}" title="{$categoryProduct.name|htmlspecialchars}">{$categoryProduct.name|truncate:14:'...'|escape:'htmlall':'UTF-8'}</a>
</p>
{if $ProdDisplayPrice AND $categoryProduct.show_price == 1 AND !isset($restricted_country_mode) AND !$PS_CATALOG_MODE}
<p class="price_display">
<span class="price">{convertPrice price=$categoryProduct.displayed_price}</span>
</p>
{else}
<br />
{/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}

如何根据价格对产品进行分类

通过将排序信息传递给getProducts成员函数,可以对产品进行排序。更改以下代码:

// Get infos
$categoryProducts = $category->getProducts($this->context->language->id, 1, 100); /* 100 products max. */
到下面的代码

// Get infos
 $categoryProducts = $category->getProducts($this->context->language->id, 1, 100, 'price', 'ASC'); /* 100 products max. */

在产品编号(在您的例子中是100)之后,您可以传递Order By(在上面的代码中是price,您可以传递其他选项,如position、name、id\u product等)参数,然后传递Order Way参数(在上面的示例中是ASC,您也可以使用DESC)

您可以通过将排序信息传递给getProducts成员函数对产品进行排序。更改以下代码:

// Get infos
$categoryProducts = $category->getProducts($this->context->language->id, 1, 100); /* 100 products max. */
到下面的代码

// Get infos
 $categoryProducts = $category->getProducts($this->context->language->id, 1, 100, 'price', 'ASC'); /* 100 products max. */

在产品数量(在您的例子中是100)之后,您可以传递Order By(在上面的代码中是price,您可以传递其他选项,如position、name、id_product等)参数,然后传递Order Way参数(在上面的示例中,它是ASC,您也可以使用DESC)

Hi@altafhussain我还有一个疑问,如何从productscategory.tpl文件调用hookProductFooter函数欢迎您。您可以直接从模板文件调用hookProductFooter。您必须在控制器或模块或php代码中直接调用特定的钩子。Hi@altafhussain。你能帮我吗嗨,你能给我一个1.5版的解决方案吗?我需要它hi@altafhussain我还有一个疑问,如何从productscategory.tpl文件调用hookProductFooter函数不客气。您可以直接从模板文件调用hookProductFooter。您必须在控制器或模块或php代码中直接调用特定的钩子。Hi@altafhussain。你能帮我吗嗨,你能给我一个1.5版的解决方案吗?我需要这个