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);
 }
예제 #2
0
 function it_filters_items_which_has_product_with_price_equal_to_configured_minimum_criteria(ChannelInterface $channel, OrderItemInterface $item1, OrderItemInterface $item2, ProductVariantInterface $item1Variant, ProductVariantInterface $item2Variant, ProductVariantPriceCalculatorInterface $productVariantPriceCalculator)
 {
     $item1->getVariant()->willReturn($item1Variant);
     $item2->getVariant()->willReturn($item2Variant);
     $productVariantPriceCalculator->calculate($item1Variant, ['channel' => $channel])->willReturn(500);
     $productVariantPriceCalculator->calculate($item2Variant, ['channel' => $channel])->willReturn(1000);
     $this->filter([$item1, $item2], ['filters' => ['price_range_filter' => ['min' => 1000]], 'channel' => $channel])->shouldReturn([$item2]);
 }
예제 #3
0
 function it_filters_items_which_has_product_with_price_equal_to_configured_minimum_criteria(OrderItemInterface $item1, OrderItemInterface $item2, ProductVariantInterface $item1Variant, ProductVariantInterface $item2Variant)
 {
     $item1->getVariant()->willReturn($item1Variant);
     $item2->getVariant()->willReturn($item2Variant);
     $item1Variant->getPrice()->willReturn(500);
     $item2Variant->getPrice()->willReturn(1000);
     $this->filter([$item1, $item2], ['filters' => ['price_range' => ['min' => 1000]]])->shouldReturn([$item2]);
 }
 function it_throws_exception_when_recalculated_on_hand_quantity_is_lower_than_zero(OrderInterface $order, OrderItemInterface $orderItem, ProductVariantInterface $productVariant)
 {
     $order->getItems()->willReturn([$orderItem]);
     $orderItem->getQuantity()->willReturn(5);
     $orderItem->getVariant()->willReturn($productVariant);
     $productVariant->isTracked()->willReturn(true);
     $productVariant->getOnHand()->willReturn(4);
     $productVariant->getName()->willReturn('Variant');
     $this->shouldThrow(\InvalidArgumentException::class)->during('decrease', [$order]);
 }
 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->process($order);
 }
예제 #6
0
 function it_holds_the_variant_stock_via_inventory_operator($inventoryOperator, $stateMachineFactory, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, StateMachineInterface $sm1, StateMachineInterface $sm2)
 {
     $order->getItems()->willReturn([$item]);
     $item->getVariant()->willReturn($variant);
     $item->getQuantity()->willReturn(2);
     $item->getUnits()->willReturn(new ArrayCollection([$unit1, $unit2]));
     $stateMachineFactory->get($unit1, InventoryUnitTransitions::GRAPH)->willReturn($sm1);
     $sm1->can(InventoryUnitTransitions::SYLIUS_HOLD)->willReturn(false);
     $sm1->apply(InventoryUnitTransitions::SYLIUS_HOLD)->shouldNotBeCalled();
     $stateMachineFactory->get($unit2, InventoryUnitTransitions::GRAPH)->willReturn($sm2);
     $sm1->can(InventoryUnitTransitions::SYLIUS_HOLD)->willReturn(true);
     $sm1->apply(InventoryUnitTransitions::SYLIUS_HOLD)->shouldBeCalled();
     $inventoryOperator->hold($variant, 1)->shouldBeCalled();
     $this->holdInventory($order);
 }
예제 #7
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);
 }
예제 #8
0
 function it_recalculates_prices_adding_all_context(GenericEvent $event, OrderInterface $order, OrderItemInterface $item, DelegatingCalculatorInterface $priceCalculator, GroupableInterface $customer, ArrayCollection $groups, ChannelInterface $channel, PriceableInterface $variant)
 {
     $event->getSubject()->shouldBeCalled()->willReturn($order);
     $order->getCustomer()->shouldBeCalled()->willReturn($customer);
     $order->getChannel()->shouldBeCalled()->willReturn($channel);
     $order->getItems()->shouldBeCalled()->willReturn(array($item));
     $order->calculateTotal()->shouldBeCalled();
     $customer->getGroups()->shouldBeCalled()->willReturn($groups);
     $groups->toArray()->shouldBeCalled()->willReturn(array('group1', 'group2'));
     $item->isImmutable()->shouldBeCalled()->willReturn(false);
     $item->getQuantity()->shouldBeCalled()->willReturn(5);
     $item->setUnitPrice(10)->shouldBeCalled();
     $item->getVariant()->shouldBeCalled()->willReturn($variant);
     $priceCalculator->calculate($variant, array('customer' => $customer, 'groups' => array('group1', 'group2'), 'channel' => array($channel), 'quantity' => 5))->shouldBeCalled()->willReturn(10);
     $this->recalculatePrices($event);
 }
