Пример #1
0
 function it_recalculates_prices_adding_customer_to_the_context(ChannelInterface $channel, CustomerGroupInterface $group, CustomerInterface $customer, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, ProductVariantPriceCalculatorInterface $productVariantPriceCalculator)
 {
     $order->getCustomer()->willReturn($customer);
     $order->getChannel()->willReturn(null);
     $order->getItems()->willReturn([$item]);
     $order->getCurrencyCode()->willReturn(null);
     $customer->getGroup()->willReturn($group);
     $item->isImmutable()->willReturn(false);
     $item->getQuantity()->willReturn(5);
     $item->getVariant()->willReturn($variant);
     $order->getChannel()->willReturn($channel);
     $productVariantPriceCalculator->calculate($variant, ['channel' => $channel])->willReturn(10);
     $item->setUnitPrice(10)->shouldBeCalled();
     $this->process($order);
 }
 /**
  * {@inheritdoc}
  */
 public function supports(OrderInterface $order, ZoneInterface $zone)
 {
     $channel = $order->getChannel();
     /** @var ChannelInterface $channel */
     Assert::isInstanceOf($channel, ChannelInterface::class);
     return $channel->getTaxCalculationStrategy() === $this->type;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function recalculate(OrderInterface $order)
 {
     $context = [];
     if (null !== ($customer = $order->getCustomer())) {
         $context['customer'] = $customer;
         $context['groups'] = $customer->getGroups()->toArray();
     }
     if (null !== $order->getChannel()) {
         $context['channel'] = [$order->getChannel()];
     }
     foreach ($order->getItems() as $item) {
         if ($item->isImmutable()) {
             continue;
         }
         $context['quantity'] = $item->getQuantity();
         $item->setUnitPrice($this->priceCalculator->calculate($item->getVariant(), $context));
     }
 }
 function it_updates_order_exchange_rate(OrderInterface $order, CurrencyContextInterface $currencyContext, RepositoryInterface $currencyRepository, CurrencyInterface $currency, ChannelInterface $channel)
 {
     $order->getChannel()->willReturn($channel);
     $currencyContext->getCurrencyCode()->willReturn('GBP');
     $currencyRepository->findOneBy(['code' => 'GBP'])->willReturn($currency);
     $currency->getExchangeRate()->willReturn(3.5);
     $currency->getCode()->willReturn('GBP');
     $order->setCurrencyCode('GBP')->shouldBeCalled();
     $order->setExchangeRate(3.5)->shouldBeCalled();
     $this->update($order);
 }
Пример #5
0
 function it_recalculates_prices_without_adding_anything_to_the_context_if_its_not_needed(DelegatingCalculatorInterface $priceCalculator, OrderInterface $order, OrderItemInterface $item, PriceableInterface $variant)
 {
     $order->getCustomer()->willReturn(null);
     $order->getChannel()->willReturn(null);
     $order->getItems()->willReturn([$item]);
     $item->isImmutable()->willReturn(false);
     $item->getQuantity()->willReturn(5);
     $item->getVariant()->willReturn($variant);
     $priceCalculator->calculate($variant, ['quantity' => 5])->willReturn(10);
     $item->setUnitPrice(10)->shouldBeCalled();
     $this->recalculate($order);
 }
Пример #6
0
 function it_cannot_be_supported_when_the_tax_calculation_strategy_from_order_channel_does_not_match_the_strategy_type(ChannelInterface $channel, OrderInterface $order, ZoneInterface $zone)
 {
     $order->getChannel()->willReturn($channel);
     $channel->getTaxCalculationStrategy()->willReturn('order_item_units_based');
     $this->supports($order, $zone)->shouldReturn(false);
 }
 function it_provides_default_tax_zone_from_order_channel(ChannelInterface $channel, OrderInterface $order, ZoneInterface $defaultTaxZone)
 {
     $order->getChannel()->willReturn($channel);
     $channel->getDefaultTaxZone()->willReturn($defaultTaxZone);
     $this->getZone($order)->shouldReturn($defaultTaxZone);
 }
Пример #8
0
 function it_returns_false_if_there_is_no_configuration_for_order_channel(ChannelInterface $channel, OrderInterface $order)
 {
     $order->getChannel()->willReturn($channel);
     $channel->getCode()->willReturn('WEB_US');
     $this->isEligible($order, [])->shouldReturn(false);
 }
Пример #9
0
 /**
  * @param OrderInterface $order
  */
 private function selectPayment(OrderInterface $order)
 {
     $paymentMethod = $this->faker->randomElement($order->getChannel()->getPaymentMethods()->toArray());
     Assert::notNull($paymentMethod);
     foreach ($order->getPayments() as $payment) {
         $payment->setMethod($paymentMethod);
     }
     $this->applyCheckoutStateTransition($order, OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT);
 }
Пример #10
0
 /**
  * @param OrderInterface $order
  */
 private function selectPayment(OrderInterface $order)
 {
     $paymentMethod = $this->faker->randomElement($this->paymentMethodRepository->findEnabledForChannel($order->getChannel()));
     Assert::notNull($paymentMethod, 'Payment method should not be null.');
     foreach ($order->getPayments() as $payment) {
         $payment->setMethod($paymentMethod);
     }
     $this->applyCheckoutStateTransition($order, OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT);
 }
 function it_does_not_apply_discount_if_percentage_configuration_not_defined(ChannelInterface $channel, OrderInterface $order, PromotionInterface $promotion)
 {
     $order->getChannel()->willReturn($channel);
     $channel->getCode()->willReturn('WEB_PL');
     $order->getItems()->shouldNotBeCalled();
     $this->execute($order, ['WEB_PL' => []], $promotion)->shouldReturn(false);
 }
 function it_returns_false_if_taxon_with_configured_code_cannot_be_found(ChannelInterface $channel, OrderInterface $order, TaxonRepositoryInterface $taxonRepository)
 {
     $order->getChannel()->willReturn($channel);
     $channel->getCode()->willReturn('WEB_US');
     $taxonRepository->findOneBy(['code' => 'sniper_rifles'])->willReturn(null);
     $this->isEligible($order, ['WEB_US' => ['taxon' => 'sniper_rifles', 'amount' => 1000]])->shouldReturn(false);
 }
 function it_does_not_apply_discount_if_configuration_is_invalid(ChannelInterface $channel, OrderInterface $order, PromotionInterface $promotion)
 {
     $order->getChannel()->willReturn($channel, $channel);
     $channel->getCode()->willReturn('WEB_US', 'WEB_US');
     $order->countItems()->willReturn(1, 1);
     $this->execute($order, ['WEB_US' => []], $promotion)->shouldReturn(false);
     $this->execute($order, ['WEB_US' => ['amount' => 'string']], $promotion)->shouldReturn(false);
 }
 function it_reverts_a_proper_promotion_adjustment_from_all_units(AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, ChannelInterface $channel, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit, PromotionInterface $promotion)
 {
     $order->getChannel()->willReturn($channel);
     $channel->getCode()->willReturn('WEB_US');
     $order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()]));
     $orderItem->getUnits()->willReturn(new ArrayCollection([$unit->getWrappedObject()]));
     $unit->getAdjustments(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->willReturn(new ArrayCollection([$promotionAdjustment1->getWrappedObject(), $promotionAdjustment2->getWrappedObject()]));
     $promotion->getCode()->willReturn('PROMOTION');
     $promotionAdjustment1->getOriginCode()->willReturn('PROMOTION');
     $unit->removeAdjustment($promotionAdjustment1)->shouldBeCalled();
     $promotionAdjustment2->getOriginCode()->willReturn('OTHER_PROMOTION');
     $unit->removeAdjustment($promotionAdjustment2)->shouldNotBeCalled();
     $this->revert($order, ['WEB_US' => ['amount' => 1000]], $promotion);
 }
 function it_provides_active_promotions_for_given_subject_channel($promotionRepository, ChannelInterface $channel, PromotionInterface $promotion1, PromotionInterface $promotion2, OrderInterface $subject)
 {
     $subject->getChannel()->willReturn($channel);
     $promotionRepository->findActiveByChannel($channel)->willReturn([$promotion1, $promotion2]);
     $this->getPromotions($subject)->shouldReturn([$promotion1, $promotion2]);
 }
 function it_throws_exception_if_order_has_no_channel(OrderInterface $subject)
 {
     $subject->getChannel()->willReturn(null);
     $this->shouldThrow(new \InvalidArgumentException('Order has no channel, but it should.'))->during('getPromotions', [$subject]);
 }
 /**
  * {@inheritdoc}
  */
 public function getZone(OrderInterface $order)
 {
     return $order->getChannel()->getDefaultTaxZone();
 }
Пример #18
0
 /**
  * {@inheritdoc}
  */
 public function supports(OrderInterface $order, ZoneInterface $zone)
 {
     return $order->getChannel()->getTaxCalculationStrategy() === $this->type;
 }