/**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     try {
         $options = $this->resolver->resolve($options);
     } catch (\Exception $e) {
         throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'filter', 'options');
     }
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'options');
     if ($operator != Operators::IS_EMPTY) {
         $this->checkValue($options['field'], $value);
     }
     $joinAlias = $this->getUniqueAlias('filter' . $attribute->getCode());
     $joinAliasOpt = $this->getUniqueAlias('filterO' . $attribute->getCode());
     $backendField = sprintf('%s.%s', $joinAliasOpt, 'id');
     if (Operators::IS_EMPTY === $operator) {
         $this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope));
         $this->qb->leftJoin($joinAlias . '.' . $attribute->getBackendType(), $joinAliasOpt)->andWhere($this->qb->expr()->isNull($backendField));
     } else {
         if (FieldFilterHelper::getProperty($options['field']) === FieldFilterHelper::CODE_PROPERTY) {
             $value = $this->objectIdResolver->getIdsFromCodes('option', $value, $attribute);
         }
         $this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope))->innerJoin($joinAlias . '.' . $attribute->getBackendType(), $joinAliasOpt, 'WITH', $this->qb->expr()->in($backendField, $value));
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     try {
         $options = $this->resolver->resolve($options);
     } catch (\Exception $e) {
         throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'filter', 'option');
     }
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'option');
     $field = $options['field'];
     if (Operators::IS_EMPTY !== $operator) {
         $this->checkValue($field, $value);
     }
     $joinAlias = $this->getUniqueAlias('filter' . $attribute->getCode(), true);
     // prepare join value condition
     $optionAlias = $joinAlias . '.option';
     if (Operators::IS_EMPTY === $operator) {
         $this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope));
         $this->qb->andWhere($this->qb->expr()->isNull($optionAlias));
     } else {
         // inner join to value
         $condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope);
         if (FieldFilterHelper::getProperty($field) === FieldFilterHelper::CODE_PROPERTY) {
             $value = $this->objectIdResolver->getIdsFromCodes('option', $value, $attribute);
         }
         $condition .= ' AND ( ' . $this->qb->expr()->in($optionAlias, $value) . ' ) ';
         $this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
     }
     return $this;
 }
 function it_copies_simple_select_value_to_a_product_value($builder, $attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValueInterface $fromProductValue, ProductValueInterface $toProductValue, AttributeOptionInterface $attributeOption)
 {
     $fromLocale = 'fr_FR';
     $toLocale = 'fr_FR';
     $toScope = 'mobile';
     $fromScope = 'mobile';
     $fromAttribute->getCode()->willReturn('fromAttributeCode');
     $toAttribute->getCode()->willReturn('toAttributeCode');
     $attrValidatorHelper->validateLocale(Argument::cetera())->shouldBeCalled();
     $attrValidatorHelper->validateScope(Argument::cetera())->shouldBeCalled();
     $fromProductValue->getData()->willReturn($attributeOption);
     $toProductValue->setOption($attributeOption)->shouldBeCalledTimes(3);
     $product1->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
     $product1->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
     $product2->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn(null);
     $product2->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
     $product3->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
     $product3->getValue('toAttributeCode', $toLocale, $toScope)->willReturn(null);
     $product4->getValue('fromAttributeCode', $fromLocale, $fromScope)->willReturn($fromProductValue);
     $product4->getValue('toAttributeCode', $toLocale, $toScope)->willReturn($toProductValue);
     $builder->addProductValue($product3, $toAttribute, $toLocale, $toScope)->shouldBeCalledTimes(1)->willReturn($toProductValue);
     $products = [$product1, $product2, $product3, $product4];
     foreach ($products as $product) {
         $this->copyAttributeData($product, $product, $fromAttribute, $toAttribute, ['from_locale' => $fromLocale, 'to_locale' => $toLocale, 'from_scope' => $fromScope, 'to_scope' => $toScope]);
     }
 }
 function it_throws_an_exception_when_the_locale_is_not_provided($qb, AttributeInterface $attribute)
 {
     $attribute->getCode()->willReturn('my_code');
     $attribute->getBackendType()->willReturn('options');
     $attribute->getAttributeType()->willReturn('pim_catalog_simpleselect');
     $this->shouldThrow('\\InvalidArgumentException')->duringAddAttributeSorter($attribute, 'desc', null, 'ecommerce');
 }
 /**
  * {@inheritdoc}
  */
 protected function findEntity($class, array $data)
 {
     if (!$this->identifierAttribute) {
         throw new MissingIdentifierException();
     }
     return $this->productRepository->findOneByIdentifier($data[$this->identifierAttribute->getCode()]);
 }
 function it_allows_setting_attribute_data_option_to_null(ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value)
 {
     $attribute->getCode()->willReturn('choice');
     $product->getValue('choice', 'fr_FR', 'mobile')->shouldBeCalled()->willReturn($value);
     $value->setOption(null)->shouldBeCalled();
     $this->setAttributeData($product, $attribute, null, ['locale' => 'fr_FR', 'scope' => 'mobile']);
 }
 function it_returns_well_formatted_actions_for_batch_job(AttributeInterface $attrColor, AttributeInterface $attrSize, ChannelInterface $channelMobile, ChannelInterface $channelEcommerce, AttributeRequirementInterface $colorMobileRequirement, AttributeRequirementInterface $colorEcommerceRequirement, AttributeRequirementInterface $sizeEcommerceRequirement)
 {
     $attrColor->getCode()->willReturn('color');
     $attrSize->getCode()->willReturn('size');
     $channelMobile->getCode()->willReturn('mobile');
     $channelEcommerce->getCode()->willReturn('ecommerce');
     $colorMobileRequirement->getAttribute()->willReturn($attrColor);
     $colorEcommerceRequirement->getAttribute()->willReturn($attrColor);
     $sizeEcommerceRequirement->getAttribute()->willReturn($attrSize);
     $colorMobileRequirement->getChannel()->willReturn($channelMobile);
     $colorEcommerceRequirement->getChannel()->willReturn($channelEcommerce);
     $sizeEcommerceRequirement->getChannel()->willReturn($channelEcommerce);
     $colorMobileRequirement->isRequired()->willReturn(false);
     $colorEcommerceRequirement->isRequired()->willReturn(true);
     $sizeEcommerceRequirement->isRequired()->willReturn(true);
     $colorMobileRequirement->getAttributeCode()->willReturn('color');
     $colorEcommerceRequirement->getAttributeCode()->willReturn('color');
     $sizeEcommerceRequirement->getAttributeCode()->willReturn('size');
     $colorMobileRequirement->getChannelCode()->willReturn('mobile');
     $colorEcommerceRequirement->getChannelCode()->willReturn('ecommerce');
     $sizeEcommerceRequirement->getChannelCode()->willReturn('ecommerce');
     $this->addAttributeRequirement($colorMobileRequirement);
     $this->addAttributeRequirement($colorEcommerceRequirement);
     $this->addAttributeRequirement($sizeEcommerceRequirement);
     $this->getActions()->shouldReturn([['attribute_code' => 'color', 'channel_code' => 'mobile', 'is_required' => false], ['attribute_code' => 'color', 'channel_code' => 'ecommerce', 'is_required' => true], ['attribute_code' => 'size', 'channel_code' => 'ecommerce', 'is_required' => true]]);
 }
 function it_removes_attributes_from_a_product_template(ProductTemplateInterface $template, AttributeInterface $name)
 {
     $name->getCode()->willReturn('name');
     $template->getValuesData()->willReturn(['name' => 'foo', 'color' => 'bar']);
     $template->setValuesData(['color' => 'bar'])->shouldBeCalled();
     $this->removeAttribute($template, $name);
 }
 function it_throws_an_error_if_attribute_data_value_does_not_contain_valid_currency($currencyManager, AttributeInterface $attribute, ProductInterface $product)
 {
     $attribute->getCode()->willReturn('attributeCode');
     $currencyManager->getActiveCodes()->willReturn(['EUR', 'USD']);
     $data = [['data' => 123, 'currency' => 'invalid currency']];
     $this->shouldThrow(InvalidArgumentException::arrayInvalidKey('attributeCode', 'currency', 'The currency does not exist', 'remover', 'prices collection', 'invalid currency'))->during('removeAttributeData', [$product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']]);
 }
 function it_resolves_eligible_values_for_a_set_of_attributes($localeRepository, $channelRepository, AttributeInterface $sku, AttributeInterface $name, AttributeInterface $desc, AttributeInterface $tax, LocaleInterface $fr, LocaleInterface $en, ChannelInterface $ecom, ChannelInterface $print)
 {
     $sku->getCode()->willReturn('sku');
     $sku->getAttributeType()->willReturn('pim_catalog_identifier');
     $sku->isLocalizable()->willReturn(false);
     $sku->isScopable()->willReturn(false);
     $sku->isLocaleSpecific()->willReturn(false);
     $name->getCode()->willReturn('name');
     $name->getAttributeType()->willReturn('pim_catalog_text');
     $name->isLocalizable()->willReturn(true);
     $name->isScopable()->willReturn(false);
     $name->isLocaleSpecific()->willReturn(false);
     $desc->getCode()->willReturn('description');
     $desc->getAttributeType()->willReturn('pim_catalog_text');
     $desc->isLocalizable()->willReturn(true);
     $desc->isScopable()->willReturn(true);
     $desc->isLocaleSpecific()->willReturn(false);
     $tax->getCode()->willReturn('tax');
     $tax->getAttributeType()->willReturn('pim_catalog_text');
     $tax->isLocalizable()->willReturn(true);
     $tax->isScopable()->willReturn(false);
     $tax->isLocaleSpecific()->willReturn(true);
     $tax->getLocaleSpecificCodes()->willReturn(['fr_FR']);
     $fr->getCode()->willReturn('fr_FR');
     $en->getCode()->willReturn('en_US');
     $localeRepository->getActivatedLocales()->willReturn([$fr, $en]);
     $ecom->getCode()->willReturn('ecommerce');
     $ecom->getLocales()->willReturn([$en, $fr]);
     $print->getCode()->willReturn('print');
     $print->getLocales()->willReturn([$en, $fr]);
     $channelRepository->findAll()->willReturn([$ecom, $print]);
     $this->resolveEligibleValues([$sku, $name, $desc, $tax])->shouldReturn([['attribute' => 'sku', 'type' => 'pim_catalog_identifier', 'locale' => null, 'scope' => null], ['attribute' => 'name', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => null], ['attribute' => 'name', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => null], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => 'ecommerce'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => 'ecommerce'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'en_US', 'scope' => 'print'], ['attribute' => 'description', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => 'print'], ['attribute' => 'tax', 'type' => 'pim_catalog_text', 'locale' => 'fr_FR', 'scope' => null]]);
 }
 function let(TranslationNormalizer $transnormalizer, AttributeInterface $attribute, AttributeGroupInterface $attributeGroup)
 {
     $this->beConstructedWith($transnormalizer);
     $transnormalizer->normalize(Argument::cetera())->willReturn([]);
     $attribute->getAttributeType()->willReturn('Yes/No');
     $attribute->getCode()->willReturn('attribute_size');
     $attribute->getGroup()->willReturn($attributeGroup);
     $attributeGroup->getCode()->willReturn('size');
     $attribute->isUnique()->willReturn(true);
     $attribute->isUseableAsGridFilter()->willReturn(false);
     $attribute->getAllowedExtensions()->willReturn(['csv', 'xml', 'json']);
     $attribute->getMetricFamily()->willReturn('Length');
     $attribute->getDefaultMetricUnit()->willReturn('Centimenter');
     $attribute->getReferenceDataName()->willReturn('color');
     $attribute->isLocalizable()->willReturn(true);
     $attribute->isScopable()->willReturn(false);
     $attribute->getLocaleSpecificCodes()->willReturn(['en_US', 'fr_FR']);
     $attribute->getMaxCharacters()->willReturn(null);
     $attribute->getValidationRule()->willReturn(null);
     $attribute->getValidationRegexp()->willReturn(null);
     $attribute->isWysiwygEnabled()->willReturn(false);
     $attribute->getNumberMin()->willReturn('');
     $attribute->getNumberMax()->willReturn('');
     $attribute->isDecimalsAllowed()->willReturn(false);
     $attribute->isNegativeAllowed()->willReturn(false);
     $attribute->getDateMin()->willReturn(null);
     $attribute->getDateMax()->willReturn(null);
     $attribute->getMaxFileSize()->willReturn(null);
     $attribute->getMinimumInputLength()->willReturn(null);
     $attribute->getSortOrder()->willReturn(0);
 }
 function it_normalize_completnesses_and_index_them($normalizer, AttributeInterface $name, AttributeInterface $description)
 {
     $normalizer->normalize('completeness', 'internal_api', ['a_context_key' => 'context_value'])->willReturn('normalized_completeness');
     $name->getCode()->willReturn('name');
     $description->getCode()->willReturn('description');
     $this->normalize(['en_US' => ['channels' => ['mobile' => ['missing' => [$name, $description], 'completeness' => 'completeness'], 'print' => ['missing' => [$name, $description], 'completeness' => 'completeness'], 'tablet' => ['missing' => [$name, $description], 'completeness' => 'completeness']]], 'fr_FR' => ['channels' => ['mobile' => ['missing' => [$name, $description], 'completeness' => 'completeness'], 'print' => ['missing' => [$name, $description], 'completeness' => 'completeness'], 'tablet' => ['missing' => [$name, $description], 'completeness' => 'completeness']]]], 'internal_api', ['a_context_key' => 'context_value'])->shouldReturn(['en_US' => ['channels' => ['mobile' => ['missing' => ['name', 'description'], 'completeness' => 'normalized_completeness'], 'print' => ['missing' => ['name', 'description'], 'completeness' => 'normalized_completeness'], 'tablet' => ['missing' => ['name', 'description'], 'completeness' => 'normalized_completeness']]], 'fr_FR' => ['channels' => ['mobile' => ['missing' => ['name', 'description'], 'completeness' => 'normalized_completeness'], 'print' => ['missing' => ['name', 'description'], 'completeness' => 'normalized_completeness'], 'tablet' => ['missing' => ['name', 'description'], 'completeness' => 'normalized_completeness']]]]);
 }
Пример #13
0
 /**
  * {@inheritdoc}
  */
 public function addAttributeFilter(AttributeInterface $attribute, $operator, $value, $locale = null, $scope = null, $options = [])
 {
     try {
         $options = $this->resolver->resolve($options);
     } catch (\Exception $e) {
         throw InvalidArgumentException::expectedFromPreviousException($e, $attribute->getCode(), 'filter', 'string');
     }
     $this->checkLocaleAndScope($attribute, $locale, $scope, 'string');
     if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator) {
         $this->checkValue($options['field'], $value);
     }
     $joinAlias = $this->getUniqueAlias('filter' . $attribute->getCode());
     $backendField = sprintf('%s.%s', $joinAlias, $attribute->getBackendType());
     if (Operators::IS_EMPTY === $operator) {
         $this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope));
         $this->qb->andWhere($this->prepareCriteriaCondition($backendField, $operator, $value));
     } else {
         $condition = $this->prepareAttributeJoinCondition($attribute, $joinAlias, $locale, $scope);
         if (Operators::IS_NOT_EMPTY === $operator) {
             $condition .= sprintf('AND (%s AND %s)', $this->qb->expr()->isNotNull($backendField), $this->qb->expr()->neq($backendField, $this->qb->expr()->literal('')));
             $this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
         } elseif (Operators::DOES_NOT_CONTAIN === $operator) {
             $whereCondition = $this->prepareCondition($backendField, $operator, $value) . ' OR ' . $this->prepareCondition($backendField, Operators::IS_NULL, null);
             $this->qb->leftJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
             $this->qb->andWhere($whereCondition);
         } else {
             $condition .= ' AND ' . $this->prepareCondition($backendField, $operator, $value);
             $this->qb->innerJoin($this->qb->getRootAlias() . '.values', $joinAlias, 'WITH', $condition);
         }
     }
     return $this;
 }
 /**
  * Returns available information for the attribute and filters which supports it
  *
  * @param AttributeInterface $attribute
  * @param array              $attributeFilters
  *
  * @return array
  */
 protected function getFilterInformationForAttribute(AttributeInterface $attribute, array $attributeFilters)
 {
     $field = $attribute->getCode();
     $attributeType = $attribute->getAttributeType();
     $isLocalizable = $attribute->isLocalizable() ? 'yes' : 'no';
     $isScopable = $attribute->isScopable() ? 'yes' : 'no';
     $newEntries = [];
     if (array_key_exists($attributeType, $attributeFilters)) {
         foreach ($attributeFilters[$attributeType] as $filter) {
             $class = get_class($filter);
             $operators = implode(', ', $filter->getOperators());
             $newEntries[] = [$field, $isLocalizable, $isScopable, $attributeType, $operators, $class];
         }
         return $newEntries;
     }
     if ($attribute->isBackendTypeReferenceData()) {
         foreach ($this->registry->getAttributeFilters() as $filter) {
             if ($filter->supportsAttribute($attribute)) {
                 $class = get_class($filter);
                 $operators = implode(', ', $filter->getOperators());
                 $newEntries[] = [$field, $isLocalizable, $isScopable, $attributeType, $operators, $class];
             }
         }
         return $newEntries;
     }
     return [[$field, $isLocalizable, $isScopable, $attributeType, '', 'Not supported']];
 }
