I wanted to be able to show a select list for product variations that do not have any attributes (my use case: product variations based on administrator configured event dates rather than user-selected attribute values). Attached patch is an adaptation of ProductVariationAttributesWidget.php to show attribute titles instead of attribute fields in product attribute Add to cart forms.

Comments

steveoliver created an issue. See original summary.

mglaman’s picture

+++ b/modules/product/src/Plugin/Field/FieldWidget/ProductVariationTitleWidget.php
@@ -0,0 +1,267 @@
+class ProductVariationTitleWidget extends WidgetBase implements ContainerFactoryPluginInterface {

Should we create a shared base for this and attribute selector? That way the AJAX callback doesn't need to be duplicated.

bojanz’s picture

I like the general idea of adding a widget for this.

@mglaman
Maybe we create an AjaxRefreshTrait and put the method there?

+      '#title' => $this->getSetting('label_display') && $this->getSetting('label_text') ? $this->getSetting('label_text') : NULL,

You would map label_display = FALSE to #title_display => 'invisible'.

+  /**
+   * {@inheritdoc}
+   */
+  public static function defaultSettings() {
+    return [
+      'label_display' => TRUE,
+      'label_text' => 'Variation:',
+    ] + parent::defaultSettings();
+  }

Not sure these defaults make sense. To start with, the label should not have ':'. Maybe we go with label_display => FALSE and "Please select" as the label? Open to ideas

steveoliver’s picture

mglaman, bojanz, all good suggestions. Addressed them in attached patch.

steveoliver’s picture

Status: Needs review » Needs work

Woops, missed "You would map label_display = FALSE to #title_display => 'invisible'." ... coming up.

steveoliver’s picture

steveoliver’s picture

Status: Needs work » Needs review
steveoliver’s picture

Title: Select product variations by title (select list) rather than attribute fields » Add product variation title widget
Component: Product » User experience

  • bojanz committed e3b7061 on 8.x-2.x authored by steveoliver
    Issue #2799589 by steveoliver, bojanz: Add product variation title...
bojanz’s picture

Status: Needs review » Fixed

Converted the trait to a base field after some deliberations. Added missing schema.

Committed, thanks!

Status: Fixed » Closed (fixed)

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