/**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->submitCustomerForm($form, $form_state);
     $values = $form_state->getValues();
     $this->order->setEmail($values['mail']);
     $this->order->setOwnerId($values['uid']);
     $this->order->save();
     drupal_set_message($this->t('The order %label has been assigned to customer %customer.', ['%label' => $this->order->label(), '%customer' => $this->order->getOwner()->label()]));
     $form_state->setRedirectUrl($this->order->toUrl('collection'));
 }
 /**
  * Tests ability to expose line item fields on the add to cart form.
  */
 public function testExposedLineItemFields()
 {
     /** @var \Drupal\Core\Entity\Entity\EntityFormDisplay $line_item_form_display */
     $line_item_form_display = EntityFormDisplay::load('commerce_line_item.product_variation.add_to_cart');
     $line_item_form_display->setComponent('quantity', ['type' => 'number']);
     $line_item_form_display->save();
     // Get the existing product page and submit Add to cart form.
     $this->postAddToCart($this->variation->getProduct(), ['quantity[0][value]' => 3]);
     // Check if the quantity was increased for the existing line item.
     $this->cart = Order::load($this->cart->id());
     $line_items = $this->cart->getLineItems();
     /** @var \Drupal\commerce_order\Entity\LineItemInterface $line_item */
     $line_item = $line_items[0];
     $this->assertEqual($line_item->getTitle(), $this->variation->getLineItemTitle());
     $this->assertTrue($line_item->getQuantity() == 3, t('The product @product has been added to cart.', ['@product' => $line_item->getTitle()]));
 }
Exemple #3
0
 /**
  * Gets the workflow for the state field.
  *
  * @param \Drupal\commerce_order\Entity\OrderInterface $order
  *   The order.
  *
  * @return string
  *   The workflow id.
  */
 public static function getWorkflow(OrderInterface $order)
 {
     $workflow = OrderType::load($order->bundle())->getWorkflow();
     return $workflow;
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function removeLineItem(OrderInterface $cart, LineItemInterface $line_item, $save_cart = TRUE)
 {
     $line_item->delete();
     $cart->removeLineItem($line_item);
     $this->eventDispatcher->dispatch(CartEvents::CART_LINE_ITEM_REMOVE, new CartLineItemRemoveEvent($cart, $line_item));
     if ($save_cart) {
         $cart->save();
     }
 }