106 days to get to Reacticon (Netherlands)

Yireo - Trainings & extensions

Open main menu

Overriding the colors of RalOption

The Magento extensio RalOption offers a way to display a product-option for a RAL colorcode within your Magento frontend. A popup displays all colors, allowing the customer to select the right color for that specific product. But the colors might not be sorted in the way you want. Worse, not all RAL colors can be matched with a webcolor (like gold). This tutorial shows you how to override the default behaviour of RalOption as you see fit.

Sorting by configuring the Magento backend

The RalOption extension delivers by default 2 color-palettes, logically named Palette 1 and Palette 2. Each palette contains a listing of RAL-codes matched with a RGB-color (for example #ffffff for the color white). The Magento backend (System > Configuration > Catalog > RalOption) allows you to select one of the existing palettes (Color Palette) and also configure the sorting of this palette.

The Color Sorting can be set to one of three values: Sorting by Default is using the ordering of RAL-codes as they appear in the palette itself. Sorting by RAL code sorts all codes by their numerical RAL-number. Sorting by RGB color tries to sort the codes by color (trying to detect luminosity which gives varying results).

Setting a palette per product

When the extension is installed, a new product attribute product_palette is added to the Magento database, which produces the same form field as the Color Palette in the System Configuration. This product attribute can be added to specific attribute sets. Products can then be configured in the backend with a specific non-default palette, which is then shown in the Magento frontend to customers.

Overriding existing palettes

The default palettes might not be perfect. The ordering might be lacking, but also, you might want to add or remove RAL codes as you see fit. The RalOption extension uses a PHP class to define a palette. By default, these classes are located in the folder app/code/community/Yireo/RalOption/Palette, but you can add overrides in the folder app/code/local/Yireo/RalOption/Helper. Simply create the folder structure if it does not exist yet. If you want to change one of the existing palettes, just copy the palette file (Palette1.php or Palette2.php) to your local folder and modify the contents there.

Creating new palettes

Instead of overriding the core palettes that RalOption ships with, you can also choose to create a new palette instead. You can for instance copy Palette1.php to Palette344.php and modify the new file as you see fit. When taking this approach, make sure to change the name of the PHP-class inside the PHP file. Files should always be of the format XYZ.php and the PHP file should include a class that resembles the name Yireo_RalOption_Palette_XYZ and implement the interface Yireo_RalOption_Api_PaletteInterface. New palettes will automatically be parsed and become available in the Magento System Configuration as a selectable option.

Additional palettes can also be provided through the observable event raloption_get_palettes which has an argument palettes which is an empty array by default and can be modified to add your own class name. Each array value should be a class name (a string) that should refer to a class definition that implements Yireo_RalOption_Api_PaletteInterface.

Posted on 17 February 2012

Looking for a training in-house?

Let's get to it!

Do not miss out on what we say

This will be the most interesting spam you've ever read

We don't write too commercial stuff, we focus on the technology (which we love) and we regularly come up with innovative solutions. Via our newsletter, you can keep yourself up to date on all of this coolness. Subscribing only takes seconds.

Sign up for the Yireo newsletter


Legal information

Other Yireo sites

Get Social

About Yireo