Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function holdInventory(OrderInterface $order)
 {
     foreach ($order->getItems() as $item) {
         $quantity = $this->applyTransition($item->getUnits(), InventoryUnitTransitions::SYLIUS_HOLD);
         $this->inventoryOperator->hold($item->getVariant(), $quantity);
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function removeFrom(OrderInterface $order)
 {
     $adjustmentsToRemove = [AdjustmentInterface::ORDER_ITEM_PROMOTION_ADJUSTMENT, AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT, AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT, AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT, AdjustmentInterface::TAX_ADJUSTMENT];
     foreach ($adjustmentsToRemove as $type) {
         $order->removeAdjustmentsRecursively($type);
     }
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function sendOrderComment(OrderInterface $order, CommentInterface $comment = null)
 {
     if (!($user = $order->getUser())) {
         throw new \InvalidArgumentException('Order has to belong to a User.');
     }
     $this->sendEmail(array('order' => $order, 'comment' => $comment), $user->getEmail());
 }
    function it_applies_calculated_shipping_charge_for_each_shipment_associated_with_the_order(
        $adjustmentRepository,
        $calculator,
        AdjustmentInterface $adjustment,
        OrderInterface $order,
        ShipmentInterface $shipment,
        ShippingMethodInterface $shippingMethod
    ) {
        $adjustmentRepository->createNew()->willReturn($adjustment);
        $order->getShipments()->willReturn(array($shipment));

        $calculator->calculate($shipment)->willReturn(450);

        $shipment->getMethod()->willReturn($shippingMethod);
        $shippingMethod->getName()->willReturn('FedEx');

        $adjustment->setAmount(450)->shouldBeCalled();
        $adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled();
        $adjustment->setDescription('FedEx')->shouldBeCalled();

        $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled();
        $order->addAdjustment($adjustment)->shouldBeCalled();

        $order->calculateTotal()->shouldBeCalled();

        $this->applyShippingCharges($order);
    }
 /**
  * {@inheritdoc}
  */
 public function update(OrderInterface $order)
 {
     /** @var CurrencyInterface $currency */
     $currency = $this->currencyRepository->findOneBy(['code' => $this->currencyContext->getCurrencyCode()]);
     $order->setCurrencyCode($currency->getCode());
     $order->setExchangeRate($currency->getExchangeRate());
 }
Exemplo n.º 6
0
 /**
  * Update order's shipping state.
  *
  * @param OrderInterface $order
  * @param string         $transition
  */
 public function updateOrderShipmentStates(OrderInterface $order, $transition = ShipmentTransitions::SYLIUS_PREPARE)
 {
     if ($order->isBackorder()) {
         $transition = ShipmentTransitions::SYLIUS_BACKORDER;
     }
     $this->processor->updateShipmentStates($order->getShipments(), $transition);
 }
 function it_decrements_a_usage_of_promotions_applied_on_order(OrderInterface $order, PromotionInterface $firstPromotion, PromotionInterface $secondPromotion)
 {
     $order->getPromotions()->willReturn([$firstPromotion, $secondPromotion]);
     $firstPromotion->decrementUsed()->shouldBeCalled();
     $secondPromotion->decrementUsed()->shouldBeCalled();
     $this->decrement($order);
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function sendOrderConfirmation(OrderInterface $order)
 {
     if (!($user = $order->getUser())) {
         throw new \InvalidArgumentException('Order has to belong to a User');
     }
     $this->sendEmail(array('order' => $order), $user->getEmail());
 }
 /**
  * {@inheritdoc}
  */
 public function generateForOrderCheckoutState(OrderInterface $order, $parameters = [], $referenceType = self::ABSOLUTE_PATH)
 {
     if (!isset($this->routeCollection[$order->getCheckoutState()]['route'])) {
         throw new RouteNotFoundException();
     }
     return $this->router->generate($this->routeCollection[$order->getCheckoutState()]['route'], $parameters, $referenceType);
 }
Exemplo n.º 10
0
 /**
  * @param OrderInterface   $order
  * @param PaymentSubjectInterface $payment
  */
 private function addAdjustmentIfForNotCancelled(OrderInterface $order, PaymentSubjectInterface $payment)
 {
     if (PaymentInterface::STATE_CANCELLED !== $payment->getState())
     {
         $order->addAdjustment($this->prepareAdjustmentForOrder($payment));
     }
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function supports(OrderInterface $order, ZoneInterface $zone)
 {
     $channel = $order->getChannel();
     /** @var ChannelInterface $channel */
     Assert::isInstanceOf($channel, ChannelInterface::class);
     return $channel->getTaxCalculationStrategy() === $this->type;
 }
 function it_returns_false_if_variant_is_not_included_and_exclude_is_not_set(OrderInterface $subject, OrderItem $orderItem, ProductVariant $variant)
 {
     $subject->getItems()->willReturn([$orderItem]);
     $orderItem->getVariant()->willReturn($variant);
     $variant->getId()->willReturn(2);
     $this->isEligible($subject, ['variant' => 1, 'exclude' => false])->shouldReturn(false);
 }
 function it_decrements_promotion_usage_if_promotion_was_used(OrderInterface $order, PromotionInterface $promotion)
 {
     $order->getPromotions()->willReturn([$promotion]);
     $promotion->getUsed()->willReturn(5);
     $promotion->setUsed(4)->shouldBeCalled();
     $this->decrementPromotionUsage($order);
 }
Exemplo n.º 14
0
 /**
  * @param OrderInterface $order
  */
 private function updateExistingPaymentsStates(OrderInterface $order)
 {
     foreach ($order->getPayments() as $payment) {
         $this->cancelPaymentStateIfNotStarted($payment);
     }
     $this->paymentManager->flush();
 }
 function it_should_recognize_subject_as_eligible_if_country_match(OrderInterface $subject, AddressInterface $address, CountryInterface $country)
 {
     $subject->getShippingAddress()->shouldBeCalled()->willReturn($address);
     $address->getCountry()->shouldBeCalled()->willReturn($country);
     $country->getId()->shouldBeCalled()->willReturn(1);
     $this->isEligible($subject, array('country' => 1))->shouldReturn(true);
 }
Exemplo n.º 16
0
 function it_should_recognize_subject_as_not_eligible_if_nth_order_is_equal_with_configured(OrderInterface $subject, UserInterface $user, \Countable $orders)
 {
     $subject->getUser()->shouldBeCalled()->willReturn($user);
     $user->getOrders()->shouldBeCalled()->willReturn($orders);
     $orders->count()->shouldBeCalled()->willReturn(10);
     $this->isEligible($subject, array('nth' => 10))->shouldReturn(true);
 }
Exemplo n.º 17
0
 /**
  * @Then /^an email with shipment's details of (this order) should be sent to "([^"]+)"$/
  */
 public function anEmailWithShipmentDetailsOfOrderShouldBeSentTo(OrderInterface $order, $recipient)
 {
     $this->assertEmailContainsMessageTo($order->getNumber(), $recipient);
     $this->assertEmailContainsMessageTo($order->getLastShipment()->getMethod()->getName(), $recipient);
     $tracking = $this->sharedStorage->get('tracking_code');
     $this->assertEmailContainsMessageTo($tracking, $recipient);
 }
Exemplo n.º 18
0
 /**
  * {@inheritdoc}
  */
 public function sendOrderConfirmation(OrderInterface $order)
 {
     if (!($email = $order->getEmail())) {
         throw new \InvalidArgumentException('Order must contain customer email');
     }
     $this->sendEmail(array('order' => $order), $email);
 }
 function it_executes_request(InvoiceNumberGeneratorInterface $invoiceNumberGenerator, CurrencyConverterInterface $currencyConverter, Convert $request, PaymentInterface $payment, OrderInterface $order, OrderItemInterface $orderItem, ProductVariantInterface $productVariant, ProductInterface $product)
 {
     $request->getTo()->willReturn('array');
     $payment->getId()->willReturn(19);
     $order->getId()->willReturn(92);
     $order->getId()->willReturn(92);
     $order->getCurrencyCode()->willReturn('PLN');
     $order->getTotal()->willReturn(22000);
     $order->getItems()->willReturn([$orderItem]);
     $order->getAdjustmentsTotalRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->willReturn(0);
     $order->getOrderPromotionTotal()->willReturn(0);
     $order->getShippingTotal()->willReturn(2000);
     $orderItem->getVariant()->willReturn($productVariant);
     $orderItem->getDiscountedUnitPrice()->willReturn(20000);
     $orderItem->getQuantity()->willReturn(1);
     $productVariant->getProduct()->willReturn($product);
     $product->getName()->willReturn('Lamborghini Aventador Model');
     $request->getSource()->willReturn($payment);
     $payment->getOrder()->willReturn($order);
     $invoiceNumberGenerator->generate($order, $payment)->willReturn('19-92');
     $currencyConverter->convertFromBase(22000, 'PLN')->willReturn(88000);
     $currencyConverter->convertFromBase(20000, 'PLN')->willReturn(80000);
     $currencyConverter->convertFromBase(2000, 'PLN')->willReturn(8000);
     $details = ['PAYMENTREQUEST_0_INVNUM' => '19-92', 'PAYMENTREQUEST_0_CURRENCYCODE' => 'PLN', 'PAYMENTREQUEST_0_AMT' => 880.0, 'PAYMENTREQUEST_0_ITEMAMT' => 880.0, 'L_PAYMENTREQUEST_0_NAME0' => 'Lamborghini Aventador Model', 'L_PAYMENTREQUEST_0_AMT0' => 800.0, 'L_PAYMENTREQUEST_0_QTY0' => 1, 'L_PAYMENTREQUEST_0_NAME1' => 'Shipping Total', 'L_PAYMENTREQUEST_0_AMT1' => 80.0, 'L_PAYMENTREQUEST_0_QTY1' => 1];
     $request->setResult($details)->shouldBeCalled();
     $this->execute($request);
 }
Exemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function process(OrderInterface $order)
 {
     if (OrderInterface::STATE_CANCELLED === $order->getState()) {
         return;
     }
     $this->exchangeRateUpdater->update($order);
 }
Exemplo n.º 21
0
 public function incrementCouponUsage(OrderInterface $order)
 {
     $coupon = $order->getPromotionCoupon();
     if (null !== $coupon) {
         $coupon->incrementUsed();
     }
 }
Exemplo n.º 22
0
 /**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException
  */
 public function update(OrderInterface $order)
 {
     $currencyCode = $order->getCurrencyCode();
     /** @var CurrencyInterface $currency */
     $currency = $this->currencyRepository->findOneBy(['code' => $currencyCode]);
     Assert::notNull($currency);
     $order->setExchangeRate($currency->getExchangeRate());
 }
 function it_returns_false_if_variant_is_included_and_count_is_set_bigger_amount_than_quantity(OrderInterface $subject, OrderItem $orderItem, ProductVariant $variant)
 {
     $subject->getItems()->willReturn([$orderItem]);
     $orderItem->getVariant()->willReturn($variant);
     $variant->getId()->willReturn(1);
     $orderItem->getPromotionSubjectCount()->willReturn(1);
     $this->isEligible($subject, ['variant' => 1, 'exclude' => false, 'count' => 2])->shouldReturn(false);
 }
Exemplo n.º 24
0
 function it_processes_payment_for_given_order(PaymentFactoryInterface $paymentFactory, PaymentInterface $payment, OrderInterface $order)
 {
     $order->getTotal()->willReturn(1234);
     $order->getCurrency()->willReturn('EUR');
     $paymentFactory->createWithAmountAndCurrency(1234, 'EUR')->willReturn($payment);
     $order->addPayment($payment)->shouldBeCalled();
     $this->processOrderPayments($order);
 }
Exemplo n.º 25
0
 /**
  * @param OrderInterface $order
  *
  * @return null|PaymentInterface
  */
 private function getLastPayment(OrderInterface $order)
 {
     $lastPayment = $order->getLastPayment(PaymentInterface::STATE_CANCELLED);
     if (null === $lastPayment) {
         $lastPayment = $order->getLastPayment(PaymentInterface::STATE_FAILED);
     }
     return $lastPayment;
 }
 function it_does_nothing_if_order_has_no_shipping_adjustments(Collection $shippingAdjustments, OrderInterface $order, ShipmentInterface $shipment, ZoneInterface $zone)
 {
     $order->getLastShipment()->willReturn($shipment);
     $order->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->willReturn($shippingAdjustments);
     $shippingAdjustments->isEmpty()->willReturn(true);
     $shippingAdjustments->last()->shouldNotBeCalled();
     $this->apply($order, $zone);
 }
Exemplo n.º 27
0
 /**
  * {@inheritdoc}
  */
 public function createPayment(OrderInterface $order)
 {
     $payment = $this->paymentRepository->createNew();
     $payment->setCurrency($order->getCurrency());
     $payment->setAmount($order->getTotal());
     $order->addPayment($payment);
     return $payment;
 }
 function it_should_recognize_subject_as_eligible_if_country_match(OrderInterface $subject, AddressInterface $address, CountryInterface $country, RepositoryInterface $countryRepository)
 {
     $country->getCode()->willReturn('IE');
     $address->getCountryCode()->willReturn('IE');
     $subject->getShippingAddress()->willReturn($address);
     $countryRepository->findOneBy(['code' => 'IE'])->willReturn($country);
     $this->isEligible($subject, ['country' => 'IE'])->shouldReturn(true);
 }
Exemplo n.º 29
0
 function it_sends_order_confirmation_email(OrderInterface $order, UserInterface $user, TwigMailerInterface $mailer)
 {
     $parameters = array('template' => 'test-template.html.twig', 'from_email' => '*****@*****.**');
     $this->beConstructedWith($mailer, $parameters);
     $order->getEmail()->willReturn('*****@*****.**');
     $mailer->sendEmail('test-template.html.twig', array('order' => $order), '*****@*****.**', '*****@*****.**')->shouldBeCalled();
     $this->sendOrderConfirmation($order);
 }
Exemplo n.º 30
0
 function it_does_not_save_addresses_for_guest_order(CustomerAddressAdderInterface $addressAdder, OrderInterface $order, CustomerInterface $customer)
 {
     $order->getCustomer()->willReturn($customer);
     $customer->getUser()->willReturn(null);
     $addressAdder->add($customer, Argument::any())->shouldNotBeCalled();
     $addressAdder->add($customer, Argument::any())->shouldNotBeCalled();
     $this->saveAddresses($order);
 }