Rework product variation title handling

Created on 25 September 2019, almost 5 years ago
Updated 18 July 2024, about 2 months ago

Let's assume a product with multiple variations, "Drupal Commerce Hoodie".
There are two different titles that each of its variation can have:
- The short title: "Small, blue"
- The full title: "Drupal Commerce Hoodie - Small, blue"
When the variation is shown in the context of a product (variation listing in the admin UI, add to cart form on the frontend), it makes sense to use the short title. When the variation is shown outside the context of a product (autocomplete, shopping cart, invoice), it makes sense to use the full title.

Right now we assume that the $variation->title stores the full title, and use that as the label. This was primarily done to make autocomplete easier. We don't even have a getter for the short title, it is constructed on the fly in ProductVariationListBuilder and ProductVariationInlineForm.
We also have $variation->getOrderItemTitle(), which returns the same label.

Note: If a product always has a single variation, we can assume that both the short and the full title are equal to the product title, since the variation title isn't useful (there is no variation listing, no need to select variations on the add to cart form).

Problems

1) There is no getter for the short title, leading to duplicated logic between ProductVariationListBuilder, ProductVariationInlineForm, etc.

2) The ProductVariationTitleWidget uses the full title instead of the short title by default, and provides no configurability.
This surprises users from time to time: #2988677: Delete the product title in the variations .

Ideally we'd use the short title by default and offer the full title as a configuration option (to maintain BC primarily, since some users obviously don't mind).

3) Neither the short nor the full title are customizable.
Users might wish to exclude a certain attribute from the short title, or change the attribute separator (e.g. "/" instead of ",").
Users might also wish to change the format of the full title (separator after the product title, etc).

4) The full title can become outdated
We need to regenerate all variation titles when a product title (or its translation) changes. We currently don't do that.
🐛 Auto generated product variation title does not change when product title changes Needs review .

5) Users who turn off title generation sometimes expect the title to be the short title, instead of the full title
See #2923799: Allow product variations to be named after the product name and variation title. .

Competition

Shopify considers the variant title to be the short title: https://help.shopify.com/en/themes/liquid/objects/variant#variant-title
The full title is constructed for the line item: https://help.shopify.com/en/themes/liquid/objects/line_item#line_item-title

BigCommerce uses the short title in the admin UI: https://support.bigcommerce.com/s/article/Adding-Products-Beta#variations
Variations/variants don't seem to have any title actually stored, according to the REST API docs.

Proposed changes

1) Follow Shopify's lead and make the $variation->title represent the short title.
Fix ProductVariationListBuilder and ProductVariationInlineForm to use the ->label() getter.
This automatically fixes ProductVariationTitleWidget as well.

2) Introduce a getter for the full title.
How do we call it? Full title? Long title? Something else?

We make $variation->getOrderItemTitle() proxy to it.
The full title is always generated on the fly. This allows us to bypass the translation problem.
We can even make it a computed property on the entity.

We default the pattern to "$product_title - $variation_title".
This covers products with multiple variations, and products with a single variation that do not generate a title.
If the product has a single variation and the title is generated, we should only do $product_title.
We worry about tokens later (since we have IF/ELSE logic here).

3) Add an option to ProductVariationTitleWidget to use the full title instead.

4) Write a custom autocomplete handler for product variations (we need this anyway cause of #3083123: Product variation autocomplete should allow matching by SKU )
The handler would either search by SKU only, or by SKU and product title. It would show the a custom label ("SKU: Full title")

5) Write a custom product variation selection widget which allows selecting first the product, then the variation (if multiple)
This is long overdue.

6) Allow the title to be generated via Token (pattern on the product variation type).
Default pattern for products with multiple variations:
Title: "[commerce_product_variation:attributes]"
[commerce_product_variation:attributes] prints a comma-separated list of attribute display names, same as today.

