Jump to content
esterflore1@yhoo.it

Prestashop 1.7.5.1 Feature for Colors

Recommended Posts

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

Share this post


Link to post
Share on other sites

Hello @esterflore1@yhoo.it

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? 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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:

 1.png.66e973fda581d75d71873ce2a0ee5241.png

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:

2.thumb.png.787319c1142c6a4e8cc4c03915697f42.png

You may need to open the Layered Navigation module configuration page and update the template to clear caches.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More