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);
 }
 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);
 }
Esempio n. 3
0
 /**
  * @param OrderInterface $order
  *
  * @return FormInterface
  */
 protected function createCheckoutShippingForm(OrderInterface $order)
 {
     $this->zones = $this->getZoneMatcher()->matchAll($order->getShippingAddress());
     if (empty($this->zones)) {
         $this->get('session')->getFlashBag()->add('error', 'sylius.checkout.shipping.error');
     }
     return $this->createForm('sylius_checkout_shipping', $order);
 }
 /**
  * @param CoreOrderInterface $order
  *
  * @return ZoneInterface|null
  */
 private function getTaxZone(CoreOrderInterface $order)
 {
     $shippingAddress = $order->getShippingAddress();
     $zone = null;
     if (null !== $shippingAddress) {
         $zone = $this->zoneMatcher->match($shippingAddress);
     }
     return $zone ?: $this->defaultTaxZoneProvider->getZone($order);
 }
 /**
  * @param OrderInterface $order
  */
 public function saveAddresses(OrderInterface $order)
 {
     /** @var CustomerInterface $customer */
     $customer = $order->getCustomer();
     $shippingAddress = $order->getShippingAddress();
     $billingAddress = $order->getBillingAddress();
     $this->addressAdder->add($customer, clone $billingAddress);
     $this->addressAdder->add($customer, clone $shippingAddress);
 }
 function it_saves_addresses_from_given_order(CustomerAddressAdderInterface $addressAdder, OrderInterface $order, CustomerInterface $customer, AddressInterface $shippingAddress, AddressInterface $billingAddress)
 {
     $order->getCustomer()->willReturn($customer);
     $order->getShippingAddress()->willReturn($shippingAddress);
     $order->getBillingAddress()->willReturn($billingAddress);
     $addressAdder->add($customer, clone $shippingAddress)->shouldBeCalled();
     $addressAdder->add($customer, clone $billingAddress)->shouldBeCalled();
     $this->saveAddresses($order);
 }
Esempio n. 7
0
 /**
  * @param OrderInterface $order
  *
  * @return FormInterface
  */
 protected function createCheckoutShippingForm(OrderInterface $order)
 {
     $this->zones = $this->getZoneMatcher()->matchAll($order->getShippingAddress());
     if (empty($this->zones)) {
         $this->get('session')->getFlashBag()->add('error', 'sylius.checkout.shipping.error');
     }
     return $this->createForm('sylius_checkout_shipping', $order, ['criteria' => ['zone' => !empty($this->zones) ? array_map(function ($zone) {
         return $zone->getId();
     }, $this->zones) : null, 'enabled' => true]]);
 }
Esempio n. 8
0
 function it_doesnt_apply_any_taxes_if_zone_is_missing(OrderInterface $order, Collection $collection, $taxationSettings)
 {
     $collection->isEmpty()->willReturn(false);
     $order->getItems()->willReturn($collection);
     $order->removeTaxAdjustments()->shouldBeCalled();
     $order->getShippingAddress()->willReturn(null);
     $taxationSettings->has('default_tax_zone')->willReturn(false);
     $order->addAdjustment(Argument::any())->shouldNotBeCalled();
     $this->applyTaxes($order);
 }
 /**
  * @When I delete the order :order
  */
 public function iDeleteTheOrder(OrderInterface $order)
 {
     $adjustmentsId = [];
     foreach ($order->getAdjustments() as $adjustment) {
         $adjustmentsId[] = $adjustment->getId();
     }
     $this->sharedStorage->set('deleted_adjustments', $adjustmentsId);
     $this->sharedStorage->set('deleted_addresses', [$order->getShippingAddress()->getId(), $order->getBillingAddress()->getId()]);
     $this->sharedStorage->set('order_id', $order->getId());
     $this->orderRepository->remove($order);
 }
