Ejemplo n.º 1
0
 /**
  * @param Order $order
  * @return Payment
  */
 protected function createPayment(Order $order)
 {
     /** @var $payment Payment */
     $payment = $this->registry->getStorage(Payment::class)->create();
     $payment->setNumber($order->getId()->getValue());
     $payment->setCurrencyCode($this->currency);
     $payment->setTotalAmount($order->getTotal()->getAmount());
     $payment->setClientId($order->getCustomer()->getId()->getValue());
     $payment->setClientEmail($order->getCustomer()->getEmail());
     $payment->setDescription('Payment for order #' . $order->getId()->getValue());
     return $payment;
 }
Ejemplo n.º 2
0
 public function createOrder(CreateOrderCommand $command)
 {
     $cart = $this->cartRepository->getCart();
     if ($cart->getLineItems()->count() === 0) {
         throw new \RuntimeException("The cart is empty");
     }
     $address = $command->getAddress();
     $order = new Order(new UuidIdentity(Uuid::uuid4()), $this->tokenStorage->getToken()->getUser(), new Address($address->getCountry(), $address->getCity(), $address->getStreet(), $address->getZipCode()));
     foreach ($cart->getLineItems() as $lineItem) {
         $order->addProduct($lineItem->getProduct(), $lineItem->getQuantity());
     }
     $this->orderRepository->save($order);
     $event = new OrderCreatedEvent($order, $command->getGatewayName());
     $this->eventBus->handle($event);
 }