示例#1
0
 /**
  * {@inheritdoc}
  */
 public function setOrder(OrderInterface $order = null)
 {
     $this->order = $order;
     if (null !== $order) {
         $this->state = $order->getState();
     }
 }
 function it_does_not_assign_a_number_to_an_order_with_number(OrderInterface $order, OrderNumberGeneratorInterface $numberGenerator)
 {
     $order->getNumber()->willReturn('00000007');
     $numberGenerator->generate($order)->shouldNotBeCalled();
     $order->setNumber(Argument::any())->shouldNotBeCalled();
     $this->assignNumber($order);
 }
 /**
  * {@inheritdoc}
  */
 public function assignNumber(OrderInterface $order)
 {
     if (null !== $order->getNumber()) {
         return;
     }
     $order->setNumber($this->numberGenerator->generate($order));
 }
 /**
  * @param OrderInterface $order
  * @param string $shipmentState
  *
  * @return int
  */
 private function countOrderShipmentsInState(OrderInterface $order, $shipmentState)
 {
     $shipments = $order->getShipments();
     return $shipments->filter(function (ShipmentInterface $shipment) use($shipmentState) {
         return $shipment->getState() === $shipmentState;
     })->count();
 }
 /**
  * @param OrderInterface $cart
  * @param OrderItemInterface $cartItem
  *
  * @return int
  */
 private function getExistingCartItemQuantityFromCart(OrderInterface $cart, OrderItemInterface $cartItem)
 {
     foreach ($cart->getItems() as $existingCartItem) {
         if ($existingCartItem->equals($cartItem)) {
             return $existingCartItem->getQuantity();
         }
     }
     return 0;
 }
示例#6
0
 /**
  * @param OrderInterface $order
  * @param OrderItemInterface $item
  */
 private function resolveOrderItem(OrderInterface $order, OrderItemInterface $item)
 {
     foreach ($order->getItems() as $existingItem) {
         if ($item->equals($existingItem)) {
             $this->orderItemQuantityModifier->modify($existingItem, $existingItem->getQuantity() + $item->getQuantity());
             return;
         }
     }
     $order->addItem($item);
 }
 function it_performs_action_as_given_admin_user_and_logout(SecurityServiceInterface $adminSecurityService, OrderInterface $order, AdminUserInterface $adminUser)
 {
     $adminSecurityService->getCurrentToken()->willThrow(TokenNotFoundException::class);
     $adminSecurityService->logIn($adminUser)->shouldBeCalled();
     $order->completeCheckout()->shouldBeCalled();
     $adminSecurityService->restoreToken(Argument::any())->shouldNotBeCalled();
     $adminSecurityService->logOut()->shouldBeCalled();
     $wrappedOrder = $order->getWrappedObject();
     $this->performActionAsAdminUser($adminUser, function () use($wrappedOrder) {
         $wrappedOrder->completeCheckout();
     });
 }
示例#8
0
 /**
  * @param BaseOrderInterface $order
  */
 private function createNewPayment(BaseOrderInterface $order)
 {
     /** @var $payment PaymentInterface */
     $payment = $this->paymentFactory->createWithAmountAndCurrencyCode($order->getTotal(), $order->getCurrencyCode());
     $paymentMethod = $this->getDefaultPaymentMethod($payment, $order);
     $lastPayment = $this->getLastPayment($order);
     if (null !== $lastPayment) {
         $paymentMethod = $lastPayment->getMethod();
     }
     if (null === $paymentMethod) {
         return;
     }
     $payment->setMethod($paymentMethod);
     $order->addPayment($payment);
 }
 /**
  * @param OrderInterface $order
  *
  * @return ShipmentInterface
  */
 private function getOrderShipment(OrderInterface $order)
 {
     if ($order->hasShipments()) {
         return $order->getShipments()->first();
     }
     try {
         /** @var ShipmentInterface $shipment */
         $shipment = $this->shipmentFactory->createNew();
         $shipment->setOrder($order);
         $shipment->setMethod($this->defaultShippingMethodResolver->getDefaultShippingMethod($shipment));
         $order->addShipment($shipment);
         return $shipment;
     } catch (UnresolvedDefaultShippingMethodException $exception) {
         return null;
     }
 }