Esempio n. 10
0
 function it_does_not_process_taxes_if_there_is_no_tax_zone(ZoneProviderInterface $defaultTaxZoneProvider, ZoneMatcherInterface $zoneMatcher, PrioritizedServiceRegistryInterface $strategyRegistry, OrderInterface $order, OrderItemInterface $orderItem, AddressInterface $address)
 {
     $order->getItems()->willReturn([$orderItem]);
     $order->isEmpty()->willReturn(false);
     $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
     $orderItem->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
     $order->getShippingAddress()->willReturn($address);
     $zoneMatcher->match($address)->willReturn(null);
     $defaultTaxZoneProvider->getZone($order)->willReturn(null);
     $strategyRegistry->all()->shouldNotBeCalled();
     $this->process($order);
 }
 /**
  * @param OrderInterface $order
  *
  * @return array
  */
 private function getZonesIdsForAddress(OrderInterface $order)
 {
     $matchedZones = $this->zoneMatcher->matchAll($order->getShippingAddress());
     if (empty($matchedZones)) {
         return [];
     }
     $zones = [];
     foreach ($matchedZones as $zone) {
         $zones[] = $zone->getId();
     }
     return $zones;
 }
Esempio n. 12
0
 /**
  * {@inheritdoc}
  */
 public function applyTaxes(OrderInterface $order)
 {
     // Remove all tax adjustments, we recalculate everything from scratch.
     $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT);
     if ($order->getItems()->isEmpty()) {
         return;
     }
     $zone = null;
     if (null !== $order->getShippingAddress()) {
         // Match the tax zone.
         $zone = $this->zoneMatcher->match($order->getShippingAddress());
     }
     if ($this->settings->has('default_tax_zone')) {
         // If address does not match any zone, use the default one.
         $zone = $zone ?: $this->settings->get('default_tax_zone');
     }
     if (null === $zone) {
         return;
     }
     $taxes = $this->processTaxes($order, $zone);
     $this->addAdjustments($taxes, $order);
 }
 function it_does_not_apply_taxes_if_there_is_no_tax_zone($defaultTaxZoneProvider, $zoneMatcher, $orderItemsTaxesApplicator, AddressInterface $address, \Iterator $iterator, Collection $items, OrderInterface $order, OrderItemInterface $orderItem)
 {
     $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
     $order->getItems()->willReturn($items);
     $order->isEmpty()->willReturn(false);
     $items->count()->willReturn(1);
     $items->getIterator()->willReturn($iterator);
     $iterator->rewind()->shouldBeCalled();
     $iterator->valid()->willReturn(true, false)->shouldBeCalled();
     $iterator->current()->willReturn($orderItem);
     $iterator->next()->shouldBeCalled();
     $orderItem->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
     $order->getShippingAddress()->willReturn($address);
     $zoneMatcher->match($address)->willReturn(null);
     $defaultTaxZoneProvider->getZone()->willReturn(null);
     $orderItemsTaxesApplicator->apply(Argument::any())->shouldNotBeCalled();
     $this->apply($order);
 }
Esempio n. 14
0
 private function createCheckoutShippingForm(OrderInterface $order)
 {
     $zones = $this->getZoneMatcher()->matchAll($order->getShippingAddress());
     return $this->createApiForm('sylius_checkout_shipping', $order, array('criteria' => array('zone' => !empty($zones) ? array_map(function ($zone) {
         return $zone->getId();
     }, $zones) : null, 'enabled' => true)));
 }
 function it_does_not_process_taxes_if_there_is_no_tax_zone(ZoneProviderInterface $defaultTaxZoneProvider, ZoneMatcherInterface $zoneMatcher, AddressInterface $address, \Iterator $itemsIterator, Collection $items, OrderInterface $order, OrderItemInterface $orderItem, PrioritizedServiceRegistryInterface $strategyRegistry)
 {
     $order->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
     $order->getItems()->willReturn($items);
     $order->isEmpty()->willReturn(false);
     $items->count()->willReturn(1);
     $items->getIterator()->willReturn($itemsIterator);
     $itemsIterator->rewind()->shouldBeCalled();
     $itemsIterator->valid()->willReturn(true, false)->shouldBeCalled();
     $itemsIterator->current()->willReturn($orderItem);
     $itemsIterator->next()->shouldBeCalled();
     $orderItem->removeAdjustmentsRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->shouldBeCalled();
     $order->getShippingAddress()->willReturn($address);
     $zoneMatcher->match($address)->willReturn(null);
     $defaultTaxZoneProvider->getZone($order)->willReturn(null);
     $strategyRegistry->all()->shouldNotBeCalled();
     $this->process($order);
 }