Пример #15
0
 /**
  * {@inheritdoc}
  */
 public function getReference()
 {
     if (null === $this->code) {
         return null;
     }
     return ($this->attribute ? $this->attribute->getCode() : '') . '.' . $this->code;
 }
 function it_normalizes_attribute($transNormalizer, $dateTimeNormalizer, AttributeInterface $attribute, AttributeGroupInterface $attributeGroup)
 {
     $transNormalizer->normalize(Argument::cetera())->willReturn([]);
     $dateMin = new \DateTime('2015-05-23 15:55:50');
     $dateMax = new \DateTime('2015-06-23 15:55:50');
     $attribute->getAttributeType()->willReturn('Yes/No');
     $attribute->getCode()->willReturn('attribute_size');
     $attribute->getGroup()->willReturn($attributeGroup);
     $attributeGroup->getCode()->willReturn('size');
     $attribute->isUnique()->willReturn(true);
     $attribute->isUseableAsGridFilter()->willReturn(true);
     $attribute->getAllowedExtensions()->willReturn(['csv', 'xml', 'json']);
     $attribute->getMetricFamily()->willReturn('Length');
     $attribute->getDefaultMetricUnit()->willReturn('Centimenter');
     $attribute->getReferenceDataName()->willReturn('color');
     $attribute->isLocalizable()->willReturn(true);
     $attribute->isScopable()->willReturn(true);
     $attribute->getLocaleSpecificCodes()->willReturn(['en_US', 'fr_FR']);
     $attribute->getMaxCharacters()->willReturn(255);
     $attribute->getValidationRule()->willReturn('email');
     $attribute->getValidationRegexp()->willReturn('[0-9]*');
     $attribute->isWysiwygEnabled()->willReturn(true);
     $attribute->getNumberMin()->willReturn('0.55');
     $attribute->getNumberMax()->willReturn('1500.55');
     $attribute->isDecimalsAllowed()->willReturn(true);
     $attribute->isNegativeAllowed()->willReturn(true);
     $attribute->getDateMin()->willReturn($dateMin);
     $attribute->getDateMax()->willReturn($dateMax);
     $attribute->getMaxFileSize()->willReturn(1024);
     $attribute->getMinimumInputLength()->willReturn(2);
     $attribute->getSortOrder()->willReturn(4);
     $dateTimeNormalizer->normalize($dateMin)->willReturn('2015-05-23T15:55:50+01:00');
     $dateTimeNormalizer->normalize($dateMax)->willReturn('2015-06-23T15:55:50+01:00');
     $this->normalize($attribute)->shouldReturn(['code' => 'attribute_size', 'type' => 'Yes/No', 'group' => 'size', 'unique' => true, 'useable_as_grid_filter' => true, 'allowed_extensions' => ['csv', 'xml', 'json'], 'metric_family' => 'Length', 'default_metric_unit' => 'Centimenter', 'reference_data_name' => 'color', 'available_locales' => ['en_US', 'fr_FR'], 'max_characters' => 255, 'validation_rule' => 'email', 'validation_regexp' => '[0-9]*', 'wysiwyg_enabled' => true, 'number_min' => '0.55', 'number_max' => '1500.55', 'decimals_allowed' => true, 'negative_allowed' => true, 'date_min' => '2015-05-23T15:55:50+01:00', 'date_max' => '2015-06-23T15:55:50+01:00', 'max_file_size' => '1024', 'minimum_input_length' => 2, 'sort_order' => 4, 'localizable' => true, 'scopable' => true, 'labels' => []]);
 }
 function it_normalizes_family($normalizer, FamilyInterface $family, AttributeInterface $sku)
 {
     $sku->getCode()->willReturn('sku');
     $family->getCode()->willReturn('mongo');
     $family->getAttributeAsLabel()->willReturn($sku);
     $normalizer->normalize($family, 'mongodb_json', [])->willReturn(['label' => 'translations']);
     $this->normalize($family, 'mongodb_json', [])->shouldReturn(['code' => 'mongo', 'label' => 'translations', 'attributeAsLabel' => 'sku']);
 }
