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

Created on 10 December 2017, about 7 years ago
Updated 21 February 2023, almost 2 years 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 work

Version

2.0

Component

Product

Created by

🇧🇪Belgium rp7

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

Merge Requests

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 about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year 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 about 1 year 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?

  • Status changed to RTBC 4 months ago
  • 🇦🇺Australia jannakha Brisbane!

    This is a very important fix!

    I've got lots of products with max 1 variation and updating product title doesn't update product variation title.
    It creates issues with views and messes up all the data.

    If title of the variations is not autogenerated - they are not going to be updated.

    Patch #39 fixes the issue.
    Old way of running tests is no longer supported.

  • First commit to issue fork.
  • 🇪🇸Spain plopesc Valladolid

    Current approach worked for us, but we had some issues with internal tests, so we had to make a few minor adjustments.

    Created MR with our last version.

    Agree that it could cause some performance issues, but for now, it solves the bug while a new approach is defined.

  • Pipeline finished with Failed
    about 1 month ago
    Total: 142s
    #338840
  • 🇩🇪Germany Anybody Porta Westfalica

    Fix should be against 3.0.x please.

Production build 0.71.5 2024