Default patterns for products with a single variation:
Title: "[commerce_product:title]"
(Does this make sense, or should we hide the pattern and have all variations have a title like "Default"? That's what Shopify does)

(7) Show the product title on product variation creation / edit / delete form, so that, when working with product variations, you always know the product context. Maybe even linked to the product? (from #18)

(8) Eventually expose the product variation title as field [META] Expose Title and other base fields in Manage Display Active which would allow to provide field formatters for the different title displays. That would bring us UI by design, consistent UX and extendability by field formatters. (from #18)

📌 Task
Status

Active

Version

3.0

Component

User experience

Created by

🇷🇸Serbia bojanz

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy FiNeX

    I've the following use case: a bookstore where every product (book) has two variations: the physical paper book and the digital ePub version.
    The product title is the book title, to keep the variation select field compact, the variation titles are: "paper book" and "digital download".

    When the user add the product to the cart, the variation title is shown, this is not a problem during the checkout because I'm able to change the views in order to also display the product title.

    What I'm trying to solve now is to do the same on the order details page (both backend and frontend) and in the receipt email.

    The problem could be easily solved updating the commerce_order_item table with a concatenation of the product and the variation title.

    Now I can join the order item data with the product, but if the product title is changed or the product is deleted, I loose the information.

    How should I resolve this issue?

  • 🇩🇪Germany Anybody Porta Westfalica

    Yeah we just ran into EXACTLY the same discussion, so we can confirm this is Major ;)
    We'll discuss this internally and try to contribute...

    What dies the Centarro team think about this?

  • 🇩🇪Germany Anybody Porta Westfalica

    Okay I read through the points in the issue summary now and also the comments. Some comments seem to address related, but different problems, as it seems to me. I really like the plan from the issue summary, but would suggest to eventually split some of them into separate issues, especially (5) and (6) from "proposed changes"?

    Maybe it would make sense to create a META issue or make this one a meta issue? (I think better a new one with less noise)

    Regarding Do not require a 'title' field Needs work I don't really like the idea to not have labels per product variation and I'd say that's a related topic, but an edge-case, while having a better visible bottom-up relation from product variation title to product title is a logical important thing.

    What I'd also like a lot would be to simply have field formatters for the title, so you could simply select:

    • "Short title"
    • "Full title"
    • "Product title"
    • "Token"
    • ...=

    and easily extend this by custom field formatters!
    But that might depend on [META] Expose Title and other base fields in Manage Display Active .

    So how should we proceed? Any chance to first get some Centarro feedback here to push this into the direction they like?

  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇩🇪Germany Anybody Porta Westfalica
  • 🇮🇱Israel jsacksick

    So how should we proceed? Any chance to first get some Centarro feedback here to push this into the direction they like

    Honestly, this wasn't really on my radar, this issue was initially opened 5 years ago and afaik, this never was a major concern on any of the projects I've been working on.

    I had that one on my radar instead 🐛 Auto generated product variation title does not change when product title changes Needs review .
    This late in the project lifecycle, this should target 3.x.

  • 🇮🇱Israel jsacksick

    @Anybody: Could you elaborate on the pain points you're currently experiencing? Are there no way to work around those?

  • 🇩🇪Germany Anybody Porta Westfalica

    @jsacksick thanks! The issue summary already points out the things we experienced very well.

    The final thing that lead me here, is the slight visibility of the parent product in the product variation CRUD forms. (e.g. /product/43/variations/9/edit)
    Product variations have a very strong relation to their parent products (can not exist without), but working on such a form you feel to be "somewhere".

    The same happens to us in other places where product variations are shown, especially in the admin backend. As a workaround you can prefix all product variations with the product name, but that leads to other issues.

    So all in all we came to the same conclusions suggested in the issue summary to be able to bring the product variations closer to their parent product con(textually) all over the projects.

    And yes of course there are workarounds, but it seems to us that this is a conceptual thing that should be improved in general and we're willing to help, as it would help us and our clients.

  • 🇮🇱Israel jsacksick

    My concern is that, I certainly wouldn't expect changes (as a merchant) around how the title is handled for variations if I'm already running a live cycle, which is why I feel it is too late to change anything in Commerce 2 at this point.

    Regarding:

    The final thing that lead me here, is the slight visibility of the parent product in the product variation CRUD forms. (e.g. /product/43/variations/9/edit)

    This is relatively easy to fix, by altering the route and specifying a different title callback. I'm guessing for some merchants, it might actually make sense to output the SKU in there too?

    Also, the product title is visible in the breadcrumb.
    Additionally, for a variation type that opts in to automatically generate variation titles, without actual attributes, the parent product title is going to be used.

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks @jsacksick yes it should definitely be backwards-compatible.

    This is relatively easy to fix, by altering the route and specifying a different title callback. I'm guessing for some merchants, it might actually make sense to output the SKU in there too?

    Would you accept this in Commerce Core or does it have to be solved in contrib?

    For the other points, can you tell which of the proposed changes from the IS you would accept for Commerce 2 and which could be considered for Commerce 3 future?

    We'd then create a META issue, split the proposed points into subissues and start working on them where it makes sense based on your decision.

    In general my late hope is that one day you'll perhaps see the points yourself, at least partially, so we can revive it ;) I don't think I'll be able to convince you that most of this makes a lot of sense, if you don't run into this yourself :P
    And yes, Commerce 3 would be fine for the large parts, as I think this is a conceptual thing. And of course especially for breaking changes!

  • 🇮🇱Israel jsacksick

    Just to clarify, I don't disagree that there are things that can and should be improved. But changing this now will lead to other issues and other people complaining that it doesn't work like the way it used to be, that's all I'm saying...

    It's hard to find the right behavior that'd satisfy everyone here... Depending on the business and what's being sold (digital vs physical etc)...

  • 🇩🇪Germany Anybody Porta Westfalica

    Thanks, yes totally with you! :)
    We just need a direction to go, so we don't waste valuable time. So let's wait for your and your teams feedback! Thanks!!

Production build 0.71.5 2024