Пример #18
0
 /**
  * Prepare join to attribute condition with current locale and scope criterias
  *
  * @param AttributeInterface $attribute the attribute
  * @param string             $joinAlias the value join alias
  * @param string             $locale    the locale
  * @param string             $scope     the scope
  *
  * @return string
  */
 public function prepareCondition(AttributeInterface $attribute, $joinAlias, $locale = null, $scope = null)
 {
     $condition = $joinAlias . '.attribute = ' . $attribute->getId();
     if ($attribute->isLocalizable() && null === $locale) {
         throw new \InvalidArgumentException(sprintf('Cannot prepare condition on localizable attribute "%s" without locale', $attribute->getCode()));
     }
     if ($attribute->isLocalizable()) {
         $condition .= ' AND ' . $joinAlias . '.locale = ' . $this->qb->expr()->literal($locale);
     }
     if ($attribute->isScopable() && null === $scope) {
         throw new \InvalidArgumentException(sprintf('Cannot prepare condition on scopable attribute "%s" without scope', $attribute->getCode()));
     }
     if ($attribute->isScopable()) {
         $condition .= ' AND ' . $joinAlias . '.scope = ' . $this->qb->expr()->literal($scope);
     }
     return $condition;
 }
 /**
  * {@inheritdoc}
  */
 public function setAttribute(AttributeInterface $attribute = null)
 {
     if (is_object($this->attribute) && $attribute != $this->attribute) {
         throw new \LogicException(sprintf('An attribute (%s) has already been set for this value', $this->attribute->getCode()));
     }
     $this->attribute = $attribute;
     return $this;
 }
 function let(Builder $qb, AttributeInterface $image, AttributeValidatorHelper $attrValidatorHelper)
 {
     $this->beConstructedWith($attrValidatorHelper, ['pim_catalog_image', 'pim_catalog_file'], ['STARTS WITH', 'ENDS WITH', 'CONTAINS', 'DOES NOT CONTAIN', '=', 'EMPTY']);
     $this->setQueryBuilder($qb);
     $image->getCode()->willReturn('picture');
     $image->isLocalizable()->willReturn(false);
     $image->isScopable()->willReturn(false);
 }
 function it_returns_empty_data_if_empty_value_provided(AttributeInterface $attribute)
 {
     $attribute->getCode()->willReturn('attribute_code');
     $fieldNameInfo = ['attribute' => $attribute, 'locale_code' => 'en_US', 'scope_code' => 'mobile'];
     $value = '';
     $expectedResult = ['attribute_code' => [['locale' => 'en_US', 'scope' => 'mobile', 'data' => null]]];
     $this->convert($fieldNameInfo, $value)->shouldReturn($expectedResult);
 }
 /**
  * Set data into product value
  *
  * @param ProductInterface   $product
  * @param AttributeInterface $attribute
  * @param mixed              $data
  * @param string             $locale
  * @param string             $scope
  */
 protected function setData(ProductInterface $product, AttributeInterface $attribute, $data, $locale, $scope)
 {
     $value = $product->getValue($attribute->getCode(), $locale, $scope);
     if (null === $value) {
         $value = $this->productBuilder->addProductValue($product, $attribute, $locale, $scope);
     }
     $value->setData($data);
 }
 function it_throws_an_exception_when_unit_families_are_not_the_same(AttributeInterface $description, AttributeInterface $name)
 {
     $description->getCode()->willReturn('description');
     $name->getCode()->willReturn('name');
     $description->getMetricFamily()->willReturn('Weight');
     $name->getMetricFamily()->willReturn('Distance');
     $this->shouldThrow(new \LogicException('Metric families are not the same for attributes: "description" and "name".'))->during('validateUnitFamilies', [$description, $name]);
 }
 function let(SerializerInterface $serializer, AttributeInterface $simpleAttribute)
 {
     $serializer->implement('Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface');
     $this->setSerializer($serializer);
     $simpleAttribute->isLocalizable()->willReturn(false);
     $simpleAttribute->isScopable()->willReturn(false);
     $simpleAttribute->getCode()->willReturn('simple');
 }
 /**
  * As boolean attribute does not support "null" value (only true/false),
  * there are some problems to make out what should really be added to the product (specially with optional attributes)
  * What we add in product:
  * | old value | new value | attribute is in family | should be added in product |
  * | null      | false     | yes                    | no                         |
  * | null      | false     | no                     | yes                        |
  *
  * This method should be removed when boolean attribute will be rework to support 3 states: true/false/null
  *
  * @deprecated will be removed in 1.7
  *
  * @param ProductInterface   $product    product to update
  * @param AttributeInterface $attribute  attribute
  * @param mixed              $data       new value
  *
  * @return bool
  */
 private function shouldBeSetInProduct(ProductInterface $product, AttributeInterface $attribute, $data)
 {
     $family = $product->getFamily();
     if (null !== $family && in_array($attribute->getCode(), $product->getFamily()->getAttributeCodes()) && false === $data) {
         return false;
     }
     return true;
 }
 function it_throws_an_exception_when_the_scope_is_not_provided(AttributeInterface $price)
 {
     $price->getId()->willReturn(42);
     $price->isLocalizable()->willReturn(false);
     $price->isScopable()->willReturn(true);
     $price->getCode()->willReturn('price');
     $this->shouldThrow('\\InvalidArgumentException')->duringPrepareCondition($price, 'alias', 'en_US', null);
 }
