/** * {@inheritdoc} */ public function isEligible(ShippingSubjectInterface $subject, array $configuration) { $count = $subject->getShippingItemCount(); if ($configuration['equal']) { return $count >= $configuration['count']; } return $count > $configuration['count']; }
/** * {@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); }
/** * {@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(); }
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); }
function it_should_recognize_subject_as_eligible_if_item_count_is_equal_with_configured_depending_on_equal_setting(ShippingSubjectInterface $subject) { $subject->getShippingItemCount()->shouldBeCalled()->willReturn(10); $this->isEligible($subject, array('count' => 10, 'equal' => false))->shouldReturn(false); $this->isEligible($subject, array('count' => 10, 'equal' => true))->shouldReturn(true); }