[email protected] Posted April 7, 2019 Share Posted April 7, 2019 Hello, how can I create a feature for colors? I created a new feature color, but it seems not possible to show it in the filters with the little colored squares like it does for the attribute color. If I use attributes for colors I have to create combinations for each product with size and color, but it would be quicker to add the color as a feature, since most of the products have only one color. Can you help me please? Thanks Link to comment Share on other sites More sharing options...
Rodrigo B Laurindo Posted April 7, 2019 Share Posted April 7, 2019 Hello @[email protected] If you use colors in features, the filters would have colors in two different places. So a customer searching for a white color would have to select white feature and white attribute, right? Because you would not be able to select an attribute value in features. Or I am not understanding you? Link to comment Share on other sites More sharing options...
[email protected] Posted April 8, 2019 Author Share Posted April 8, 2019 Hello Rodrigo Thanks for your answer. I can disable the color attribute in the filter and leave only the feature filter. The problem is that for color feature it seems not possible to show it in the filters with the little colored squares like it does for the attribute color. I Thanks Link to comment Share on other sites More sharing options...
Rodrigo B Laurindo Posted April 8, 2019 Share Posted April 8, 2019 Yes, I am afraid It will not be possible. Colors can only be used in attributes as a native option. Maybe you could find some custom module for what you want. Link to comment Share on other sites More sharing options...
kamjosi Posted March 27, 2020 Share Posted March 27, 2020 Hello I have the same problem. It would be nice to filter colors by feature but I like to show those colored circles as well. The problem is that I have different Manufacturers with different color names so lets suggest you will filter attributes and you search for black. You will see "midnight black", "black widow", "tinted black",..... Sometimes one product has two different options of black which makes it even more complicated. Thats simply not an option. Anyone an idea how to handle this? The goal is to filter just one color and get all the shades / variants from all the manufacturers. 1 Link to comment Share on other sites More sharing options...
NPO Posted March 27, 2020 Share Posted March 27, 2020 There are a couple of addon modules that allow you to add colour swatches or add a colour swatch filter and use colours as a feature rather then an attribute. Just make sure you take a very very close look at them to make sure they will do what you want (some may need a little tweaking). Link to comment Share on other sites More sharing options...
HiPresta Modules Posted March 29, 2020 Share Posted March 29, 2020 Here is an instruction on how to add colors for features: Need to modify the file /modules/ps_facetedsearch/src/Filters/Block.php 1) Add the following function at the end of the Block class: public function getFeatureColor($feature_name) { switch (Tools::strtolower($feature_name)) { case 'white': return '#ffffff'; case 'black': return '#000000'; case 'black': return '#0000FF'; case 'red': return '#FF0000'; default: return ''; break; } } Like this: You'll need to add all color names and codes in this function you're going to use. 2) Find the function getFeaturesBlock() and modify the following array: Before: $featureBlock[$idFeature]['values'][$idFeatureValue] = [ 'nbr' => $count, 'name' => $featureValues[$idFeatureValue]['value'], 'url_name' => $urlName, 'meta_title' => $metaTitle ]; After: $featureBlock[$idFeature]['values'][$idFeatureValue] = [ 'nbr' => $count, 'name' => $featureValues[$idFeatureValue]['value'], 'url_name' => $urlName, 'meta_title' => $metaTitle, 'color' => $this->getFeatureColor($featureValues[$idFeatureValue]['value']) ]; Like this: You may need to open the Layered Navigation module configuration page and update the template to clear caches. Link to comment Share on other sites More sharing options...
Amadek Posted October 20, 2023 Share Posted October 20, 2023 HiPresta Modules: your solution do not work in PrestaShop 8.1.1. I was tested it. Have you any solution od module work with Presta 8.1.1 and PHP 8.2? Link to comment Share on other sites More sharing options...
Prestapepe Posted May 18, 2024 Share Posted May 18, 2024 BUt then... whith this solution... how we assign colour caracteristics to each combination? Link to comment Share on other sites More sharing options...
internetprofi Posted June 6, 2024 Share Posted June 6, 2024 On 10/20/2023 at 1:00 PM, Amadek said: HiPresta Modules: your solution do not work in PrestaShop 8.1.1. I was tested it. Have you any solution od module work with Presta 8.1.1 and PHP 8.2? Problem is in this line "switch (Tools::strtolower($feature_name))" The function "Tools::strtolower" is not functional in this section Correct entry "switch ($feature_name)" public function getFeatureColor($feature_name) { switch ($feature_name) { case 'white': return '#ffffff'; case 'black': return '#000000'; case 'black': return '#0000FF'; case 'red': return '#FF0000'; default: return ''; break; } } In this case, the colors must be entered exactly as they are entered in PrestaShop public function getFeatureColor($feature_name) { switch ($feature_name) { case 'White': return '#ffffff'; case 'Black': return '#000000'; case 'Black': return '#0000FF'; case 'Red': return '#FF0000'; default: return ''; break; } } 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