예제 #9
0
 function it_decreases_the_variant_stock_via_inventory_operator($inventoryOperator, $stateMachineFactory, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, StateMachineInterface $sm1, StateMachineInterface $sm2)
 {
     $order->getItems()->willReturn([$item]);
     $item->getVariant()->willReturn($variant);
     $item->getQuantity()->willReturn(2);
     $item->getUnits()->shouldBeCalled()->willReturn([$unit1, $unit2]);
     $stateMachineFactory->get($unit1, InventoryUnitTransitions::GRAPH)->willReturn($sm1);
     $sm1->can(InventoryUnitTransitions::SYLIUS_SELL)->willReturn(true);
     $sm1->can(InventoryUnitTransitions::SYLIUS_RELEASE)->willReturn(true);
     $sm1->apply(InventoryUnitTransitions::SYLIUS_SELL)->shouldBeCalled();
     $stateMachineFactory->get($unit2, InventoryUnitTransitions::GRAPH)->willReturn($sm2);
     $sm2->can(InventoryUnitTransitions::SYLIUS_SELL)->willReturn(true);
     $sm2->can(InventoryUnitTransitions::SYLIUS_RELEASE)->willReturn(false);
     $sm2->apply(InventoryUnitTransitions::SYLIUS_SELL)->shouldBeCalled();
     $inventoryOperator->decrease([$unit1, $unit2])->shouldBeCalled();
     $inventoryOperator->release($variant, 1)->shouldBeCalled();
     $this->updateInventory($order);
 }
예제 #10
0
 protected function createInventoryUnits(OrderItemInterface $item, $quantity, $state = InventoryUnitInterface::STATE_CHECKOUT)
 {
     $units = $this->inventoryUnitFactory->create($item->getVariant(), $quantity, $state);
     foreach ($units as $unit) {
         $item->addInventoryUnit($unit);
     }
 }
 function it_does_nothing_if_variant_is_not_tracked_during_selling(OrderInterface $order, OrderItemInterface $orderItem, ProductVariantInterface $variant)
 {
     $order->getItems()->willReturn([$orderItem]);
     $orderItem->getVariant()->willReturn($variant);
     $variant->isTracked()->willReturn(false);
     $variant->setOnHold(Argument::any())->shouldNotBeCalled();
     $variant->setOnHand(Argument::any())->shouldNotBeCalled();
     $this->sell($order);
 }
예제 #12
0
 function its_shippable_is_an_order_item_variant(OrderItemInterface $orderItem, ProductVariantInterface $variant)
 {
     $orderItem->getVariant()->willReturn($variant);
     $this->getShippable()->shouldReturn($variant);
 }
 function it_does_not_apply_taxes_with_amount_0(CalculatorInterface $calculator, AdjustmentFactoryInterface $adjustmentsFactory, TaxRateResolverInterface $taxRateResolver, Collection $items, Collection $units, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, ProductVariantInterface $productVariant, TaxRateInterface $taxRate, ZoneInterface $zone)
 {
     $order->getItems()->willReturn($items);
     $items->count()->willReturn(2);
     $items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()]));
     $orderItem->getQuantity()->willReturn(2);
     $orderItem->getVariant()->willReturn($productVariant);
     $taxRateResolver->resolve($productVariant, ['zone' => $zone])->willReturn($taxRate);
     $orderItem->getUnits()->willReturn($units);
     $units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()]));
     $unit1->getTotal()->willReturn(1000);
     $calculator->calculate(1000, $taxRate)->willReturn(0);
     $unit2->getTotal()->willReturn(900);
     $calculator->calculate(900, $taxRate)->willReturn(0);
     $adjustmentsFactory->createWithData(AdjustmentInterface::TAX_ADJUSTMENT, Argument::cetera())->shouldNotBeCalled();
     $unit1->addAdjustment(Argument::any())->shouldNotBeCalled();
     $unit2->addAdjustment(Argument::any())->shouldNotBeCalled();
     $this->apply($order, $zone);
 }
 function it_does_not_apply_taxes_with_amount_0($adjustmentsFactory, $calculator, $distributor, $taxRateResolver, Collection $items, Collection $units, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, ProductVariantInterface $productVariant, TaxRateInterface $taxRate, ZoneInterface $zone)
 {
     $order->getItems()->willReturn($items);
     $items->count()->willReturn(1);
     $items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()]));
     $orderItem->getQuantity()->willReturn(2);
     $orderItem->getVariant()->willReturn($productVariant);
     $taxRateResolver->resolve($productVariant, ['zone' => $zone])->willReturn($taxRate);
     $orderItem->getTotal()->willReturn(1000);
     $calculator->calculate(1000, $taxRate)->willReturn(0);
     $taxRate->getLabel()->willReturn('Simple tax (0%)');
     $taxRate->isIncludedInPrice()->willReturn(false);
     $orderItem->getUnits()->willReturn($units);
     $units->getIterator()->willReturn(new \ArrayIterator([$unit1->getWrappedObject(), $unit2->getWrappedObject()]));
     $distributor->distribute(0, 2)->willReturn([0, 0]);
     $adjustmentsFactory->createWithData(AdjustmentInterface::TAX_ADJUSTMENT, 'Simple tax (0%)', 0, false)->shouldNotBeCalled();
     $this->apply($order, $zone);
 }
 function it_throws_invalid_argument_exception_if_on_hold_quantity_to_decrease_will_be_below_zero(OrderInterface $order, OrderItemInterface $orderItem, ProductVariantInterface $productVariant)
 {
     $productVariant->getOnHold()->willReturn(5);
     $productVariant->isTracked()->willReturn(true);
     $productVariant->getName()->willReturn('t-shirt');
     $orderItem->getVariant()->willReturn($productVariant);
     $orderItem->getQuantity()->willReturn(10);
     $order->getItems()->willReturn([$orderItem]);
     $productVariant->setOnHold(-5)->shouldNotBeCalled();
     $this->shouldThrow(\InvalidArgumentException::class)->during('decrease', [$order]);
 }