Jump to content

[SOLVED] Get feature value id inside product list (category)


Nikita9999

Recommended Posts

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 by Nikita9999 (see edit history)
Link to comment
Share on other sites

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

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

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 by Nikita9999 (see edit history)
Link to comment
Share on other sites

 

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

{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

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

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

  • Nikita9999 changed the title to [SOLVED] Get feature value id inside product list (category)

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...