function it_adds_violation_if_variant_with_given_same_options_already_exists(ExecutionContextInterface $context, ProductInterface $variable, ProductOptionValueInterface $optionValue, ProductVariantInterface $existingVariant, ProductVariantInterface $variant)
 {
     $constraint = new ProductVariantCombination(['message' => 'Variant with given options already exists']);
     $variant->getProduct()->willReturn($variable);
     $variant->getOptionValues()->willReturn(new ArrayCollection([$optionValue->getWrappedObject()]));
     $existingVariant->hasOptionValue($optionValue)->willReturn(true);
     $variable->hasVariants()->willReturn(true);
     $variable->hasOptions()->willReturn(true);
     $variable->getVariants()->willReturn([$existingVariant]);
     $context->addViolation('Variant with given options already exists', Argument::any())->shouldBeCalled();
     $this->validate($variant, $constraint);
 }
Ejemplo n.º 2
0
 function it_generates_variants_for_every_possible_permutation_of_an_objects_options_and_option_values(ProductInterface $productVariable, ProductOptionInterface $colorOption, ProductOptionInterface $sizeOption, ProductOptionValueInterface $blackColor, ProductOptionValueInterface $largeSize, ProductOptionValueInterface $mediumSize, ProductOptionValueInterface $redColor, ProductOptionValueInterface $smallSize, ProductOptionValueInterface $whiteColor, ProductVariantFactoryInterface $productVariantFactory, ProductVariantInterface $permutationVariant)
 {
     $productVariable->hasOptions()->willReturn(true);
     $productVariable->getOptions()->willReturn([$colorOption, $sizeOption]);
     $colorOption->getValues()->willReturn([$blackColor, $whiteColor, $redColor]);
     $sizeOption->getValues()->willReturn([$smallSize, $mediumSize, $largeSize]);
     $blackColor->getId()->willReturn('black1');
     $whiteColor->getId()->willReturn('white2');
     $redColor->getId()->willReturn('red3');
     $smallSize->getId()->willReturn('small4');
     $mediumSize->getId()->willReturn('medium5');
     $largeSize->getId()->willReturn('large6');
     $productVariantFactory->createForProduct($productVariable)->willReturn($permutationVariant);
     $permutationVariant->addOptionValue(Argument::type(ProductOptionValueInterface::class))->shouldBeCalled();
     $productVariable->addVariant($permutationVariant)->shouldBeCalled();
     $this->generate($productVariable);
 }
 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]]);
 }