3

How to add a color hex code field to a product attribute using drupal commerce 2

I can add the form field but do not know how to create the field type: color or the corresponding hex code.

Thanks

2
  • 1
    Have you seen this and given it a go? drupalcommerce.org/blog/44310/…
    – Leigh
    Commented Nov 8, 2018 at 12:56
  • Thanks Leigh. That really does help. It was the color_field module I was missing. Cheers Commented Nov 8, 2018 at 13:08

1 Answer 1

3

For anyone else grappling with this issue in future here is what I did:

****How to add a color hex code field to a product attribute using drupal commerce 2****

see also: https://drupalcommerce.org/blog/44310/enabling-fancy-attributes-commerce-2x

Use the Color Field module to add a color field to your Color attribute. https://www.drupal.org/project/color_field

Install with Composer: $ composer require 'drupal/color_field:2.x-dev'

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Product Attributes >> Add Colour Attribute >> Manage Fields

Add:

Label: Color Hex Code

Machine Name: field_color_hex_code

Field type: color

DEFAULT VALUE The default value for this field, used when creating new content.

COLOR HEX CODE

Color #D3D3D3

Opacity 1

Record Opacity Ticked

FIELD SETTINGS TAB

Format storage #123ABC Choose how to store the color.

Allowed number of values: Limited 1

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Product Attributes >> Add Colour Attribute >> Manage form display

FIELD WIDGET

Name Textfield textfield size: 60

Color Hex Code Color default No placeholder

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Product Attributes >> Add Colour Attribute >> Manage display

FIELD LABEL FORMAT

Color Hex Code Hidden Color Swatch Square Width: 40 Height: 40

Note: Remember to change the attribute selection widget to use the rendered option for your attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.