예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function calculate(PriceableInterface $subject, array $context = array())
 {
     if (null === ($type = $subject->getPricingCalculator())) {
         throw new \InvalidArgumentException('Cannot calculate the price for PriceableInterface instance without calculator defined.');
     }
     $calculator = $this->registry->get($type);
     return $calculator->calculate($subject, $subject->getPricingConfiguration(), $context);
 }
 function it_returns_defaul_price_if_current_channel_price_is_not_configured($channelContext, ChannelInterface $channel, PriceableInterface $subject)
 {
     $channelContext->getChannel()->willReturn($channel);
     $channel->getId()->willReturn(1);
     $subject->getPricingConfiguration()->willReturn([2 => 1400]);
     $subject->getPrice()->willReturn(2000);
     $this->calculate($subject, [], [])->shouldReturn(2000);
 }
 function it_returns_the_default_price_if_configuration_does_not_exist_for_group(PriceableInterface $priceable, GroupInterface $group)
 {
     $configuration = [42 => 4999, 17 => 4599, 95 => 4400];
     $context = ['groups' => [$group]];
     $group->getId()->shouldBeCalled()->willReturn(22);
     $priceable->getPrice()->shouldBeCalled()->willReturn(3500);
     $this->calculate($priceable, $configuration, $context)->shouldReturn(3500);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public final function calculate(PriceableInterface $subject, array $configuration, array $context = [])
 {
     $price = $this->getPriceForConfigurationAndContext($configuration, $context);
     if (null === $price) {
         return $subject->getPrice();
     }
     return $price;
 }
예제 #5
0
 /**
  * @param PriceableInterface $subject
  * @param array              $configuration
  * @param array              $context
  *
  * @return int
  */
 public function calculate(PriceableInterface $subject, array $configuration, array $context = [])
 {
     $currentChannel = $this->channelContext->getChannel();
     $calculatorConfiguration = $subject->getPricingConfiguration();
     if (!isset($calculatorConfiguration[$currentChannel->getId()])) {
         return $subject->getPrice();
     }
     return $calculatorConfiguration[$currentChannel->getId()];
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function calculate(PriceableInterface $subject, array $configuration, array $context = [])
 {
     $quantity = array_key_exists('quantity', $context) ? $context['quantity'] : 1;
     foreach ($configuration as $range) {
         if (null === $range['price']) {
             throw new \Exception('Volume-based price ranges require a `price`.');
         }
         if (empty($range['min']) && $quantity <= $range['max'] || $range['min'] <= $quantity && empty($range['max']) || $range['min'] <= $quantity && $quantity <= $range['max']) {
             return $range['price'];
         }
     }
     return $subject->getPrice();
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function calculate(PriceableInterface $subject, array $configuration, array $context = array())
 {
     $quantity = array_key_exists('quantity', $context) ? $context['quantity'] : 1;
     foreach ($configuration as $range) {
         if (empty($range['max']) && $quantity > $range['min']) {
             return $range['price'];
         }
         if ($range['min'] <= $quantity && $quantity <= $range['max']) {
             return $range['price'];
         }
     }
     return $subject->getPrice();
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function calculate(PriceableInterface $subject, array $configuration, array $context = array())
 {
     if (!array_key_exists($this->parameterName, $context)) {
         return $subject->getPrice();
     }
     $price = null;
     foreach ($context[$this->parameterName] as $object) {
         if (!in_array($this->className, class_implements($object))) {
             throw new UnexpectedTypeException($object, $this->className);
         }
         $id = $object->getId();
         if (array_key_exists($id, $configuration) && (null === $price || $configuration[$id] < $price)) {
             $price = (int) round($configuration[$id]);
         }
     }
     if (null === $price) {
         return $subject->getPrice();
     }
     return $price;
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 public function calculate(PriceableInterface $subject, array $configuration, array $context = array())
 {
     if (!array_key_exists('groups', $context)) {
         return $subject->getPrice();
     }
     $price = null;
     foreach ($context['groups'] as $group) {
         if (!$group instanceof GroupInterface) {
             throw new UnexpectedTypeException($group, 'Sylius\\Component\\Core\\Model\\GroupInterface');
         }
         $id = $group->getId();
         if (array_key_exists($id, $configuration)) {
             if (null === $price || $configuration[$id] < $price) {
                 $price = $configuration[$id];
             }
         }
     }
     if (null === $price) {
         return $subject->getPrice();
     }
     return $price;
 }
예제 #10
0
 function it_returns_the_default_price_stored_on_the_priceable_object(PriceableInterface $priceable)
 {
     $priceable->getPrice()->willReturn(1299);
     $this->calculate($priceable, array())->shouldReturn(1299);
 }
예제 #11
0
 /**
  * {@inheritdoc}
  */
 public function calculate(PriceableInterface $subject, array $configuration, array $context = [])
 {
     return $subject->getPrice();
 }