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_copies_a_price_collection_value_to_a_product_value($builder, $attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValue $fromProductValue, ProductValue $toProductValue, ProductPriceInterface $price)
 {
     $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([$price]);
     $price->getCurrency()->willReturn('USD');
     $price->getData()->willReturn(123);
     $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);
     $builder->addPriceForCurrencyWithData($toProductValue, 'USD', 123)->shouldBeCalled();
     $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_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_denormalizes_data_into_reference_data($resolver, AttributeInterface $attribute, ReferenceDataInterface $battlecruiser, ReferenceDataRepository $referenceDataRepo)
 {
     $attribute->getReferenceDataName()->willReturn('starship');
     $resolver->resolve('starship')->willReturn($referenceDataRepo);
     $referenceDataRepo->findOneBy(['code' => 'battlecruiser'])->willReturn($battlecruiser);
     $this->denormalize('battlecruiser', 'pim_reference_data_simpleselect', 'json', ['attribute' => $attribute])->shouldReturn($battlecruiser);
 }
 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']]]]);
 }
 function it_allows_setting_option_to_null(ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value)
 {
     $attribute->getCode()->willReturn('choice');
     $product->getValue('choice', null, null)->shouldBeCalled()->willReturn($value);
     $value->setOption(null)->shouldBeCalled();
     $this->setValue([$product], $attribute, null);
 }
 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');
 }
 function it_supports_date_attributes(AttributeInterface $dateAtt, AttributeInterface $otherAtt)
 {
     $dateAtt->getAttributeType()->willReturn('pim_catalog_date');
     $this->supportsAttribute($dateAtt)->shouldReturn(true);
     $otherAtt->getAttributeType()->willReturn('pim_catalog_other');
     $this->supportsAttribute($otherAtt)->shouldReturn(false);
 }
 /**
  * Get empty value for specified attribute depending on its type
  *
  * @param AttributeInterface $attribute
  *
  * @return array|bool|string|null
  */
 protected function getEmptyValue(AttributeInterface $attribute)
 {
     switch ($attribute->getAttributeType()) {
         case 'pim_catalog_metric':
             $emptyValue = ['data' => null, 'unit' => $attribute->getDefaultMetricUnit()];
             break;
         case 'pim_catalog_multiselect':
         case 'pim_reference_data_multiselect':
             $emptyValue = [];
             break;
         case 'pim_catalog_text':
             $emptyValue = '';
             break;
         case 'pim_catalog_boolean':
             $emptyValue = false;
             break;
         case 'pim_catalog_price_collection':
             $emptyValue = [];
             break;
         default:
             $emptyValue = null;
             break;
     }
     return $emptyValue;
 }
 function it_copies_multi_select_value_to_a_product_value($builder, $attrValidatorHelper, AttributeInterface $fromAttribute, AttributeInterface $toAttribute, ProductInterface $product1, ProductInterface $product2, ProductInterface $product3, ProductInterface $product4, ProductValue $fromProductValue, ProductValue $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->getOptions()->willReturn([$attributeOption])->shouldBeCalled(3);
     $toProductValue->getOptions()->willReturn([$attributeOption]);
     $toProductValue->removeOption($attributeOption)->shouldBeCalled();
     $toProductValue->addOption($attributeOption)->shouldBeCalled();
     $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_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]]);
 }
 /**
  * {@inheritdoc}
  */
 protected function findEntity($class, array $data)
 {
     if (!$this->identifierAttribute) {
         throw new MissingIdentifierException();
     }
     return $this->productManager->getProductRepository()->findOneByIdentifier($data[$this->identifierAttribute->getCode()]);
 }
 function it_throws_exception_when_scope_is_not_provided_but_expected(ProductInterface $product, AttributeInterface $price)
 {
     $price->getCode()->willReturn('price');
     $price->isLocalizable()->willReturn(false);
     $price->isScopable()->willReturn(true);
     $this->shouldThrow(new \InvalidArgumentException('A scope must be provided to create a value for the scopable attribute price'))->duringAddProductValue($product, $price);
 }
Ejemplo n.º 14
0
 function it_does_not_support_other_attributes($identifier, $textarea, AttributeInterface $image)
 {
     $this->supportAttribute($identifier)->shouldReturn(false);
     $this->supportAttribute($textarea)->shouldReturn(false);
     $image->getAttributeType()->willReturn('pim_catalog_image');
     $this->supportAttribute($image)->shouldReturn(false);
 }
Ejemplo n.º 15
0
 /**
  * Sets the attribute
  *
  * @param AttributeInterface $attribute
  *
  * @throws ColumnLabelException
  */
 public function setAttribute(AttributeInterface $attribute = null)
 {
     $this->attribute = $attribute;
     if (null === $attribute) {
         $this->locale = null;
         $this->scope = null;
         $this->suffixes = $this->rawSuffixes;
         $this->propertyPath = lcfirst(Inflector::classify($this->name));
     } else {
         if (!in_array($attribute->getBackendType(), [AbstractAttributeType::BACKEND_TYPE_REF_DATA_OPTION, AbstractAttributeType::BACKEND_TYPE_REF_DATA_OPTIONS])) {
             $this->propertyPath = $attribute->getBackendType();
         } else {
             $this->propertyPath = $attribute->getReferenceDataName();
         }
         $suffixes = $this->rawSuffixes;
         if ($attribute->isLocalizable()) {
             if (count($suffixes)) {
                 $this->locale = array_shift($suffixes);
             } else {
                 throw new ColumnLabelException('The column "%column%" must contain a locale code', ['%column%' => $this->label]);
             }
         }
         if ($attribute->isScopable()) {
             if (count($suffixes)) {
                 $this->scope = array_shift($suffixes);
             } else {
                 throw new ColumnLabelException('The column "%column%" must contain a scope code', ['%column%' => $this->label]);
             }
         }
         $this->suffixes = $suffixes;
     }
 }
 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);
 }
