function it_denies_category_requirement_if_categories_dont_match(ShippingSubjectInterface $subject, ShippingMethodInterface $shippingMethod, ShippingCategoryInterface $shippingCategory, ShippingCategoryInterface $shippingCategory2, ShippableInterface $shippable)
 {
     $shippingMethod->getCategory()->shouldBeCalled()->willReturn($shippingCategory);
     $shippingMethod->getCategoryRequirement()->shouldBeCalled()->willReturn(ShippingMethodInterface::CATEGORY_REQUIREMENT_MATCH_ANY);
     $shippable->getShippingCategory()->shouldBeCalled()->willReturn($shippingCategory2);
     $subject->getShippables()->shouldBeCalled()->willReturn([$shippable]);
     $this->isCategoryEligible($subject, $shippingMethod)->shouldReturn(false);
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function calculate(ShippingSubjectInterface $subject)
 {
     if (null === ($method = $subject->getMethod())) {
         throw new UndefinedShippingMethodException('Cannot calculate charge for shipping subject without defined shipping method.');
     }
     $calculator = $this->registry->get($method->getCalculator());
     return $calculator->calculate($subject, $method->getConfiguration());
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function isEligible(ShippingSubjectInterface $subject, array $configuration)
 {
     $count = $subject->getShippingItemCount();
     if ($configuration['equal']) {
         return $count >= $configuration['count'];
     }
     return $count > $configuration['count'];
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function calculate(ShippingSubjectInterface $subject)
 {
     // FIXME: ShippingSubjectInterface does not have any of called methods!
     if (null === ($method = $subject->getMethod())) {
         throw new UndefinedShippingMethodException('Cannot calculate charge for shipping subject without defined shipping method.');
     }
     /** @var CalculatorInterface $calculator */
     $calculator = $this->registry->get($method->getCalculator());
     return $calculator->calculate($subject, $method->getConfiguration());
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function calculate(ShippingSubjectInterface $subject, array $configuration)
 {
     $firstItemCost = $configuration['first_item_cost'];
     $additionalItemCost = $configuration['additional_item_cost'];
     $additionalItemLimit = $configuration['additional_item_limit'];
     $totalItems = $subject->getShippingItemCount();
     $additionalItems = $totalItems - 1;
     if (0 !== $additionalItemLimit) {
         $additionalItems = $additionalItemLimit >= $additionalItems ? $additionalItems : $additionalItemLimit;
     }
     return (int) ($firstItemCost + $additionalItems * $additionalItemCost);
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function calculate(ShippingSubjectInterface $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);
 }
 /**
  * {@inheritdoc}
  */
 public function isEligible(ShippingSubjectInterface $subject, ShippingMethodInterface $method)
 {
     if (!($category = $method->getCategory())) {
         return true;
     }
     $numMatches = $numShippables = 0;
     foreach ($subject->getShippables() as $shippable) {
         ++$numShippables;
         if ($category === $shippable->getShippingCategory()) {
             ++$numMatches;
         }
     }
     switch ($method->getCategoryRequirement()) {
         case ShippingMethodInterface::CATEGORY_REQUIREMENT_MATCH_NONE:
             return 0 === $numMatches;
         case ShippingMethodInterface::CATEGORY_REQUIREMENT_MATCH_ANY:
             return 0 < $numMatches;
         case ShippingMethodInterface::CATEGORY_REQUIREMENT_MATCH_ALL:
             return $numShippables === $numMatches;
     }
     return false;
 }
 function its_calculated_value_should_be_an_integer(ShippingSubjectInterface $subject)
 {
     $subject->getShippingVolume()->willReturn(100);
     $this->calculate($subject, ['amount' => 500, 'division' => 2])->shouldBeInteger();
 }
예제 #9
0
 function its_calculated_value_should_be_an_integer(ShippingSubjectInterface $subject)
 {
     $subject->getShippingWeight()->willReturn(10);
     $this->calculate($subject, array('fixed' => 200, 'variable' => 500, 'division' => 1))->shouldBeInteger();
 }
예제 #10
0
 function it_should_recognize_subject_as_eligible_if_unit_count_is_equal_with_configured_depending_on_equal_setting(ShippingSubjectInterface $subject)
 {
     $subject->getShippingUnitCount()->shouldBeCalled()->willReturn(10);
     $this->isEligible($subject, ['count' => 10, 'equal' => false])->shouldReturn(false);
     $this->isEligible($subject, ['count' => 10, 'equal' => true])->shouldReturn(true);
 }
예제 #11
0
 /**
  * {@inheritdoc}
  */
 public function calculate(ShippingSubjectInterface $subject, array $configuration)
 {
     return (int) ($configuration['fixed'] + round($configuration['variable'] * ($subject->getShippingWeight() / $configuration['division'])));
 }
예제 #12
0
 /**
  * {@inheritdoc}
  */
 public function calculate(ShippingSubjectInterface $subject, array $configuration)
 {
     return $configuration['amount'] * ($subject->getShippingWeight() / $configuration['division']);
 }
예제 #13
0
 function it_should_calculate_the_total_with_the_per_item_amount_configured_on_the_method(ShippingSubjectInterface $subject)
 {
     $subject->getShippingItemCount()->willReturn(11);
     $this->calculate($subject, array('amount' => 200))->shouldReturn(2200);
 }
예제 #14
0
 /**
  * {@inheritdoc}
  */
 public function calculate(ShippingSubjectInterface $subject, array $configuration)
 {
     return (int) round($configuration['amount'] * ($subject->getShippingVolume() / $configuration['division']));
 }
예제 #15
0
 /**
  * {@inheritdoc}
  */
 public function calculate(ShippingSubjectInterface $subject, array $configuration)
 {
     return (int) ($configuration['amount'] * $subject->getShippingItemCount());
 }
 function its_calculated_value_should_be_an_integer(ShippingSubjectInterface $subject)
 {
     $subject->getShippingItemCount()->willReturn(6);
     $this->calculate($subject, array('amount' => 200))->shouldBeInteger();
 }
 /**
  * {@inheritdoc}
  */
 public function supports(ShippingSubjectInterface $subject)
 {
     return $subject instanceof ShipmentInterface && null !== $subject->getOrder() && null !== $subject->getOrder()->getShippingAddress() && null !== $subject->getOrder()->getChannel();
 }