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); }
/** * @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()]; }