Nikita9999 Posted December 2, 2021 Share Posted December 2, 2021 (edited) Hi, I'm looking for a way to get the feature value id (not the feature id) inside my category page I've done an override of CategoryController, and want to grab the product list then loop on it and do something like this : $ids_feature = array_column(Product::getFeaturesStatic((int)Tools::getValue('id_product')), 'id_feature_value'); to attach on each product the id_feature_value but I'm stuck to retrieve the product list, or perhaps is there a better way to retrieve the id_feature_value Thanks Edited December 7, 2021 by Nikita9999 (see edit history) Link to comment Share on other sites More sharing options...
ShashaGreyBeMyBride Posted December 4, 2021 Share Posted December 4, 2021 As far as I understood, I guess I did something similar to this using pure SQL. It runs over a certain order, checks all the values of all products this order contains, and retrieves the total amount of each feature value. It returns something like this: +--------+----------+---------------+---------------+ | order | customer | featureATotal | featureBTotal | +--------+----------+---------------+---------------+ | 678952 | 5896 | 85 | 585 | | 678555 | 5158 | 212 | 412 | +--------+----------+---------------+---------------+ Let me know whether you want to see the code. Link to comment Share on other sites More sharing options...
ventura Posted December 5, 2021 Share Posted December 5, 2021 You can use the hook displayProductListReviews to display the product listing information on the category pages. Link to comment Share on other sites More sharing options...
Nikita9999 Posted December 6, 2021 Author Share Posted December 6, 2021 Thanks for your answer, in fact I want to override this method from CategoryController and add feature value and their id : protected function getProductSearchQuery() { $query = new ProductSearchQuery(); $query ->setIdCategory($this->category->id) ->setSortOrder(new SortOrder('product', Tools::getProductsOrder('by'), Tools::getProductsOrder('way'))); return $query; } Link to comment Share on other sites More sharing options...
ventura Posted December 6, 2021 Share Posted December 6, 2021 To display the information in the product listing of the category page it´s better to use the hook Link to comment Share on other sites More sharing options...
Nikita9999 Posted December 6, 2021 Author Share Posted December 6, 2021 (edited) 15 minutes ago, ventura said: To display the information in the product listing of the category page it´s better to use the hook but displayProductListReviews is a tpl hook, I'm in the php controller I can't use it ? In the tpl I miss some informations related to the product (feature value id) and I want to add them using the controller Edited December 6, 2021 by Nikita9999 (see edit history) Link to comment Share on other sites More sharing options...
ventura Posted December 6, 2021 Share Posted December 6, 2021 In this hook you can set up the logic to display the contents of each product, as for example used by the productcomments module to display the ratings. Link to comment Share on other sites More sharing options...
ventura Posted December 6, 2021 Share Posted December 6, 2021 Alternatively, if you don't need more data than the features you can add the code directly in templates/catalog/_partials/miniatures/product.tpl for example like this {assign var='features' value=Product::getFeaturesStatic((int)$product.id)} {foreach from=$features item='feature'} {assign var='feature_lang' value=Feature::getFeature($language.id, $feature.id_feature)} {assign var='feature_value_lang' value=FeatureValue::getFeatureValueLang($feature.id_feature_value)} <p> {$feature.id_feature} {$feature_lang.name}: {FeatureValue::selectLang($feature_value_lang, $language.id)}</p> {/foreach} Link to comment Share on other sites More sharing options...
Nikita9999 Posted December 6, 2021 Author Share Posted December 6, 2021 {assign var='features' value=Product::getFeaturesStatic((int)$product.id)} Thanks thats exactly what I wanted to do in the controller !! it's working perfectly I don't understand what you mean by using the displayProductListReviews hook ? do you have an example ? Link to comment Share on other sites More sharing options...
ventura Posted December 6, 2021 Share Posted December 6, 2021 10 minutes ago, Nikita9999 said: {assign var='features' value=Product::getFeaturesStatic((int)$product.id)} Thanks thats exactly what I wanted to do in the controller !! it's working perfectly I don't understand what you mean by using the displayProductListReviews hook ? do you have an example ? Yes, as I mentioned before, the default hook included displayProductListReviews which for example uses the productcomments module, to show in the product list the user ratings. This hook allows to host in an own .tpl the content that is required to appear in each product. Link to comment Share on other sites More sharing options...
Nikita9999 Posted December 7, 2021 Author Share Posted December 7, 2021 23 hours ago, ventura said: Yes, as I mentioned before, the default hook included displayProductListReviews which for example uses the productcomments module, to show in the product list the user ratings. This hook allows to host in an own .tpl the content that is required to appear in each product. Ok thank you I'll take a look on it to see how it works I closed the topic as my issue is solved Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now