Пример #1
0
 /**
  * Tests deleting a line item type programmatically and through the form.
  */
 public function testLineItemTypeDeletion()
 {
     $values = ['id' => strtolower($this->randomMachineName(8)), 'label' => $this->randomMachineName(16), 'purchasableEntityType' => 'commerce_product_variation', 'orderType' => 'default'];
     $line_item_type = $this->createEntity('commerce_line_item_type', $values);
     $this->drupalGet('admin/commerce/config/line-item-types/' . $line_item_type->id() . '/delete');
     $this->assertResponse(200, 'line item type delete form can be accessed at admin/commerce/config/line-item-types/' . $line_item_type->id() . '/delete.');
     $this->assertText(t('This action cannot be undone.'), 'The line item type deletion confirmation form is available');
     $this->drupalPostForm(NULL, NULL, t('Delete'));
     $line_item_type_exists = (bool) LineItemType::load($line_item_type->id());
     $this->assertFalse($line_item_type_exists, 'The line item type has been deleted form the database.');
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installConfig('commerce_order');
     $this->installEntitySchema('user');
     $this->installEntitySchema('profile');
     $this->installEntitySchema('commerce_order');
     $this->installEntitySchema('commerce_line_item');
     // A line item type that doesn't need a purchasable entity, for simplicity.
     LineItemType::create(['id' => 'test', 'label' => 'Test', 'orderType' => 'default'])->save();
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions)
 {
     /** @var \Drupal\commerce_order\Entity\LineItemTypeInterface $line_item_type */
     $line_item_type = LineItemType::load($bundle);
     $purchasable_entity_type = $line_item_type->getPurchasableEntityTypeId();
     $fields = [];
     $fields['purchased_entity'] = clone $base_field_definitions['purchased_entity'];
     if ($purchasable_entity_type) {
         $fields['purchased_entity']->setSetting('target_type', $purchasable_entity_type);
     } else {
         // This line item type won't reference a purchasable entity. The field
         // can't be removed here, or converted to a configurable one, so it's
         // hidden instead. See https://www.drupal.org/node/2346347#comment-10254087.
         $fields['purchased_entity']->setRequired(FALSE);
         $fields['purchased_entity']->setDisplayOptions('form', ['type' => 'hidden']);
         $fields['purchased_entity']->setDisplayConfigurable('form', FALSE);
         $fields['purchased_entity']->setDisplayConfigurable('view', FALSE);
         $fields['purchased_entity']->setReadOnly(TRUE);
         // Make the title field visible and required.
         $fields['title'] = clone $base_field_definitions['title'];
         $fields['title']->setRequired(TRUE);
         $fields['title']->setDisplayOptions('form', ['type' => 'string_textfield', 'weight' => -1]);
         $fields['title']->setDisplayConfigurable('form', TRUE);
         $fields['title']->setDisplayConfigurable('view', TRUE);
     }
     return $fields;
 }