/** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { $status = $this->entity->save(); drupal_set_message($this->t('Saved the %label order type.', ['%label' => $this->entity->label()])); $form_state->setRedirect('entity.commerce_order_type.collection'); if ($status == SAVED_NEW) { commerce_order_add_line_items_field($this->entity); } }
/** * Tests deleting a Order Type programmaticaly and through the form. */ public function testDeleteOrderType() { // Create a order type programmaticaly. $type = $this->createEntity('commerce_order_type', ['id' => 'foo', 'label' => 'Label for foo', 'workflow' => 'order_default']); commerce_order_add_line_items_field($type); // Create a order. $order = $this->createEntity('commerce_order', array('type' => $type->id(), 'mail' => $this->loggedInUser->getEmail())); // Try to delete the order type. $this->drupalGet('admin/commerce/config/order-types/' . $type->id() . '/delete'); $this->assertRaw(t('%type is used by 1 order on your site. You can not remove this order type until you have removed all of the %type orders.', array('%type' => $type->label())), 'The order type will not be deleted until all orders of that type are deleted'); $this->assertNoText(t('This action cannot be undone.'), 'The order type deletion confirmation form is not available'); // Deleting the order type when its not being referenced by a order. $order->delete(); $this->drupalGet('admin/commerce/config/order-types/' . $type->id() . '/delete'); $this->assertRaw(t('Are you sure you want to delete the order type %label?', array('%label' => $type->label()))); $this->assertText(t('This action cannot be undone.'), 'The order type deletion confirmation form is available'); $this->drupalPostForm(NULL, NULL, t('Delete')); $type_exists = (bool) OrderType::load($type->id()); $this->assertFalse($type_exists, 'The order type has been deleted from the database.'); }