Auto generated product variation title does not change when product title changes

Created on 10 December 2017, over 6 years ago
Updated 20 May 2024, about 1 month ago

You have the option to automatically generate the product variation title. This auto generated title is based on the product title & the variations attributes.

It appears that whenever the product title changes, this won't be reflected in the auto generated variation title.

In order to get the variation title to use the new products title, is to save the variation title again.
It is based upon code from Drupal\commerce\Plugin\Commerce\InlineForm\ContentEntity->ensureTranslation().

🐛 Bug report
Status

Needs review

Version

2.0

Component

Product

Created by

🇧🇪Belgium rp7

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.

  • 🇩🇰Denmark NicklasMF

    What is status on this as I see fails on the latest build?

  • Status changed to Needs review 8 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 8 months ago
    773 pass, 3 fail
  • 🇳🇱Netherlands Arantxio Dordrecht

    I've updated some of the tests, this is because the variation has to be reloaded.
    Included the interdiff.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 8 months ago
    771 pass, 6 fail
  • 🇳🇱Netherlands Arantxio Dordrecht

    Some test fail because off the javascript test instability, but I saw one test that i seem to have missed, so here is a updated patch.

  • 🇮🇱Israel jsacksick

    hm... Not really in favor of committing this as this could lead to the variations being saved multiple times and could potentially lead to data loss.

  • 🇬🇧United Kingdom griz

    So that's it? Product variations keep the title they got when the product was first created unless:

    • The site builder installs this patch
    • The site builder installs commerce_bulk and the site admin remembers to use this to re-save the product variations after modifying a product. Give that a 50% chance at best.
    • The site builder creates a VBO view that the site admin remembers to use to re-save the variations

    If this isn't going to make it into commerce, it should be a module. Adding a second submit button for "Save and update variations" would be my preferred method.
    I would like to do this myself but I've already spent too long on the project that most needs this so it won't be any time soon :(

  • 🇮🇱Israel jsacksick

    Well, there are sites that have thousands of variations, so resaving all variations whenever a product is saved is really bad performance wise IMO.

  • 🇧🇪Belgium rp7

    The variations can be re-saved in the background (through a queue). So that removes the performance bottleneck.

  • 🇮🇱Israel jsacksick

    @rp7: Now that I think about it... I'm actually wondering why we aren't generating variation titles / labels on the fly... Afaik, one would always call the label method? Or maybe $variation->getTitle() which actually returns the field value in which case this would be a problem.

    My point is, if we were simply overridding the label() method to add our logic there, we wouldn't need to care about "stale" titles right?

    So the title would always be up to date as we'd prepend the product title from there?

  • 🇧🇪Belgium rp7

    @jsacksick
    Might be a good idea to consider!
    (not entirely sure how that would play with cacheability & invalidation, something to research)

  • 🇬🇧United Kingdom griz

    @jsacksick Generating the variation title seems like the best solution to me.

    It occurs to me that there will almost certainly be sites out there that reference the product variation title in order screens, invoice templates etc. The result is that when a product title changes, they will show that the customer ordered something they did not (or at least, the title was different when they placed the order). I suppose that any rendering of an order or a list of orders should use the order_item label instead, but that doesn't help the site builders who've done it that way and would need to update their templates and views.

    This is the case regardless of whether the variation titles are batch-generated after a product title update, or generated on the fly.
    For that reason I think this should be a contrib module that could make its way into commerce core in the next major version?

Production build 0.69.0 2024