function it_checks_value_existence(ProductRepositoryInterface $productRepository, ProductValueInterface $value)
 {
     $productRepository->valueExists($value)->willReturn(true);
     $this->valueExists($value)->shouldReturn(true);
     $productRepository->valueExists($value)->willReturn(false);
     $this->valueExists($value)->shouldReturn(false);
 }
 /**
  * Checks the uniqueness of product values that should be unique
  * As the uniqueness check is normally executed against the database
  * and imported products have not been persisted yet, this effectively
  * checks that the items in the current batch don't contain duplicate values
  * for unique attributes.
  *
  * @param object $entity
  * @param array  $columnsInfo
  * @param array  $data
  *
  * @throws DuplicateProductValueException When duplicate values are encountered
  */
 protected function checkUniqueValues($entity, array $columnsInfo, array $data)
 {
     foreach ($columnsInfo as $columnInfo) {
         if ($columnInfo->getAttribute()) {
             $value = $this->getProductValue($entity, $columnInfo);
             if ($value->getAttribute()->isUnique()) {
                 $code = $value->getAttribute()->getCode();
                 $valueData = (string) $value;
                 if ($valueData !== '') {
                     if ($this->productRepository->valueExists($value)) {
                         throw new DuplicateProductValueException($code, $valueData, $data);
                     }
                     $this->uniqueValues[$code] = isset($this->uniqueValues[$code]) ? $this->uniqueValues[$code] : [];
                     if (isset($this->uniqueValues[$code][$valueData])) {
                         throw new DuplicateProductValueException($code, $valueData, $data);
                     } else {
                         $this->uniqueValues[$code][$valueData] = "";
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Check if a product value with a specific value already exists
  *
  * @param ProductValueInterface $value
  *
  * @return bool
  *
  * @deprecated will be removed in 1.5, please use ProductRepositoryInterface::valueExists
  */
 public function valueExists(ProductValueInterface $value)
 {
     return $this->productRepository->valueExists($value);
 }
 function it_does_not_validate_with_empty_value(ProductRepositoryInterface $productRepository, ProductValueInterface $value, ExecutionContextInterface $context, Constraint $constraint)
 {
     $productRepository->valueExists($value)->shouldNotBeCalled();
     $context->buildViolation(Argument::any())->shouldNotBeCalled();
     $this->validate("", $constraint)->shouldReturn(null);
 }
 /**
  * @param ProductValueInterface $productValue
  *
  * @return bool
  */
 protected function alreadyExists(ProductValueInterface $productValue)
 {
     return $this->repository->valueExists($productValue);
 }