1

I am moving my site from Ubercart to Commerce. I currently have some products set up with attributes that can be selected by a customer, please see this URL for an example http://www.wild-sage.co.uk/products/soap-box

How would I go about setting this up using Commerce?

1 Answer 1

0

Instead of dropdowns, you could use checkboxes and line item fields using Commerce custom products module.

All fields are supported as customer-facing line item fields, except some entity reference fields that use views to display their options. Note, the only limitation here would be that your fields would need to be able to react to the specific product.

Customizable products are like content types and define fields per bundle. So you would need a bundle per unique set of requirements. There is no limit, but it would probably be easier to model the "selection criteria" using fields on the products and then create a hook_form_alter() that would change the options available to select.


UPDATE: Code Example

Assumption 1: You've created a custom line item bundle

Assumption 2: You've created two fields. The first for the line item options (this would include all possibilities) and the second would be for the product (this would include any possibilities that match what that kind of product should have, doesn't need to be a complete list, but it would need to be the same ids/values of the first field).

Assumption 3: The workflow would look like this:

select the soaps you would want to show PER product

select the soaps you would want to show PER product

Now, on the product display you would see this:

enter image description here

<?php
function MODULE_form_alter(&$form, &$form_state, $form_id) {
  if (strpos($form_id, 'commerce_cart_add_to_cart_form_') === 0) {
    $product = $form_state['default_product'];
    $show_these = $product->field_include_these_soaps['und'];
    $all_soap_options = $form['line_item_fields']['field_soaps']['und']['#options'];
    $only_show = array();
    foreach ($show_these as $key => $value) {
      $real_key = $value['value'];
      $only_show[$real_key] = $all_soap_options[$real_key];
    }
    $form['line_item_fields']['field_soaps']['und']['#options'] = $only_show;
  }
}
?>
3
  • Thank you I had looked at that module but as yet have not worked out quite how I could use it. Using hook_form_alter is way over my head but I will have a look.
    – julie
    Commented Feb 9, 2016 at 17:02
  • Added code example to help ya out. Admittedly, this is pretty intense, but trying to help you understand the power of such flexibility :)
    – joshmiller
    Commented Feb 9, 2016 at 19:12
  • Note you could even crazier and associate it with taxonomy terms that have price fields that can affect the final price of the product. This has limitations, but here's the video I created walking you through that: youtube.com/watch?v=j9KsyvQZaAY
    – joshmiller
    Commented Feb 9, 2016 at 19:21

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.