function it_does_not_add_violation_when_validating_product_in_groups_with_unique_combination_of_axis_attributes($context, $productRepository, GroupInterface $tShirtVariantGroup, GroupTypeInterface $tShirtGroupType, ProductInterface $redTShirtProduct, AttributeInterface $sizeAttribute, AttributeInterface $colorAttribute, ProductValueInterface $sizeProductValue, ProductValueInterface $redColorProductValue, UniqueVariantAxis $uniqueVariantAxisConstraint)
 {
     $tShirtVariantGroup->getId()->willReturn(1);
     $tShirtVariantGroup->getLabel()->willReturn('TShirts');
     $tShirtVariantGroup->getType()->willReturn($tShirtGroupType);
     $tShirtGroupType->isVariant()->willReturn(true);
     $tShirtVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]);
     $sizeAttribute->getCode()->willReturn('size');
     $sizeAttribute->isBackendTypeReferenceData()->willReturn(false);
     $colorAttribute->getCode()->willReturn('color');
     $colorAttribute->isBackendTypeReferenceData()->willReturn(false);
     $redTShirtProduct->getVariantGroup()->willReturn($tShirtVariantGroup);
     $redTShirtProduct->getId()->willReturn(1);
     $redTShirtProduct->getValue('size')->willReturn($sizeProductValue);
     $redTShirtProduct->getValue('color')->willReturn($redColorProductValue);
     $sizeProductValue->getOption()->willReturn('XL');
     $redColorProductValue->getOption()->willReturn('Red');
     $criteria = [['attribute' => $sizeAttribute, 'option' => 'XL'], ['attribute' => $colorAttribute, 'option' => 'Red']];
     $productRepository->findAllForVariantGroup($tShirtVariantGroup, $criteria)->willReturn([]);
     $context->buildViolation()->shouldNotBeCalled(Argument::cetera());
     $this->validate($redTShirtProduct, $uniqueVariantAxisConstraint);
 }
 /**
  * Prepare query criteria for variant group
  *
  * @param GroupInterface   $variantGroup
  * @param ProductInterface $product
  * @param Constraint       $constraint
  *
  * @return array
  */
 protected function prepareQueryCriterias(GroupInterface $variantGroup, ProductInterface $product, Constraint $constraint)
 {
     $criteria = array();
     foreach ($variantGroup->getAxisAttributes() as $attribute) {
         $value = $product->getValue($attribute->getCode());
         // we don't add criteria when option is null, as this check is performed by HasVariantAxesValidator
         if (null !== $value && null !== $value->getOption()) {
             $criteria[] = ['attribute' => $attribute, 'option' => $value->getOption()];
         } else {
             $this->addEmptyAxisViolation($constraint, $variantGroup->getLabel(), $product->getIdentifier()->getVarchar(), $attribute->getCode());
         }
     }
     return $criteria;
 }
 /**
  * Prepare query criteria for variant group
  *
  * @param GroupInterface   $variantGroup
  * @param ProductInterface $product
  * @param Constraint       $constraint
  *
  * @return array
  */
 protected function prepareQueryCriterias(GroupInterface $variantGroup, ProductInterface $product, Constraint $constraint)
 {
     $criteria = [];
     foreach ($variantGroup->getAxisAttributes() as $attribute) {
         $value = $product->getValue($attribute->getCode());
         // we don't add criteria when option is null, as this check is performed by HasVariantAxesValidator
         if (null === $value || null === $value->getOption() && !$attribute->isBackendTypeReferenceData()) {
             $this->addEmptyAxisViolation($constraint, $variantGroup->getLabel(), $product->getIdentifier()->getVarchar(), $attribute->getCode());
             continue;
         }
         $current = ['attribute' => $attribute];
         if (null !== $value->getOption()) {
             $current['option'] = $value->getOption();
         } elseif ($attribute->isBackendTypeReferenceData()) {
             $current['referenceData'] = ['name' => $attribute->getReferenceDataName(), 'data' => $value->getData()];
         }
         $criteria[] = $current;
     }
     return $criteria;
 }
 function it_adds_a_violation_when_validating_product_in_groups_with_non_unique_combination_of_axis_attributes($context, $productRepository, GroupInterface $tShirtVariantGroup, GroupTypeInterface $tShirtGroupType, GroupInterface $clothesVariantGroup, GroupTypeInterface $clothesGroupType, ProductInterface $redTShirtProduct, AttributeInterface $sizeAttribute, AttributeInterface $colorAttribute, ProductValueInterface $sizeProductValue, ProductValueInterface $colorProductValue, ProductInterface $redTShirtProduct2, UniqueVariantAxis $uniqueVariantAxisConstraint)
 {
     $redTShirtProduct->getGroups()->willReturn([$tShirtVariantGroup, $clothesVariantGroup]);
     $tShirtVariantGroup->getId()->willReturn(1);
     $tShirtVariantGroup->getLabel()->willReturn('TShirts');
     $tShirtVariantGroup->getType()->willReturn($tShirtGroupType);
     $tShirtGroupType->isVariant()->willReturn(true);
     $tShirtVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]);
     $clothesVariantGroup->getId()->willReturn(2);
     $clothesVariantGroup->getLabel()->willReturn('Clothes');
     $clothesVariantGroup->getType()->willReturn($clothesGroupType);
     $clothesGroupType->isVariant()->willReturn(true);
     $clothesVariantGroup->getAxisAttributes()->willReturn([$sizeAttribute, $colorAttribute]);
     $sizeAttribute->getCode()->willReturn('size');
     $colorAttribute->getCode()->willReturn('color');
     $redTShirtProduct->getValue('size')->willReturn($sizeProductValue);
     $redTShirtProduct->getValue('color')->willReturn($colorProductValue);
     $redTShirtProduct->getId()->willReturn(1);
     $sizeProductValue->getOption()->willReturn('XL');
     $colorProductValue->getOption()->willReturn('Red');
     $redTShirtProduct2->getGroups()->willReturn([$clothesVariantGroup]);
     $redTShirtProduct2->getValue('size')->willReturn($sizeProductValue);
     $redTShirtProduct2->getValue('color')->willReturn($colorProductValue);
     $redTShirtProduct2->getId()->willReturn(2);
     $criteria = [['attribute' => $sizeAttribute, 'option' => 'XL'], ['attribute' => $colorAttribute, 'option' => 'Red']];
     $productRepository->findAllForVariantGroup($tShirtVariantGroup, $criteria)->willReturn([]);
     $productRepository->findAllForVariantGroup($clothesVariantGroup, $criteria)->willReturn([$redTShirtProduct2]);
     $context->addViolation('Group "%variant group%" already contains another product with values "%values%"', ['%variant group%' => 'Clothes', '%values%' => 'size: XL, color: Red'])->shouldBeCalled();
     $this->validate($redTShirtProduct, $uniqueVariantAxisConstraint);
 }