Ejemplo n.º 17
0
 /**
  * Sets the attribute
  *
  * @param AttributeInterface $attribute
  *
  * @throws ColumnLabelException
  */
 public function setAttribute(AttributeInterface $attribute = null)
 {
     $this->attribute = $attribute;
     if (null === $attribute) {
         $this->locale = null;
         $this->scope = null;
         $this->suffixes = $this->rawSuffixes;
         $this->propertyPath = lcfirst(Inflector::classify($this->name));
     } else {
         $this->propertyPath = $attribute->getBackendType();
         $suffixes = $this->rawSuffixes;
         if ($attribute->isLocalizable()) {
             if (count($suffixes)) {
                 $this->locale = array_shift($suffixes);
             } else {
                 throw new ColumnLabelException('The column "%column%" must contain a locale code', array('%column%' => $this->label));
             }
         }
         if ($attribute->isScopable()) {
             if (count($suffixes)) {
                 $this->scope = array_shift($suffixes);
             } else {
                 throw new ColumnLabelException('The column "%column%" must contain a scope code', array('%column%' => $this->label));
             }
         }
         $this->suffixes = $suffixes;
     }
 }
 function it_adds_violation_when_date_min_is_not_valid($context, AttributeInterface $attribute, ValidDateRange $constraint)
 {
     $date = new \DateTime();
     $attribute->getDateMin()->willReturn('not_a_date');
     $attribute->getDateMax()->willReturn($date);
     $context->addViolationAt('dateMin', $constraint->invalidDateMessage)->shouldBeCalled();
     $this->validate($attribute, $constraint);
 }
Ejemplo n.º 19
0
 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' => []]]];
     $this->convert($fieldNameInfo, $value)->shouldReturn($expectedResult);
 }
Ejemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function guessConstraints(AttributeInterface $attribute)
 {
     $constraints = array();
     if ('email' === $attribute->getValidationRule()) {
         $constraints[] = new Assert\Email();
     }
     return $constraints;
 }
 function it_creates_and_sets_geolocation_to_product_value($productBuilder, ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $value)
 {
     $attribute->getCode()->shouldBeCalled()->willReturn('geolocation');
     $product->getValue('geolocation', 'FR', 'master')->shouldBeCalled()->willReturn(null);
     $productBuilder->addProductValue($product, $attribute, 'FR', 'master')->shouldBeCalled()->willReturn($value);
     $value->setData(Argument::type('CleverAge\\Bundle\\GeolocAttributeBundle\\Model\\Geolocation'))->shouldBeCalled();
     $this->setValue([$product], $attribute, ['latitude' => 12, 'longitude' => 12], 'FR', 'master');
 }
Ejemplo n.º 22
0
 /**
  * {@inheritdoc}
  */
 public function guessConstraints(AttributeInterface $attribute)
 {
     $constraints = [];
     if ($attribute->isUnique()) {
         $constraints[] = new UniqueValue();
     }
     return $constraints;
 }
Ejemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 public function guessConstraints(AttributeInterface $attribute)
 {
     $constraints = [];
     if ('regexp' === $attribute->getValidationRule() && ($pattern = $attribute->getValidationRegexp())) {
         $constraints[] = new Assert\Regex(['pattern' => $pattern]);
     }
     return $constraints;
 }
 /**
  * {@inheritdoc}
  */
 public function guessConstraints(AttributeInterface $attribute)
 {
     $constraints = array();
     if (!$attribute->isDecimalsAllowed()) {
         $constraints[] = new NotDecimal();
     }
     return $constraints;
 }
 /**
  * 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 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');
 }
 /**
  * Set option into the product value
  *
  * @param ProductInterface              $product
  * @param AttributeInterface            $attribute
  * @param AttributeOptionInterface|null $option
  * @param string|null                   $locale
  * @param string|null                   $scope
  */
 protected function setOption(ProductInterface $product, AttributeInterface $attribute, AttributeOptionInterface $option = null, $locale = null, $scope = null)
 {
     $value = $product->getValue($attribute->getCode(), $locale, $scope);
     if (null === $value) {
         $value = $this->productBuilder->addProductValue($product, $attribute, $locale, $scope);
     }
     $value->setOption($option);
 }
Ejemplo n.º 28
0
 /**
  * {@inheritdoc}
  */
 public function guessConstraints(AttributeInterface $attribute)
 {
     $constraints = [];
     if ('url' === $attribute->getValidationRule()) {
         $constraints[] = new Assert\Url();
     }
     return $constraints;
 }
 /**
  * {@inheritdoc}
  */
 public function guessConstraints(AttributeInterface $attribute)
 {
     $constraints = array();
     if ($attribute->isRequired()) {
         $constraints[] = new Assert\NotBlank();
     }
     return $constraints;
 }
 function it_denormalizes_data_into_metric(AttributeInterface $attribute, $factory, MetricInterface $metric)
 {
     $attribute->getMetricFamily()->willReturn('Frequency');
     $factory->createMetric('Frequency')->shouldBeCalled()->willReturn($metric);
     $metric->setData(3)->shouldBeCalled();
     $metric->setUnit('GIGAHERTZ')->shouldBeCalled();
     $this->denormalize(['data' => 3, 'unit' => 'GIGAHERTZ'], 'pim_catalog_metric', 'json', ['attribute' => $attribute])->shouldReturn($metric);
 }