예제 #1
0
 function it_filters_items_which_has_product_with_price_equal_to_configured_minimum_criteria(ChannelInterface $channel, OrderItemInterface $item1, OrderItemInterface $item2, ProductVariantInterface $item1Variant, ProductVariantInterface $item2Variant, ProductVariantPriceCalculatorInterface $productVariantPriceCalculator)
 {
     $item1->getVariant()->willReturn($item1Variant);
     $item2->getVariant()->willReturn($item2Variant);
     $productVariantPriceCalculator->calculate($item1Variant, ['channel' => $channel])->willReturn(500);
     $productVariantPriceCalculator->calculate($item2Variant, ['channel' => $channel])->willReturn(1000);
     $this->filter([$item1, $item2], ['filters' => ['price_range_filter' => ['min' => 1000]], 'channel' => $channel])->shouldReturn([$item2]);
 }
예제 #2
0
 /**
  * @param ProductVariantInterface $variant
  * @param array $configuration
  *
  * @return bool
  */
 private function isItemVariantInPriceRange(ProductVariantInterface $variant, array $configuration)
 {
     $price = $this->productVariantPriceCalculator->calculate($variant, ['channel' => $configuration['channel']]);
     $priceRange = $configuration['filters']['price_range_filter'];
     if (isset($priceRange['min']) && isset($priceRange['max'])) {
         return $priceRange['min'] <= $price && $priceRange['max'] >= $price;
     }
     return $priceRange['min'] <= $price;
 }
예제 #3
0
 /**
  * @param ProductVariantInterface $variant
  * @param ChannelInterface $channel
  *
  * @return array
  */
 private function constructOptionsMap(ProductVariantInterface $variant, ChannelInterface $channel)
 {
     $optionMap = [];
     /** @var ProductOptionValueInterface $option */
     foreach ($variant->getOptionValues() as $option) {
         $optionMap[$option->getOptionCode()] = $option->getValue();
     }
     $optionMap['value'] = $this->productVariantPriceCalculator->calculate($variant, ['channel' => $channel]);
     return $optionMap;
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function process(BaseOrderInterface $order)
 {
     /** @var OrderInterface $order */
     Assert::isInstanceOf($order, OrderInterface::class);
     $channel = $order->getChannel();
     foreach ($order->getItems() as $item) {
         if ($item->isImmutable()) {
             continue;
         }
         $item->setUnitPrice($this->productVariantPriceCalculator->calculate($item->getVariant(), ['channel' => $channel]));
     }
 }
예제 #5
0
 function it_recalculates_prices_adding_customer_to_the_context(ChannelInterface $channel, CustomerGroupInterface $group, CustomerInterface $customer, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, ProductVariantPriceCalculatorInterface $productVariantPriceCalculator)
 {
     $order->getCustomer()->willReturn($customer);
     $order->getChannel()->willReturn(null);
     $order->getItems()->willReturn([$item]);
     $order->getCurrencyCode()->willReturn(null);
     $customer->getGroup()->willReturn($group);
     $item->isImmutable()->willReturn(false);
     $item->getQuantity()->willReturn(5);
     $item->getVariant()->willReturn($variant);
     $order->getChannel()->willReturn($channel);
     $productVariantPriceCalculator->calculate($variant, ['channel' => $channel])->willReturn(10);
     $item->setUnitPrice(10)->shouldBeCalled();
     $this->process($order);
 }
 function it_provides_array_containing_product_variant_options_map_with_corresponding_price(ChannelInterface $channel, ProductInterface $tShirt, ProductOptionValueInterface $black, ProductOptionValueInterface $large, ProductOptionValueInterface $small, ProductOptionValueInterface $white, ProductVariantInterface $blackLargeTShirt, ProductVariantInterface $blackSmallTShirt, ProductVariantInterface $whiteLargeTShirt, ProductVariantInterface $whiteSmallTShirt, ProductVariantPriceCalculatorInterface $productVariantPriceCalculator)
 {
     $tShirt->getVariants()->willReturn([$blackSmallTShirt, $whiteSmallTShirt, $blackLargeTShirt, $whiteLargeTShirt]);
     $blackSmallTShirt->getOptionValues()->willReturn([$black, $small]);
     $whiteSmallTShirt->getOptionValues()->willReturn([$white, $small]);
     $blackLargeTShirt->getOptionValues()->willReturn([$black, $large]);
     $whiteLargeTShirt->getOptionValues()->willReturn([$white, $large]);
     $productVariantPriceCalculator->calculate($blackSmallTShirt, ['channel' => $channel])->willReturn(1000);
     $productVariantPriceCalculator->calculate($whiteSmallTShirt, ['channel' => $channel])->willReturn(1500);
     $productVariantPriceCalculator->calculate($blackLargeTShirt, ['channel' => $channel])->willReturn(2000);
     $productVariantPriceCalculator->calculate($whiteLargeTShirt, ['channel' => $channel])->willReturn(2500);
     $black->getOptionCode()->willReturn('t_shirt_color');
     $white->getOptionCode()->willReturn('t_shirt_color');
     $small->getOptionCode()->willReturn('t_shirt_size');
     $large->getOptionCode()->willReturn('t_shirt_size');
     $black->getValue()->willReturn('Black');
     $white->getValue()->willReturn('White');
     $small->getValue()->willReturn('Small');
     $large->getValue()->willReturn('Large');
     $this->provideVariantsPrices($tShirt, $channel)->shouldReturn([['t_shirt_color' => 'Black', 't_shirt_size' => 'Small', 'value' => 1000], ['t_shirt_color' => 'White', 't_shirt_size' => 'Small', 'value' => 1500], ['t_shirt_color' => 'Black', 't_shirt_size' => 'Large', 'value' => 2000], ['t_shirt_color' => 'White', 't_shirt_size' => 'Large', 'value' => 2500]]);
 }
예제 #7
0
 function it_throws_invalid_argument_exception_when_channel_key_is_not_present_in_context(ProductVariantInterface $productVariant, ProductVariantPriceCalculatorInterface $productVariantPriceCalculator)
 {
     $context = ['lennahc' => ''];
     $this->shouldThrow(\InvalidArgumentException::class)->during('getPrice', [$productVariant, $context]);
     $productVariantPriceCalculator->calculate($productVariant, $context)->shouldNotBeCalled();
 }
예제 #8
0
 /**
  * {@inheritdoc}
  */
 public function getPrice(ProductVariantInterface $productVariant, array $context)
 {
     Assert::keyExists($context, 'channel');
     return $this->productVariantPriceCalculator->calculate($productVariant, $context);
 }