Changing 'Generate variation titles based on attribute values' will not change the Title field definition

Created on 28 August 2018, about 6 years ago
Updated 19 February 2024, 9 months ago

After using Drupal Commerce with only the default product and default variation types.

Now I have decided to use multiple variants for products, by using the add-to-cart variant title select list.

So, in the default variant settings, I unchecked the 'Generate variation titles based on attribute values'.

But in the variant edit form, the title textbox is still hidden?

If I created a new product and a new variation type and unchecked the 'Generate variation titles based on attribute values', and create new product, then the title field is shown.

but if I try to create new product of the old product type, the title field will not be shown!

in commerce\modules\product\src\Entity\ProductVariation.php I found this code which seems relevant to the problem, but I couldn't do anything with.

  public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
    /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */
    $fields = [];
    /** @var \Drupal\commerce_product\Entity\ProductVariationTypeInterface $variation_type */
    $variation_type = ProductVariationType::load($bundle);
    // $variation_type could be NULL if the method is invoked during uninstall.
	
    if ($variation_type && $variation_type->shouldGenerateTitle()) {
      // The title is always generated, the field needs to be hidden.
      // The widget is hidden in commerce_product_field_widget_form_alter()
      // since setDisplayOptions() can't affect existing form displays.
      $fields['title'] = clone $base_field_definitions['title'];
      $fields['title']->setRequired(FALSE);
      $fields['title']->setDisplayConfigurable('form', FALSE);
    }

    return $fields;
  }

I guess after title field has been created, the 'Generate variation titles based on attribute values' checkbox will not set the title field to be shown again!?

๐Ÿ› Bug report
Status

Fixed

Version

2.0

Component

Product

Created by

๐Ÿ‡ธ๐Ÿ‡พSyria Wisamx

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.

Production build 0.71.5 2024