Move Order Item Product variation widgets selection (attributes vs. title) into Product Add to cart form formatter

Created on 20 August 2024, 5 months ago

Problem/Motivation

TL;DR:

Having product with variations that should show the Product variation title select and others that should show the Product variation attributes selects, you're forced to create dedicated order item types just to be able to configure that.

That shouldn't be the purpose of order item types and makes things over-complicated. What you want is to be able to select this in the "Variations" field formatter.

Details:

Having a shop with several distinct product (variation) types, of which some are attribute-selection based and others are product-variation title based, the currenct concept of setting the "Add to cart" form field widget in the order item type falls short.

While I'd expect to have this setting in the Product's Manage display (/admin/commerce/config/product-types/default/edit/display) field formatter as separate formatter or setting of the "Add to cart form" Formatter (Drupal\commerce_product\Plugin\Field\FieldFormatter\AddToCartFormatter) you're currently forced to create another order item type just for the sake of being able to switch the field widget in the "Add to cart form" to

  • Product variation title
  • Product variation attributes

This is ugly, because I assume that Order item types were made for different reasons - cases where the order item is indeed something different! Not for just being able to display the product variation title vs. attributes in the add to cart form.

Steps to reproduce

Proposed resolution

Instead of selecting the widget for the "Add to cart form" in the order item type and having to provide two order item types for these two displays

Either
Allow selecting the attributes vs. title display in the Add to cart form formatter as setting

Or
Instead of having just the Add to cart form formatter ("commerce_add_to_cart"), provide two different formatters representing these different displays

... and forward it to the lazy builder:

    $elements[0]['add_to_cart_form'] = [
      '#lazy_builder' => [
        'commerce_product.lazy_builders:addToCartForm', [
          $product->id(),
          $view_mode,
          $this->getSetting('combine'),
          $langcode,
        ],
      ],
      '#create_placeholder' => TRUE,
    ];

from where it should then do, what's currently done by the existing widget.

For BC maybe new formatters / widget could be introduced, while keeping the old functionality for the existing widgets.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Feature request
Status

Active

Version

3.0

Component

Product

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024