/** * {@inheritdoc} */ public function calculate(ShipmentInterface $subject) { if (null === ($method = $subject->getMethod())) { throw new UndefinedShippingMethodException('Cannot calculate charge for shipment without a defined shipping method.'); } /** @var CalculatorInterface $calculator */ $calculator = $this->registry->get($method->getCalculator()); return $calculator->calculate($subject, $method->getConfiguration()); }
function it_should_delegate_calculation_to_a_calculator_defined_on_shipping_method(ServiceRegistryInterface $registry, ShipmentInterface $shipment, ShippingMethodInterface $method, CalculatorInterface $calculator) { $shipment->getMethod()->willReturn($method); $method->getCalculator()->willReturn('default'); $method->getConfiguration()->willReturn([]); $registry->get('default')->willReturn($calculator); $calculator->calculate($shipment, [])->shouldBeCalled()->willReturn(1000); $this->calculate($shipment, [])->shouldReturn(1000); }
/** * {@inheritdoc} */ public function calculate(ShipmentInterface $subject, array $configuration) { $firstUnitCost = $configuration['first_unit_cost']; $additionalUnitCost = $configuration['additional_unit_cost']; $additionalUnitLimit = $configuration['additional_unit_limit']; $totalUnits = $subject->getShippingUnitCount(); $additionalUnits = $totalUnits - 1; if (0 !== $additionalUnitLimit) { $additionalUnits = $additionalUnitLimit >= $additionalUnits ? $additionalUnits : $additionalUnitLimit; } return (int) ($firstUnitCost + $additionalUnits * $additionalUnitCost); }
function its_calculated_value_should_be_an_integer(ShipmentInterface $shipment) { $configuration = ['first_unit_cost' => 1090, 'additional_unit_cost' => 200, 'additional_unit_limit' => 3]; $shipment->getShippingUnitCount()->willReturn(6); $this->calculate($shipment, $configuration)->shouldBeInteger(); }
/** * {@inheritdoc} */ public function calculate(ShipmentInterface $subject, array $configuration) { return (int) ($configuration['amount'] * $subject->getShippingUnitCount()); }
/** * @param ShipmentInterface $shipment */ public function sendConfirmationEmail(ShipmentInterface $shipment) { /** @var \Sylius\Component\Core\Model\OrderInterface $order */ $order = $shipment->getOrder(); $this->emailSender->send(Emails::SHIPMENT_CONFIRMATION, array($order->getCustomer()->getEmail()), array('shipment' => $shipment, 'order' => $order)); }
/** * {@inheritdoc} */ public function calculate(ShipmentInterface $subject, array $configuration) { return (int) round($configuration['amount'] * ($subject->getShippingVolume() / $configuration['division'])); }
function its_calculated_value_should_be_an_integer(ShipmentInterface $subject) { $subject->getShippingVolume()->willReturn(100); $this->calculate($subject, ['amount' => 500, 'division' => 2])->shouldBeInteger(); }
function its_calculated_value_should_be_an_integer(ShipmentInterface $subject) { $subject->getShippingWeight()->willReturn(10); $this->calculate($subject, ['fixed' => 200, 'variable' => 500, 'division' => 1])->shouldBeInteger(); }
function its_calculated_value_should_be_an_integer(ShipmentInterface $subject) { $subject->getShippingUnitCount()->willReturn(6); $this->calculate($subject, ['amount' => 200])->shouldBeInteger(); }
/** * {@inheritdoc} */ public function calculate(ShipmentInterface $subject, array $configuration) { return (int) ($configuration['fixed'] + round($configuration['variable'] * ($subject->getShippingWeight() / $configuration['division']))); }
function it_should_calculate_the_first_and_every_additional_item_cost_taking_limit_into_account(ShipmentInterface $shipment) { $configuration = array('first_item_cost' => 1500, 'additional_item_cost' => 300, 'additional_item_limit' => 3); $shipment->getShippingItemCount()->willReturn(8); $this->calculate($shipment, $configuration)->shouldReturn(2400); }