Once a Product type is created, I cannot change Variation type in Product type. Is this a feature?

This is useful because I want to use entity_clone and create multiple similar Product types and change the variation type after the clone.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

petergus created an issue. See original summary.

bojanz’s picture

Title: Cannot change Variation type in Product type » Loosen the variation type disabling on the product type form
Category: Bug report » Task

It is a feature, because changing this after creating products would cause breakage.
However, the check is too strict. We can allow changing the variation type as long as you don't have any product entities created.
That would satisfy the clone use case.

petergus’s picture

ok, thanks for clarifying. Rather than waiting for patch or try to code under time pressure, as a workaround I have been using Field tools to clone all fields and displays over.

Could you tell me where I would have to change the referenced variation in the database?

bojanz’s picture

This is config, it's all serialized, there's no db column to change.

petergus’s picture

Ah that's why I couldn't find it :D Guess I will continue with my field-tools in the meantime since I wouldn't know where to start with contributing a patch.

czigor’s picture

Status: Active » Needs review
FileSize
3.32 KB
petergus’s picture

Works great!

bojanz’s picture

Status: Needs review » Needs work

The fix looks good. Tests need a bit of cleanup:

+    $this->assertFalse($this->getSession()->getPage()->findField('variationType')->hasAttribute('disabled'));

This line is too long and hard to read. Let's assign $variation_type_field on the line above, then use that in the assert:

  $variation_type_field = $this->getSession()->getPage()->findField('variationType');
  $this->assertFalse($variation_type_field->hasAttribute('disabled'));
+    // Cannot change the variation of a product type once a product has been
+    // created.
+    $values = [
+      'type' => 'default',
+      'title' => 'Test product',
+      'sku' => 'testsku',
+    ];
+    \Drupal::entityTypeManager()->getStorage('commerce_product')->create($values)->save();

Should use $this->createEntity() for consistency.

bojanz’s picture

Status: Needs work » Needs review
FileSize
3.53 KB

EDIT:

+    $product = $this->createEntity('commerce_product', [
+      'type' => 'default',
+      'title' => 'Test product',
+      'sku' => 'testsku',
+    ]);

Missed the SKU field, no such thing on a product. Can be fixed on commit.

  • bojanz committed 391365b on 8.x-2.x authored by czigor
    Issue #3014686 by bojanz, czigor: Loosen the variation type disabling on...
bojanz’s picture

Status: Needs review » Fixed

Done. Thanks, Andras!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.