php - Prestashop 1.7.6.5 : sorting product by characteristics
Get the solution ↓↓↓I want to be able to display my products by sorting them by characteristics (ps_feature). How to do and which files to modify? I managed to do this sort by modifying the templates/catalog/_partial/products.tpl file and creating a function in the override/classes/Product.php file and it works. But it works if I display all my products without pagination. As soon as I set up a pagination (50 products per page for example), the function only works for each group of 50 products but not for all the products! I must have to make this modification in another file before but I do not know which one (categoryController.php, ...)? Thanks for your help
I modify this file : products.tpl with the new function getOrdreFeatureProduct:
<div class="products row">
{$tabFeatureProduct = Product::getOrdreFeatureProduct($listing.products)}
{** {foreach from=$listing.products item="product"} **}
{foreach from=$tabFeatureProduct item="product"}
{$display = Product::getProductsWithRights($product.id, $category.id, $customer.id)}
{if $display == "true"}
{block name='product_miniature'}
{include file='catalog/_partials/miniatures/product.tpl' product=$product}
{/block}
{/if}
{/foreach}
And here is my function which allows to re-sort the characteristics :
public static function getOrdreFeatureProduct($tabprod)
{ // Nouveau Tri :
// - Famille -> ['features'][x]['name'] == 'Famille'
// - Lieux -> ['features'][x]['name'] == 'Lieux'
// - Type -> ['features'][x]['name'] == 'Type'
// - Collecion -> ['features'][x]['name'] == 'Collection'
// - Ss-CatГ©gorie -> ['features'][x]['name'] == 'Sous-Categorie'
//***** 1er TRI sur la Famille *****
foreach($tabprod as $key => $value)
{ //recherche de la clГ© Famille
$clef='';
foreach($value['features'] as $kf => $vf)
{ if($vf['name'] == 'Famille')
{ $clef = $kf;
}
}
$tri_famille[$key] = $value['features'][$clef]['value'];
}
//***** 2ГЁme TRI sur le LIEUX_PDF *****
foreach($tabprod as $key => $value)
{ //recherche de la clГ© Lieux
$clef='';
foreach($value['features'] as $kf => $vf)
{ if($vf['name'] == 'Lieux_PDF')
{ $clef = $kf;
}
}
$tri_lieux[$key] = $value['features'][$clef]['value'];
}
//***** 3ГЁme TRI sur le TYPE *****
foreach($tabprod as $key => $value)
{ //recherche de la clГ© Type
$clef='';
foreach($value['features'] as $kf => $vf)
{ if($vf['name'] == 'Type')
{ $clef = $kf;
}
}
$tri_type[$key] = $value['features'][$clef]['value'];
}
//***** 4ГЁme TRI sur la Collection PDF *****
foreach($tabprod as $key => $value)
{ //recherche de la clГ© Type
$clef='';
foreach($value['features'] as $kf => $vf)
{ if($vf['name'] == 'Collection_PDF')
{ $clef = $kf;
}
}
$tri_collec[$key] = $value['features'][$clef]['value'];
}
//***** 5ГЁme TRI sur la Sous-CatГ©gorie *****
foreach($tabprod as $key => $value)
{ //recherche de la clГ© Type
$clef='';
foreach($value['features'] as $kf => $vf)
{ if($vf['name'] == 'Sous-Categorie')
{ $clef = $kf;
}
}
$tri_sscat[$key] = $value['features'][$clef]['value'];
}
//Tri complet selon les 4 ordres de tri : Famille/Type/Collection_PDF/Sous-Categorie
array_multisort($tri_famille, SORT_ASC,
$tri_lieux, SORT_ASC,
$tri_type, SORT_ASC,
$tri_collec, SORT_ASC,
$tri_sscat, SORT_ASC,
$tabprod);
return $tabprod;
}
This function reorders my products well but only for each page and not for all the products. if I modify the maximum number of products per page (1000 for example), it works perfectly. it is probably necessary to make a modification in a program before but I do not know which? Maybe the ProductListingFrontController.php program but I don't know where? Thanks.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: warning: undefined array key
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.