/** * @param ProductVariantInterface $variant * * @return array */ private function constructOptionsMap(ProductVariantInterface $variant) { $optionMap = []; /** @var ProductOptionValueInterface $option */ foreach ($variant->getOptionValues() as $option) { $optionMap[$option->getOptionCode()] = $option->getValue(); } $optionMap['value'] = $variant->getPrice(); return $optionMap; }
/** * @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; }
function it_provides_array_containing_product_variant_options_map_with_corresponding_price(ProductInterface $tShirt, ProductOptionValueInterface $black, ProductOptionValueInterface $large, ProductOptionValueInterface $small, ProductOptionValueInterface $white, ProductVariantInterface $blackLargeTShirt, ProductVariantInterface $blackSmallTShirt, ProductVariantInterface $whiteLargeTShirt, ProductVariantInterface $whiteSmallTShirt) { $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]); $blackSmallTShirt->getPrice()->willReturn(1000); $whiteSmallTShirt->getPrice()->willReturn(1500); $blackLargeTShirt->getPrice()->willReturn(2000); $whiteLargeTShirt->getPrice()->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)->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]]); }