Jump to content

Prestashop 1.7.5.1 Feature for Colors


esterflore1@yhoo.it

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

Link to comment
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

Link to comment
Share on other sites

  • 11 months later...

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.

 

  • Like 1
Link to comment
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).

Link to comment
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.

Link to comment
Share on other sites

  • 3 years later...

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