Display selected attribute color name

In this tutorial I will show you how easily you can create feature to show selected color name (on product page that has color attribute). As you already know PrestaShop 1.7 has a feature to create "combinations". Combinations are product variants (product variant is based on product attributes: different sizes of shoes, different colors of t-shirts etc). Each product variant can have own unique values of attributes like size, material, color etc. In this guide we are focused on color attribute - selection of color attribute does not display the color name. This guide shows how to change it and display selected color attribute. Tutorial is based on "classic" template but it is applicable for all themes that are based on "classic" theme structure.

 

color attribute name

 

Modification of theme files

To create this feature we have to modify two classic theme files. custom.js - that contains custom javascripts and custom.css that is used to create custom css styles in template. Let's start with .css styles.

 

Modification of custom.css

File is located in this directory: themes/classic/assets/css/custom.css (if you use different theme than "classic" theme - open your theme directory instead). At the end of this file paste code attached below:

.ColorLabel:after {
    display:inline-block;
    content:attr(data-after);
    margin-left:5px;
    font-weight:bold;
}

 

Modification of custom.js

File is located in this directory: themes/classic/assets/js/custom.js (the same as previously if you use different theme than "classic" - open your theme directory instead). At the end of this file paste code attached below:

$(document).ready(function(){
 $(".input-color").parent().parent().parent().parent().find('.control-label').addClass('ColorLabel');
 $(".input-color:checked").parent().parent().parent().parent().find('.ColorLabel').attr('data-after', 
 $(".input-color:checked").parent().find('.sr-only').html());
 
 prestashop.on("updatedProduct", function (){
  $(".input-color").parent().parent().parent().parent().find('.control-label').addClass('ColorLabel'); 
  $(".input-color:checked").parent().parent().parent().parent().find('.ColorLabel').attr('data-after', 
  $(".input-color:checked").parent().find('.sr-only').html());
 });
});

 

 

Visibility of changes

That's all, after save of the files you should see the changes on product pages. If you do not see any difference it might be required to clear your browser cache because it remembers old .css and .js file contents. Simply saying: if after modification you do not see the difference - clear browser cache or refresh product page with key combination: ctrl+f5 (hard refresh with cache clear).

 

How to define color name?

Each color attribute value in PrestaShop allows to define 3 parameters:

- color 

- texture

- color name

Module to display "name" of the color uses "color name" option available on color value configuration page (see screenshot)

author milos myszczuk
Article by Milosz Myszczuk PrestaShop expert, official PrestaShop community moderator. PHP developer, specialist in relative and spatial databases management, GIS Analyst, CEO & founder of VEKIA interactive agency. Read more about VEKIA company
If you like my articles and want much more valuable tips, feel free to send me donation
1.4 version 1.4.11 1.6 404 addon admin advertise ahref ajax alpha animation api app application authentication back office backup badge banner basics block bootstrap button cache carrier cart catalog category certificate changelog chat class clear client clip cms code colors columns comments configuration contact container content controller cookie counter country coupon css csv currency customer dashboard database debug default delete delivery desktop developer device disable discount displayNav displayTop download dynamic editor effect empty encrypt engine error exchange exclude export facebook faceshop fade fancoupon fancybox fanpage fatal feature feed field file fix fixed font footer free friendly url front ftp full gallery generate gift global godaddy google google+ gray grid groupon header help hide highlight homefeatured homepage hook hosting hover howto htaccess html html5 ID image import include input instagram installation integration iPhone issue javascript jquery kgb knowhow languages law left likebox link list livingsocial loading log login logo loyality mail mailing maintenance manufacturer marketing marquee mcrypt menu meta mobile modification module movie moving multilanguage multiupload must have mysql news newsletter notification number open graph order override page password performance PHP phpmyadmin picture pinterest plugin popup post prestashop prestashop 1.0 prestashop 1.1 prestashop 1.2 prestashop 1.3 prestashop 1.4 prestashop 1.5 price rules problem product profile promotion proslider purifier quantity query quick tip random rates register reinsurance release reporting reset responsive restore results ribbon rich text right sales search security seo service shadow share shipping shop shopmania slider smarty social networks SQL SSL statistics stock store style subcategory superuser support switcher tab tablet tag tax template text theme tinyMCE tips and tricks tpl tracking translations tree trends trigger tumblr tutorial twitter update upgrade upload variables video visits voucher vulnerability web2print wide widget width window wishlist wysiwyg youtube zip zopim