Skip to content

Commit

Permalink
Merge pull request Sylius#8097 from stefandoorn/product-variant-gener…
Browse files Browse the repository at this point in the history
…ator-code-instead-of-id

Use codes of option value & option instead of ID in variant generator
  • Loading branch information
pjedrzejewski committed May 25, 2017
2 parents d46c126 + 775084f commit 2f494d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Expand Up @@ -63,8 +63,8 @@ public function generate(ProductInterface $product)

foreach ($product->getOptions() as $key => $option) {
foreach ($option->getValues() as $value) {
$optionSet[$key][] = $value->getId();
$optionMap[$value->getId()] = $value;
$optionSet[$key][] = $value->getCode();
$optionMap[$value->getCode()] = $value;
}
}

Expand Down Expand Up @@ -108,8 +108,8 @@ private function addOptionValue(ProductVariantInterface $variant, array $optionM
return;
}

foreach ($permutation as $id) {
$variant->addOptionValue($optionMap[$id]);
foreach ($permutation as $code) {
$variant->addOptionValue($optionMap[$code]);
}
}
}
Expand Up @@ -67,9 +67,9 @@ function it_generates_variants_for_every_value_of_an_objects_single_option(

$colorOption->getValues()->willReturn([$blackColor, $whiteColor, $redColor]);

$blackColor->getId()->willReturn('black1');
$whiteColor->getId()->willReturn('white2');
$redColor->getId()->willReturn('red3');
$blackColor->getCode()->willReturn('black1');
$whiteColor->getCode()->willReturn('white2');
$redColor->getCode()->willReturn('red3');

$variantsParityChecker->checkParity($permutationVariant, $productVariable)->willReturn(false);

Expand Down Expand Up @@ -97,9 +97,9 @@ function it_does_not_generate_variant_if_given_variant_exists(

$colorOption->getValues()->willReturn([$blackColor, $whiteColor, $redColor]);

$blackColor->getId()->willReturn('black1');
$whiteColor->getId()->willReturn('white2');
$redColor->getId()->willReturn('red3');
$blackColor->getCode()->willReturn('black1');
$whiteColor->getCode()->willReturn('white2');
$redColor->getCode()->willReturn('red3');

$variantsParityChecker->checkParity($permutationVariant, $productVariable)->willReturn(true);

Expand Down Expand Up @@ -132,12 +132,12 @@ function it_generates_variants_for_every_possible_permutation_of_an_objects_opti
$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');
$blackColor->getCode()->willReturn('black1');
$whiteColor->getCode()->willReturn('white2');
$redColor->getCode()->willReturn('red3');
$smallSize->getCode()->willReturn('small4');
$mediumSize->getCode()->willReturn('medium5');
$largeSize->getCode()->willReturn('large6');

$variantsParityChecker->checkParity($permutationVariant, $productVariable)->willReturn(false);

Expand Down

0 comments on commit 2f494d3

Please sign in to comment.