I am using Drupal 7 with Drupal Commerce (not kickstart). My products are boxes setup in Series varying by height.

Series 500 has 3 boxes
box 1 has dimensions of 120x20x10
box 2 has 120x20x20
box 3 has 120x20x30

Everything else about the boxes are the same, so "height" is my product attribute. Drupal Commerce attributes by default need to be an options_select field, but I have over 1000 products of varying heights and I really didn't want to have to build and maintain a gigantic array of heights down to a thousandth of a inch (whether in the gui or in code).

My original thoughts were to build a module that has a sql table to store product heights. Then add two fields to the product, a decimal and an options field and hide the options field. When the user enters a decimal in the height field on the product page, on save the module will check to see if the value exists and if not insert the value into the sql table. The options field will be setup to use an allowed values function to query the sql table to build the "heights" array so again on save after the module stores the decimal in the sql table, it will then set the value in the options field keeping the two in sync.

This would allow me to have an options field I don't have to maintain, but seemed a little hacky so wondered if there was anyone else out there that found better way (as I have googled and had no luck).


1 Answer 1


For the answer, I actually found a possible dup of my questions here:

support integer or float values as an attribute

but it was never answered, which is why I left mine up. However, the question had a little more research into my problem and was able to give me insight that any field that implements hook_options_list and has an entity "property_type" defined in its hook_field_info then it can be used as an attribute.

From here I created a module that installs a new widget for the "list" modules that allows textfield input and adds the sanitized value of the textfield to the "allowed_values" on POST so that it passes validation. From the viewmode standpoint it works like a normal list and you can use the select widget on the commerce product attribute settings to use this as an attribute.

I know the security ramifications of this could be dicey, however I am sanitizing the field input and I have only myself actually contributing content so I feel this solution works for me.

  • 1
    nice, could you post a bit of code of how you implements hook_options_list and has an entity "property_type" defined in its hook_field_info and following ? Nt very clear for me, and I'm in emergency mode to find a solution ! Thank you
    – Kojo
    Commented Oct 15, 2015 at 14:16

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.