Пример #27
0
 function it_removes_attribute_indexes_when_a_localizable_and_scopable_attribute_is_removed($collection, AttributeInterface $title)
 {
     $title->getCode()->willReturn('title');
     $collection->getIndexInfo()->willReturn([["key" => ["_id" => 1]], ["key" => ["normalizedData.title-ecommerce-en_US" => 1]], ["key" => ["normalizedData.title-ecommerce-de_DE" => 1]], ["key" => ["normalizedData.title-mobile-de_DE" => 1]], ["key" => ["normalizedData.manufacturer_title" => 1]], ["key" => ["normalizedData.title_left-en_US" => 1]], ["key" => ["normalizedData.title_left-de_DE" => 1]]]);
     $collection->deleteIndex('normalizedData.title-ecommerce-en_US')->shouldBeCalled();
     $collection->deleteIndex('normalizedData.title-ecommerce-de_DE')->shouldBeCalled();
     $collection->deleteIndex('normalizedData.title-mobile-de_DE')->shouldBeCalled();
     $this->purgeIndexesFromAttribute($title);
 }
 function let(SerializerInterface $serializer, AttributeInterface $simpleAttribute, LocalizerRegistryInterface $localizerRegistry)
 {
     $this->beConstructedWith($localizerRegistry, 4);
     $serializer->implement('Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface');
     $this->setSerializer($serializer);
     $simpleAttribute->isLocalizable()->willReturn(false);
     $simpleAttribute->isScopable()->willReturn(false);
     $simpleAttribute->getCode()->willReturn('simple');
 }
 function it_throws_an_exception_if_value_is_not_a_valid_array(AttributeInterface $attribute)
 {
     $attribute->getId()->willReturn(1);
     $attribute->getCode()->willReturn('color');
     $value = 'string';
     $this->shouldThrow(InvalidArgumentException::arrayExpected('color', 'filter', 'reference_data', $value))->during('addAttributeFilter', [$attribute, '=', $value, null, null, ['field' => 'color']]);
     $value = ['foo'];
     $this->shouldThrow(InvalidArgumentException::numericExpected('color', 'filter', 'reference_data', 'string'))->during('addAttributeFilter', [$attribute, '=', $value, null, null, ['field' => 'color']]);
 }
 function it_sets_attribute_when_new_value_is_different_from_product_value($builder, AttributeInterface $attribute, ProductInterface $product, FamilyInterface $family, ProductValue $productValue)
 {
     $family->getAttributeCodes()->willReturn(['sku', 'is_color']);
     $product->getFamily()->willReturn($family);
     $attribute->getCode()->willReturn('is_color');
     $product->getValue('is_color', null, null)->willReturn(null);
     $builder->addProductValue($product, $attribute, null, null)->willReturn($productValue);
     $this->setAttributeData($product, $attribute, true, ['locale' => null, 'scope' => null]);
 }