We make heavy use of Ubercart's ability to accept free text as attributes in a product. This is especially useful for sports competition entries, where we collect a fair bit of arbitrary information from our competitors.

I'm not seeing a ready way to do this with Drupal Commerce. It's possible to create some fields for a given content type, and that gets us partway there, but it's rather.... clunky and not something our average users will be able to master.

Is there a clean, simple, way to do this?

For example, on product 1, I'll want first and last names and a phone number. On product 2, I'll want sailboat name and size in addition to that.

Suggestions?

Comments

Cayenne created an issue. See original summary.

bojanz’s picture

Status: Active » Fixed

Same approach on D7 and D8, with plenty of examples online. You add a field to your line item (D7) / order item (D8) and expose it on the add to cart form.

See https://docs.drupalcommerce.org/commerce2/developer-guide/products/displ...

This is controlled per order item type / product variation type. You will need to implement custom hook_form_alter() logic to show/hide fields per-product or per-variation.

Cayenne’s picture

Okay, I can work with that. And I see that I can make the field appear in the checkout form etc by tweaking the underlying view.

So the final question would be how to get that information to appear in the emailed customer receipt? I have found that an email record of the transaction is quite important to the customers.

Would I need to override commerce-order-receipt.html.twig?

bojanz’s picture

Yes! You can also join us in #commerce on Drupal Slack for more real time help.

Cayenne’s picture

Will do.

Meanwhile, here is the code I'm using to override the receipt form. The twig template is in the themes directory of my custom module

/**
 * Implements hook_theme().
 */
function webform_helper_theme() {
  $theme['commerce_order_receipt'] = [
    'template' => 'commerce-order-receipt-alt',
  ];



  return $theme;
}

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.