コード例 #1
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));
     }
 }
コード例 #2
0
    function it_applies_payment_charges(
        $adjustmentRepository,
        $delegatingFeeCalculator,
        AdjustmentInterface $adjustment,
        OrderInterface $order,
        PaymentSubjectInterface $payment,
        PaymentMethodInterface $paymentMethod
    ) {
        $order->removeAdjustments('payment')->shouldBeCalled();
        $order->getPayments()->willReturn(array($payment))->shouldBeCalled();

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

        $payment->getState()->willReturn('new')->shouldBeCalled();
        $payment->getMethod()->willReturn($paymentMethod);
        $paymentMethod->getName()->willReturn('testPaymentMethod');

        $delegatingFeeCalculator->calculate($payment)->willReturn(50);

        $adjustmentRepository->createNew()->willReturn($adjustment)->shouldBeCalled();
        $adjustment->setType('payment')->shouldBeCalled();
        $adjustment->setAmount(50)->shouldBeCalled();
        $adjustment->setDescription('testPaymentMethod')->shouldBeCalled();

        $order->addAdjustment($adjustment)->shouldBeCalled();

        $this->applyPaymentCharges($order);
    }
コード例 #3
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);
 }
コード例 #4
0
 function it_applies_fixed_discount_as_promotion_adjustment($adjustmentRepository, OrderInterface $order, AdjustmentInterface $adjustment, PromotionInterface $promotion)
 {
     $adjustmentRepository->createNew()->willReturn($adjustment);
     $promotion->getDescription()->willReturn('promotion description');
     $adjustment->setAmount(-500)->shouldBeCalled();
     $adjustment->setLabel(OrderInterface::PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $adjustment->setDescription('promotion description')->shouldBeCalled();
     $order->addAdjustment($adjustment)->shouldBeCalled();
     $configuration = array('amount' => 500);
     $this->execute($order, $configuration, $promotion);
 }
コード例 #5
0
 function it_does_nothing_if_there_are_no_shipment_taxes_on_order($adjustmentsFactory, $calculator, $taxRateResolver, Collection $shippingAdjustments, OrderInterface $order, ShipmentInterface $shipment, ShippingMethodInterface $shippingMethod, TaxRateInterface $taxRate, ZoneInterface $zone)
 {
     $order->getLastShipment()->willReturn($shipment);
     $shipment->getMethod()->willReturn($shippingMethod);
     $taxRateResolver->resolve($shippingMethod, ['zone' => $zone])->willReturn($taxRate);
     $order->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->willReturn($shippingAdjustments);
     $shippingAdjustments->isEmpty()->willReturn(false);
     $order->getShippingTotal()->willReturn(1000);
     $calculator->calculate(1000, $taxRate)->willReturn(0);
     $adjustmentsFactory->createWithData(Argument::cetera())->shouldNotBeCalled();
     $order->addAdjustment(Argument::any())->shouldNotBeCalled();
     $this->apply($order, $zone);
 }
コード例 #6
0
 function it_applies_percentage_discount_as_promotion_adjustment($adjustmentRepository, $originator, OrderInterface $order, AdjustmentInterface $adjustment, PromotionInterface $promotion)
 {
     $order->getPromotionSubjectTotal()->willReturn(10000);
     $adjustmentRepository->createNew()->willReturn($adjustment);
     $promotion->getDescription()->willReturn('promotion description');
     $adjustment->setAmount(-2500)->shouldBeCalled();
     $adjustment->setLabel(AdjustmentInterface::PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $adjustment->setDescription('promotion description')->shouldBeCalled();
     $originator->setOrigin($adjustment, $promotion)->shouldBeCalled();
     $order->addAdjustment($adjustment)->shouldBeCalled();
     $configuration = array('percentage' => 0.25);
     $this->execute($order, $configuration, $promotion);
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function applyShippingCharges(OrderInterface $order)
 {
     // Remove all shipping adjustments, we recalculate everything from scratch.
     $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT);
     foreach ($order->getShipments() as $shipment) {
         $shippingCharge = $this->calculator->calculate($shipment);
         $adjustment = $this->adjustmentFactory->createNew();
         $adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT);
         $adjustment->setAmount($shippingCharge);
         $adjustment->setDescription($shipment->getMethod()->getName());
         $order->addAdjustment($adjustment);
     }
 }
コード例 #8
0
 function it_does_not_applies_bigger_discount_than_promotion_subject_total($adjustmentFactory, $originator, OrderInterface $order, AdjustmentInterface $adjustment, PromotionInterface $promotion)
 {
     $adjustmentFactory->createNew()->willReturn($adjustment);
     $promotion->getDescription()->willReturn('promotion description');
     $order->getPromotionSubjectTotal()->willReturn(1000);
     $adjustment->setAmount(-1000)->shouldBeCalled();
     $adjustment->setType(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $adjustment->setLabel('promotion description')->shouldBeCalled();
     $originator->setOrigin($adjustment, $promotion)->shouldBeCalled();
     $order->addAdjustment($adjustment)->shouldBeCalled();
     $configuration = ['amount' => 1500];
     $this->execute($order, $configuration, $promotion);
 }
コード例 #9
0
 function it_applies_percentage_discount_as_promotion_adjustment(FactoryInterface $adjustmentFactory, $originator, OrderInterface $order, AdjustmentInterface $adjustment, PromotionInterface $promotion)
 {
     $order->getPromotionSubjectTotal()->willReturn(10000);
     $adjustmentFactory->createNew()->willReturn($adjustment);
     $promotion->getName()->willReturn('Test promotion');
     $adjustment->setAmount(-2500)->shouldBeCalled();
     $adjustment->setType(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->shouldBeCalled();
     $adjustment->setLabel('Test promotion')->shouldBeCalled();
     $originator->setOrigin($adjustment, $promotion)->shouldBeCalled();
     $order->addAdjustment($adjustment)->shouldBeCalled();
     $configuration = ['percentage' => 0.25];
     $this->execute($order, $configuration, $promotion);
 }
コード例 #10
0
 function it_applies_calculated_shipping_charge_for_each_shipment_associated_with_the_order(FactoryInterface $adjustmentFactory, DelegatingCalculatorInterface $calculator, AdjustmentInterface $adjustment, OrderInterface $order, ShipmentInterface $shipment, ShippingMethodInterface $shippingMethod)
 {
     $adjustmentFactory->createNew()->willReturn($adjustment);
     $order->getShipments()->willReturn([$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->setLabel('FedEx')->shouldBeCalled();
     $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled();
     $order->addAdjustment($adjustment)->shouldBeCalled();
     $this->process($order);
 }
コード例 #11
0
 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->setLabel(Order::SHIPPING_ADJUSTMENT)->shouldBeCalled();
     $adjustment->setDescription('FedEx')->shouldBeCalled();
     $order->removeShippingAdjustments()->shouldBeCalled();
     $order->addAdjustment($adjustment)->shouldBeCalled();
     $order->calculateTotal()->shouldBeCalled();
     $this->applyShippingCharges($order);
 }
コード例 #12
0
 function it_applies_shipment_taxes_on_order_based_on_shipment_adjustments_and_rate($adjustmentsFactory, $calculator, $taxRateResolver, AdjustmentInterface $shippingAdjustment, AdjustmentInterface $shippingTaxAdjustment, Collection $shippingAdjustments, OrderInterface $order, ShipmentInterface $shipment, ShippingMethodInterface $shippingMethod, TaxRateInterface $taxRate, ZoneInterface $zone)
 {
     $order->getLastShipment()->willReturn($shipment);
     $shipment->getMethod()->willReturn($shippingMethod);
     $taxRateResolver->resolve($shippingMethod, array('zone' => $zone))->willReturn($taxRate);
     $taxRate->getLabel()->willReturn('Simple tax (10%)');
     $taxRate->isIncludedInPrice()->willReturn(false);
     $order->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->willReturn($shippingAdjustments);
     $shippingAdjustments->isEmpty()->willReturn(false);
     $shippingAdjustments->last()->willReturn($shippingAdjustment);
     $shippingAdjustment->getAmount()->willReturn(1000);
     $calculator->calculate(1000, $taxRate)->willReturn(100);
     $adjustmentsFactory->createWithData(AdjustmentInterface::TAX_ADJUSTMENT, 'Simple tax (10%)', 100, false)->willReturn($shippingTaxAdjustment);
     $order->addAdjustment($shippingTaxAdjustment)->shouldBeCalled();
     $this->apply($order, $zone);
 }
コード例 #13
0
 /**
  * {@inheritdoc}
  */
 public function process(OrderInterface $order)
 {
     // Remove all shipping adjustments, we recalculate everything from scratch.
     $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT);
     foreach ($order->getShipments() as $shipment) {
         try {
             $shippingCharge = $this->shippingChargesCalculator->calculate($shipment);
             $adjustment = $this->adjustmentFactory->createNew();
             $adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT);
             $adjustment->setAmount($shippingCharge);
             $adjustment->setLabel($shipment->getMethod()->getName());
             $order->addAdjustment($adjustment);
         } catch (UndefinedShippingMethodException $exception) {
         }
     }
 }
コード例 #14
0
 /**
  * @param OrderInterface $order
  * @param int $taxAmount
  * @param string $label
  * @param bool $included
  */
 private function addAdjustment($order, $taxAmount, $label, $included)
 {
     /** @var AdjustmentInterface $shippingTaxAdjustment */
     $shippingTaxAdjustment = $this->adjustmentFactory->createWithData(AdjustmentInterface::TAX_ADJUSTMENT, $label, $taxAmount, $included);
     $order->addAdjustment($shippingTaxAdjustment);
 }
コード例 #15
0
 private function addAdjustments(array $taxes, OrderInterface $order)
 {
     foreach ($taxes as $description => $tax) {
         $adjustment = $this->adjustmentRepository->createNew();
         $adjustment->setLabel(AdjustmentInterface::TAX_ADJUSTMENT);
         $adjustment->setAmount($tax['amount']);
         $adjustment->setDescription($description);
         $adjustment->setNeutral($tax['included']);
         $order->addAdjustment($adjustment);
     }
 }
コード例 #16
0
 function it_does_nothing_if_order_has_0_shipping_total(TaxRateResolverInterface $taxRateResolver, OrderInterface $order, ZoneInterface $zone)
 {
     $order->getShippingTotal()->willReturn(0);
     $taxRateResolver->resolve(Argument::any())->shouldNotBeCalled();
     $order->addAdjustment(Argument::any())->shouldNotBeCalled();
     $this->apply($order, $zone);
 }