Vote up!
Vote down!

Dynamic field type for Line Items exposed on 'add to cart form'?

Hi there

Is it possible to have a dynamic field type for a line item which is exposed on the add to cart form? (eg select list where the list of options is dynamically generated by the field type)

Shop sells fabrics, each fabric 'product' has:
- multiple colour codes (the colours vary from 'product' to product)
- multiple sizes (the sizes vary from 'product' to product)
- one image per 'product' (shade card showing all the colours and sizes)
- one price per 'product' (irrespective of size/colour selected)


1) Satin Fabric in 30 colours, and 3 sizes.
2) Cotton Fabric in 60 different colours, and 2 sizes

Functionality required: front end

- Customer clicks on product category or product.
- Selects Colour and Size from select lists.
- Clicks 'add to cart'.
- Customer may then select other colour/size for same fabric (product) and click 'add to cart'.
- Checkout lists each product with separate line items for various colours/sizes selected

Functionality required: back end

Easy method for client to add new 'products' eg:
- click add product
- add one product variation with the following fields:
---- colours available (text area), lists all the colour codes (one per row) to match shade card
---- sizes available (text area), lists all the sizes (one per row)
---- upload image (shade card)
---- set price
- select category
- save

Not feasible to add individual product variations for each option, eg for Satin Fabrics 30 colours x 3 sizes = 90 product variations of size and colour. This is not needed as all satin fabrics have the same price. (large overhead of product variations for clients to add and maintain)

Can setup line item types for 'size' and 'colour', however each 'product' then requires its own line item as the colours and sizes are different from product to product. (difficult for client to maintain)

Can use: https://www.drupal.org/project/commerce_option, however a new 'option set' will need to be created for each 'product' to cater for the different sizes and colours (difficult for client to maintain)

Thought that the field type 'computed' could be used as one of the fields under the line item, this way the field would be dynamic and we could load the colours/sizes as required. However this appears not to be supported: https://www.drupal.org/node/2194343

Potential Solution:

Create a new field type based on a text select list which allows for the loading of dynamic values (eg from a text area in the product node), and then the saving of the selection as a individual line item in the cart.

Any thoughts or comments are appreciated.

Asked by: James Johnston
on November 12, 2014

1 Answer