示例#10
0
 /**
  *  Recalculates total after units total or adjustments total change.
  */
 protected function recalculateTotal()
 {
     $this->total = $this->unitsTotal + $this->adjustmentsTotal;
     if ($this->total < 0) {
         $this->total = 0;
     }
     if (null !== $this->order) {
         $this->order->recalculateItemsTotal();
     }
 }
示例#11
0
 /**
  * {@inheritdoc}
  */
 public function removeUnit(OrderItemUnitInterface $unit)
 {
     if ($this->hasUnit($unit)) {
         $this->units->removeElement($unit);
         $this->quantity--;
         $this->unitsTotal -= $unit->getTotal();
         $this->recalculateTotal();
         if (null !== $this->order) {
             $this->order->calculateItemsTotal();
         }
     }
 }
示例#12
0
 /**
  * @param OrderInterface $order
  */
 public function completeCheckout(OrderInterface $order)
 {
     $order->completeCheckout();
 }
示例#13
0
 function it_removes_an_order_item_from_an_order(OrderInterface $order, OrderItemInterface $orderItem, OrderProcessorInterface $orderProcessor)
 {
     $order->removeItem($orderItem)->shouldBeCalled();
     $orderProcessor->process($order)->shouldBeCalled();
     $this->removeFromOrder($order, $orderItem);
 }
 /**
  * @param OrderInterface $order
  * @param string $state
  *
  * @return PaymentInterface[]
  */
 private function getPaymentsWithState(OrderInterface $order, $state)
 {
     return $order->getPayments()->filter(function (PaymentInterface $payment) use($state) {
         return $state === $payment->getState();
     });
 }
 /**
  * {@inheritdoc}
  */
 public function generate(OrderInterface $order, PaymentInterface $payment)
 {
     return $order->getId() . '-' . $payment->getId();
 }
 public function it_generates_invoice_number_based_on(OrderInterface $order, PaymentInterface $payment)
 {
     $order->getId()->willReturn('001');
     $payment->getId()->willReturn('1');
     $this->generate($order, $payment)->shouldReturn('001-1');
 }
示例#17
0
 /**
  * @param OrderInterface $order
  *
  * @return bool
  */
 private function canOrderBeFulfilled(OrderInterface $order)
 {
     return OrderPaymentStates::STATE_PAID === $order->getPaymentState() && OrderShippingStates::STATE_SHIPPED === $order->getShippingState();
 }
 function it_completes_order(OrderInterface $order)
 {
     $order->complete()->shouldBeCalled();
     $this->completeOrder($order);
 }
 /**
  * @param OrderInterface $order
  */
 public function completeOrder(OrderInterface $order)
 {
     $order->complete();
 }
 /**
  * {@inheritdoc}
  */
 public function process(OrderInterface $order)
 {
     foreach (self::$adjustmentsToRemove as $type) {
         $order->removeAdjustmentsRecursively($type);
     }
 }
 /**
  * @param OrderInterface $order
  */
 private function clearTaxes(OrderInterface $order)
 {
     $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);
     foreach ($order->getItems() as $item) {
         $item->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT);
     }
 }
示例#22
0
 function it_does_not_recalculate_adjustments_on_adjustable_entity_when_neutral_set_to_current_value(OrderInterface $order)
 {
     $order->addAdjustment($this->getWrappedObject())->shouldBeCalled();
     $this->setAdjustable($order);
     $order->recalculateAdjustmentsTotal()->shouldNotBeCalled();
     $this->setNeutral(false);
 }
 function it_completes_an_order(OrderInterface $order)
 {
     $order->completeCheckout()->shouldBeCalled();
     $this->completeCheckout($order);
 }
 /**
  * @param OrderInterface $order
  *
  * @return null|PaymentInterface
  */
 private function getLastPayment(OrderInterface $order)
 {
     return $order->getLastPayment(PaymentInterface::STATE_CANCELLED) ?: $order->getLastPayment(PaymentInterface::STATE_FAILED);
 }