public function it_does_not_filter_a_product_value_if_it_is_in_channels_options(ProductValueInterface $price, AttributeInterface $priceAttribute) { $price->getAttribute()->willReturn($priceAttribute); $priceAttribute->isScopable()->willReturn(false); $price->getScope()->willReturn('fr_FR'); $this->filterObject($price, 'pim:product_value:view', ['channels' => ['en_US', 'fr_FR']])->shouldReturn(false); }
function it_adds_missing_product_values_from_family_on_new_product($valuesResolver, FamilyInterface $family, ProductInterface $product, AttributeInterface $sku, AttributeInterface $name, AttributeInterface $desc, ProductValueInterface $skuValue) { $sku->getCode()->willReturn('sku'); $sku->getAttributeType()->willReturn('pim_catalog_identifier'); $sku->isLocalizable()->willReturn(false); $sku->isScopable()->willReturn(false); $name->getCode()->willReturn('name'); $name->getAttributeType()->willReturn('pim_catalog_text'); $name->isLocalizable()->willReturn(true); $name->isScopable()->willReturn(false); $desc->getCode()->willReturn('description'); $desc->getAttributeType()->willReturn('pim_catalog_text'); $desc->isLocalizable()->willReturn(true); $desc->isScopable()->willReturn(true); // get expected attributes $product->getAttributes()->willReturn([$sku]); $family->getAttributes()->willReturn([$sku, $name, $desc]); $product->getFamily()->willReturn($family); // get eligible values $valuesResolver->resolveEligibleValues(['sku' => $sku, 'name' => $name, 'description' => $desc])->willReturn([['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']]); // get existing values $skuValue->getAttribute()->willReturn($sku); $skuValue->getLocale()->willReturn(null); $skuValue->getScope()->willReturn(null); $product->getValues()->willReturn([$skuValue]); // add 6 new values : 4 desc (locales x scopes) + 2 name (locales $product->addValue(Argument::any())->shouldBeCalledTimes(6); $this->addMissingProductValues($product); }
function it_generates_the_media_filename_prefix(ProductValueInterface $fileValue, AttributeInterface $file) { $fileValue->getAttribute()->willReturn($file); $file->getCode()->willReturn('file'); $fileValue->getLocale()->willReturn('de_DE'); $fileValue->getScope()->willReturn('print'); $prefix = $this->generateFilenamePrefix($fileValue); $prefix->shouldMatch('/-file-de_DE-print-/'); }
function it_adds_violations_if_value_is_scopable_and_its_scope_does_not_exist($context, $channelRepository, ProductValueInterface $value, AttributeInterface $scopableAttribute, ScopableValue $constraint, ConstraintViolationBuilderInterface $violation) { $value->getAttribute()->willReturn($scopableAttribute); $scopableAttribute->isScopable()->willReturn(true); $value->getScope()->willReturn('inexistingChannel'); $scopableAttribute->getCode()->willReturn('attributeCode'); $channelRepository->findOneByIdentifier('inexistingChannel')->willReturn(null); $violationData = ['%attribute%' => 'attributeCode', '%channel%' => 'inexistingChannel']; $context->buildViolation($constraint->inexistingScopeMessage, $violationData)->shouldBeCalled()->willReturn($violation); $this->validate($value, $constraint); }
function it_generates_the_path_when_the_value_is_localisable_and_scopable(ProductValueInterface $value, FileInfoInterface $fileInfo, AttributeInterface $attribute) { $value->getMedia()->willReturn($fileInfo); $value->getLocale()->willReturn('fr_FR'); $value->getScope()->willReturn('ecommerce'); $value->getAttribute()->willReturn($attribute); $fileInfo->getOriginalFilename()->willReturn('file.jpg'); $attribute->getCode()->willReturn('picture'); $attribute->isLocalizable()->willReturn(true); $attribute->isScopable()->willReturn(true); $this->generate($value, ['identifier' => 'sku001'])->shouldReturn('files/sku001/picture/fr_FR/ecommerce/file.jpg'); }
/** * Get the internal key that is used to index * a product value in a collection of values * * @param ProductValueInterface $value * * @return string */ public static function getKey(ProductValueInterface $value) { $attribute = $value->getAttribute(); $key = $attribute->getCode(); if ($attribute->isLocalizable()) { $key .= '_' . $value->getLocale(); } if ($attribute->isScopable()) { $key .= '_' . $value->getScope(); } return $key; }
function it_normalizes_a_product_value_into_mongodb_document($mongoFactory, $serializer, ProductValueInterface $value, AttributeInterface $attribute, \MongoDBRef $mongoDBRef, \MongoId $mongoId) { $context = ['_id' => $mongoId, 'collection_name' => 'product']; $mongoFactory->createMongoId()->willReturn($mongoId); $mongoFactory->createMongoDBRef('product', $mongoId)->willReturn($mongoDBRef); $attribute->getId()->willReturn(123); $attribute->getBackendType()->willReturn('text'); $value->getAttribute()->willReturn($attribute); $value->getData()->willReturn('my description'); $value->getLocale()->willReturn(null); $value->getScope()->willReturn(null); $this->normalize($value, 'mongodb_document', $context)->shouldReturn(['_id' => $mongoId, 'attribute' => 123, 'entity' => $mongoDBRef, 'text' => 'my description']); }
/** * {@inheritdoc} */ public function hasValue(ProductValueInterface $value) { $attributeCode = $value->getAttribute()->getCode(); if (!isset($this->valuesData[$attributeCode])) { return false; } $valuesData = $this->valuesData[$attributeCode]; foreach ($valuesData as $valueData) { if ($valueData['locale'] === $value->getLocale() && $valueData['scope'] === $value->getScope()) { return true; } } return false; }
function it_does_not_add_value_if_already_present(ProductValueInterface $notPresent, ProductInterface $product, AttributeInterface $attribute, ProductValueInterface $present, ProductInterface $anotherProduct) { $notPresent->getProduct()->willReturn($product); $notPresent->getData()->willReturn('new-data'); $notPresent->getAttribute()->willReturn($attribute); $notPresent->getLocale()->willReturn(null); $notPresent->getScope()->willReturn(null); $attribute->getCode()->willReturn('sku'); $this->addValue($notPresent)->shouldReturn(true); $present->getProduct()->willReturn($anotherProduct); $present->getData()->willReturn('new-data'); $present->getAttribute()->willReturn($attribute); $present->getLocale()->willReturn(null); $present->getScope()->willReturn(null); $attribute->getCode()->willReturn('sku'); $this->addValue($present)->shouldReturn(false); }
function it_adds_missing_product_values_from_family_on_new_product(FamilyInterface $family, ProductInterface $product, AttributeInterface $sku, AttributeInterface $name, AttributeInterface $desc, $localeRepository, LocaleInterface $fr, LocaleInterface $en, $channelRepository, ChannelInterface $ecom, ChannelInterface $print, ProductValueInterface $skuValue) { // get expected attributes $product->getAttributes()->willReturn([$sku]); $product->getFamily()->willReturn($family); $family->getAttributes()->willReturn([$sku, $name, $desc]); // get expected values $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('desc'); $desc->getAttributeType()->willReturn('pim_catalog_text'); $desc->isLocalizable()->willReturn(true); $desc->isScopable()->willReturn(true); $desc->isLocaleSpecific()->willReturn(false); $fr->getCode()->willReturn('fr_FR'); $en->getCode()->willReturn('fr_FR'); $localeRepository->getActivatedLocales()->willReturn([$fr, $en]); $ecom->getCode()->willReturn('ecom'); $ecom->getLocales()->willReturn([$en, $fr]); $print->getCode()->willReturn('print'); $print->getLocales()->willReturn([$en, $fr]); $channelRepository->findAll()->willReturn([$ecom, $print]); // get existing values $skuValue->getAttribute()->willReturn($sku); $skuValue->getLocale()->willReturn(null); $skuValue->getScope()->willReturn(null); $product->getValues()->willReturn([$skuValue]); // add 6 new values : 4 desc (locales x scopes) + 2 name (locales $product->addValue(Argument::any())->shouldBeCalledTimes(6); $this->addMissingProductValues($product); }
/** * @param ProductInterface $product * @param ProductValueInterface $value * * @return string */ public function generateFilenamePrefix(ProductInterface $product, ProductValueInterface $value) { return sprintf('%s-%s-%s-%s-%s-%s', $product->getId(), Urlizer::urlize($product->getIdentifier(), '_'), $value->getAttribute()->getCode(), $value->getLocale(), $value->getScope(), time()); }
/** * @param ProductValueInterface $value * * @return string */ public function generateFilenamePrefix(ProductValueInterface $value) { return sprintf('%s-%s-%s-%s-%s', uniqid(), $value->getAttribute()->getCode(), $value->getLocale(), $value->getScope(), time()); }
/** * Normalize the field name for value * * @param ProductValueInterface $value * * @return string */ public static function getNormalizedValueFieldFromValue(ProductValueInterface $value) { return self::getNormalizedValueField($value->getAttribute(), $value->getLocale(), $value->getScope()); }
function it_generates_filename_prefix(ProductInterface $product, ProductValueInterface $value, ProductValueInterface $identifier, AttributeInterface $attribute) { $identifier->getData()->shouldBeCalled(); $product->getIdentifier()->willReturn($identifier); $value->getAttribute()->willReturn($attribute); $attribute->getCode()->shouldBeCalled(); $value->getLocale()->shouldBeCalled(); $value->getScope()->shouldBeCalled(); $this->generateFilenamePrefix($product, $value); }
/** * @param ProductValueInterface $productValue * * @return string */ protected function getUniqueValueCode(ProductValueInterface $productValue) { $attributeCode = $productValue->getAttribute()->getCode(); $uniqueValueCode = $attributeCode; $uniqueValueCode .= null !== $productValue->getLocale() ? $productValue->getLocale() : ''; $uniqueValueCode .= null !== $productValue->getScope() ? $productValue->getScope() : ''; return $uniqueValueCode; }
/** * Is scopable and is the scope corresponding ? * * @param ProductValueInterface $value * @param string $scopeCode * * @return boolean */ protected function isScopeNormalizable(ProductValueInterface $value, $scopeCode) { return $scopeCode == null || !$value->getAttribute()->isScopable() || $value->getAttribute()->isScopable() && $value->getScope() === $scopeCode; }
/** * Normalize the field name for values * * @param ProductValueInterface $value * * @return string */ protected function getFieldValue($value) { // TODO : should be extracted $suffix = ''; if ($value->getAttribute()->isLocalizable()) { $suffix = sprintf('-%s', $value->getLocale()); } if ($value->getAttribute()->isScopable()) { $suffix .= sprintf('-%s', $value->getScope()); } return $value->getAttribute()->getCode() . $suffix; }
/** * Prepare attribute view * * @param AttributeInterface $attribute * @param ProductValueInterface $value * @param FormView $view * * @return array */ protected function prepareAttributeView(AttributeInterface $attribute, ProductValueInterface $value, FormView $view) { $attributeView = ['id' => $attribute->getId(), 'isRemovable' => $value->isRemovable(), 'code' => $attribute->getCode(), 'label' => $attribute->getLabel(), 'sortOrder' => $attribute->getSortOrder(), 'allowValueCreation' => in_array($attribute->getAttributeType(), $this->choiceAttributeTypes), 'locale' => $value->getLocale()]; if ($attribute->isScopable()) { $attributeView['values'] = array_merge($this->getAttributeValues($attribute, $value->getLocale()), [$value->getScope() => $view]); ksort($attributeView['values']); } else { $attributeView['value'] = $view; } $classes = $this->getAttributeClasses($attribute); if (!empty($classes)) { $attributeView['classes'] = $classes; } return $attributeView; }
/** * Get product value * * @param ProductInterface $product * @param ProductValueInterface $value * * @return ProductValueInterface */ protected function getProductValue(ProductInterface $product, ProductValueInterface $value) { return $product->getValue($value->getAttribute()->getCode(), $value->getAttribute()->isLocalizable() ? $this->getLocale()->getCode() : null, $value->getAttribute()->isScopable() ? $value->getScope() : null); }