Commit ed94de74 authored by Jonathan Sacksick's avatar Jonathan Sacksick Committed by Jonathan Sacksick
Browse files

Issue #3270838 by jsacksick, mrweiner: Allow additional variation types to be...

Issue #3270838 by jsacksick, mrweiner: Allow additional variation types to be added to a product type with existing products.
parent 068e135e
Loading
Loading
Loading
Loading
+0 −6
Changes for modules/product/src/Form/ProductTypeForm.php: 0 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -72,12 +72,10 @@ class ProductTypeForm extends CommerceBundleEntityFormBase {
    // @todo Clean up once https://www.drupal.org/node/2318187 is fixed.
    if (in_array($this->operation, ['add', 'duplicate'])) {
      $product = $this->entityTypeManager->getStorage('commerce_product')->create(['type' => $product_type->uuid()]);
      $products_exist = FALSE;
    }
    else {
      $storage = $this->entityTypeManager->getStorage('commerce_product');
      $product = $storage->create(['type' => $product_type->id()]);
      $products_exist = $storage->getQuery()->accessCheck(FALSE)->condition('type', $product_type->id())->execute();
    }
    $form_state->set('original_entity', $this->entity->createDuplicate());

@@ -130,10 +128,6 @@ class ProductTypeForm extends CommerceBundleEntityFormBase {
      ],
      '#required' => !$product_type->isNew(),
    ];
    if ($products_exist) {
      $form['variations']['variationTypes']['#disabled'] = TRUE;
      $form['variations']['variationTypes']['#description'] = $this->t('Products exist for this product type, you can no longer edit this setting.');
    }
    $form['variations']['multipleVariations'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Allow each product to have multiple variations.'),
+0 −12
Changes for modules/product/tests/src/Functional/ProductTypeTest.php: 0 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -143,9 +143,6 @@ class ProductTypeTest extends ProductBrowserTestBase {
   */
  public function testEdit() {
    $this->drupalGet('admin/commerce/config/product-types/default/edit');

    $variation_types_field = $this->getSession()->getPage()->findById('edit-variationtypes-default');
    $this->assertFalse($variation_types_field->hasAttribute('disabled'));
    $edit = [
      'label' => 'Default!',
      'description' => 'New description.',
@@ -178,15 +175,6 @@ class ProductTypeTest extends ProductBrowserTestBase {
    // Confirm that the product display was updated.
    $form_display = commerce_get_entity_display('commerce_product', 'default', 'form');
    $this->assertEmpty($form_display->getComponent('variations'));

    // Cannot change the variation type once a product has been created.
    $product = $this->createEntity('commerce_product', [
      'type' => 'default',
      'title' => 'Test product',
    ]);
    $this->drupalGet('admin/commerce/config/product-types/default/edit');
    $variation_type_field = $this->getSession()->getPage()->findField('edit-variationtypes-default');
    $this->assertTrue($variation_type_field->hasAttribute('disabled'));
  }

  /**