Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     parent::submitForm($form, $form_state);
     $line_item_type_storage = $this->entityManager->getStorage('commerce_line_item_type');
     /** @var \Drupal\commerce_order\Entity\LineItemInterface $line_item */
     $line_item = $this->entity;
     /** @var \Drupal\commerce\PurchasableEntityInterface $purchased_entity */
     $purchased_entity = $line_item->getPurchasedEntity();
     /** @var \Drupal\commerce_order\Entity\LineItemTypeInterface $line_item_type */
     $line_item_type = $line_item_type_storage->load($line_item->bundle());
     $store = $this->selectStore($purchased_entity);
     $cart = $this->cartProvider->getCart($line_item_type->getOrderTypeId(), $store);
     if (!$cart) {
         $cart = $this->cartProvider->createCart('default', $store);
     }
     $this->cartManager->addLineItem($cart, $line_item, $form_state->get(['settings', 'combine']));
     drupal_set_message(t('@entity added to @cart-link.', ['@entity' => $purchased_entity->label(), '@cart-link' => Link::createFromRoute('your cart', 'commerce_cart.page')->toString()]));
 }