Ejemplo n.º 1
0
 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);
 }
 /**
  * @param AttributeInterface $attribute
  *
  * @return array
  */
 protected function getChoiceUrlParams(AttributeInterface $attribute)
 {
     $referenceDataName = $attribute->getReferenceDataName();
     $referenceData = $this->registry->get($referenceDataName);
     if (null === $referenceData) {
         throw new \InvalidArgumentException(sprintf('Reference data "%s" does not exist', $referenceDataName));
     }
     return ['class' => $referenceData->getClass(), 'dataLocale' => $this->userContext->getCurrentLocaleCode(), 'collectionId' => $attribute->getId()];
 }
 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']]);
 }
 /**
  * Don't allow creating an identifier attribute if one already exists
  *
  * @param AttributeInterface $attribute
  * @param Constraint         $constraint
  */
 public function validate($attribute, Constraint $constraint)
 {
     if ($attribute->getAttributeType() === 'pim_catalog_identifier') {
         $identifier = $this->manager->getIdentifierAttribute();
         if ($identifier && $identifier->getId() !== $attribute->getId()) {
             $this->context->addViolationAt('attributeType', $constraint->message);
         }
     }
 }
 function it_adds_a_violation_if_attribute_identifier_already_exists($context, $attributeRepository, AttributeInterface $attribute, AttributeInterface $identifier, SingleIdentifierAttribute $constraint)
 {
     $attribute->getAttributeType()->willReturn('pim_catalog_identifier');
     $attribute->getId()->willReturn(2);
     $attributeRepository->getIdentifier()->willReturn($identifier);
     $identifier->getId()->willReturn(1);
     $context->addViolationAt('attributeType', $constraint->message)->shouldBeCalled();
     $this->validate($attribute, $constraint);
 }
 /**
  * Don't allow creating an identifier attribute if one already exists
  *
  * @param AttributeInterface $attribute
  * @param Constraint         $constraint
  */
 public function validate($attribute, Constraint $constraint)
 {
     if (AttributeTypes::IDENTIFIER === $attribute->getAttributeType()) {
         $identifier = $this->attributeRepository->getIdentifier();
         if ($identifier && $identifier->getId() !== $attribute->getId()) {
             $this->context->buildViolation($constraint->message)->atPath('attributeType')->addViolation();
         }
     }
 }
 function it_provides_available_axis_as_a_sorted_choice($registry, AttributeRepositoryInterface $attRepository, AttributeInterface $attribute1, AttributeInterface $attribute2)
 {
     $attribute1->getId()->willReturn(1);
     $attribute1->getLabel()->willReturn('Foo');
     $attribute2->getId()->willReturn(2);
     $attribute2->getLabel()->willReturn('Bar');
     $registry->getRepository(self::ATTRIBUTE_CLASS)->willReturn($attRepository);
     $attRepository->findAllAxis()->willReturn([$attribute1, $attribute2]);
     $this->getAvailableAxisChoices()->shouldReturn([2 => 'Bar', 1 => 'Foo']);
 }
Ejemplo n.º 8
0
 function it_updates_a_family($attrRequiFactory, $channelRepository, FamilyTranslation $translation, FamilyInterface $family, AttributeRepositoryInterface $attributeRepository, AttributeInterface $skuAttribute, AttributeInterface $nameAttribute, AttributeInterface $descAttribute, AttributeInterface $priceAttribute, AttributeRequirementInterface $skuMobileRqrmt, AttributeRequirementInterface $nameMobileRqrmt, AttributeRequirementInterface $skuPrintRqrmt, AttributeRequirementInterface $namePrintRqrmt, AttributeRequirementInterface $descPrintRqrmt, ChannelInterface $mobileChannel, ChannelInterface $printChannel)
 {
     $values = ['code' => 'mycode', 'attributes' => ['sku', 'name', 'description', 'price'], 'attribute_as_label' => 'name', 'requirements' => ['mobile' => ['sku', 'name'], 'print' => ['name', 'description']], 'labels' => ['fr_FR' => 'Moniteurs', 'en_US' => 'PC Monitors']];
     $family->getAttributeRequirements()->willReturn([$skuMobileRqrmt, $skuPrintRqrmt]);
     $family->getAttributes()->willReturn([$skuAttribute, $nameAttribute, $descAttribute, $priceAttribute]);
     $family->removeAttribute($nameAttribute)->shouldBeCalled();
     $family->removeAttribute($priceAttribute)->shouldBeCalled();
     $family->removeAttribute($descAttribute)->shouldBeCalled();
     $family->getId()->willReturn(42);
     $skuAttribute->getId()->willReturn(1);
     $nameAttribute->getId()->willReturn(2);
     $descAttribute->getId()->willReturn(3);
     $priceAttribute->getId()->willReturn(4);
     $skuMobileRqrmt->getAttribute()->willReturn($skuAttribute);
     $skuMobileRqrmt->getChannelCode()->willReturn('mobile');
     $skuPrintRqrmt->getAttribute()->willReturn($skuAttribute);
     $skuPrintRqrmt->getChannelCode()->willReturn('print');
     $attributeRepository->findOneByIdentifier('sku')->willReturn($skuAttribute);
     $attributeRepository->findOneByIdentifier('name')->willReturn($nameAttribute);
     $attributeRepository->findOneByIdentifier('description')->willReturn($descAttribute);
     $attributeRepository->findOneByIdentifier('price')->willReturn($priceAttribute);
     $attributeRepository->getIdentifier()->willReturn($skuAttribute);
     $skuAttribute->getAttributeType()->willReturn('pim_catalog_identifier');
     $nameAttribute->getAttributeType()->willReturn('pim_catalog_text');
     $descAttribute->getAttributeType()->willReturn('pim_catalog_textarea');
     $priceAttribute->getAttributeType()->willReturn('pim_catalog_price_collection');
     $channelRepository->getChannelCodes()->willReturn(['mobile', 'print']);
     $channelRepository->findOneByIdentifier('mobile')->willReturn($mobileChannel);
     $channelRepository->findOneByIdentifier('print')->willReturn($printChannel);
     $attrRequiFactory->createAttributeRequirement($nameAttribute, $mobileChannel, true)->willReturn($nameMobileRqrmt);
     $attrRequiFactory->createAttributeRequirement($nameAttribute, $printChannel, true)->willReturn($namePrintRqrmt);
     $attrRequiFactory->createAttributeRequirement($descAttribute, $printChannel, true)->willReturn($descPrintRqrmt);
     $nameMobileRqrmt->getAttribute()->willReturn($nameAttribute);
     $namePrintRqrmt->getAttribute()->willReturn($nameAttribute);
     $descPrintRqrmt->getAttribute()->willReturn($descAttribute);
     $family->setAttributeRequirements([$skuMobileRqrmt, $skuPrintRqrmt, $nameMobileRqrmt, $namePrintRqrmt, $descPrintRqrmt])->shouldBeCalled();
     $family->setCode('mycode')->shouldBeCalled();
     $family->addAttribute($skuAttribute)->shouldBeCalled();
     $family->addAttribute($nameAttribute)->shouldBeCalled();
     $family->addAttribute($skuAttribute)->shouldBeCalled();
     $family->addAttribute($skuAttribute)->shouldBeCalled();
     $family->setLocale('en_US')->shouldBeCalled();
     $family->setLocale('fr_FR')->shouldBeCalled();
     $family->getTranslation()->willReturn($translation);
     $translation->setLabel('label en us');
     $translation->setLabel('label fr fr');
     $family->addAttribute($skuAttribute)->shouldBeCalled();
     $family->addAttribute($nameAttribute)->shouldBeCalled();
     $family->addAttribute($descAttribute)->shouldBeCalled();
     $family->addAttribute($priceAttribute)->shouldBeCalled();
     $family->setAttributeAsLabel($nameAttribute)->shouldBeCalled();
     $this->update($family, $values, []);
 }
 function let(QueryBuilder $qb, AttributeValidatorHelper $attrValidatorHelper, Expr $expr, AttributeInterface $image)
 {
     $this->beConstructedWith($attrValidatorHelper, ['pim_catalog_image', 'pim_catalog_file'], ['STARTS WITH', 'ENDS WITH', 'CONTAINS', 'DOES NOT CONTAIN', '=', 'EMPTY']);
     $this->setQueryBuilder($qb);
     $qb->getRootAlias()->willReturn('p');
     $qb->expr()->willReturn($expr);
     $image->getId()->willReturn(1);
     $image->getCode()->willReturn('picture');
     $image->isLocalizable()->willReturn(false);
     $image->isScopable()->willReturn(false);
     $image->getBackendType()->willReturn('media');
 }
 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']);
 }
 function it_throws_an_exception_if_no_groups_found($attributeGroupRepository, AttributeInterface $attribute, AttributeTranslation $translation)
 {
     $attribute->getId()->willReturn(null);
     $attribute->getAttributeType()->willReturn('pim_reference_data_simpleselect');
     $data = ['labels' => ['en_US' => 'Test1', 'fr_FR' => 'Test2'], 'group' => 'marketing', 'attributeType' => 'pim_catalog_text'];
     $attribute->setLocale('en_US')->shouldBeCalled();
     $attribute->setLocale('fr_FR')->shouldBeCalled();
     $attribute->getTranslation()->willReturn($translation);
     $translation->setLabel('Test1')->shouldBeCalled();
     $translation->setLabel('Test2')->shouldBeCalled();
     $attributeGroupRepository->findOneByIdentifier('marketing')->willReturn(null);
     $this->shouldThrow(new \InvalidArgumentException('AttributeGroup "marketing" does not exist'))->during('update', [$attribute, $data]);
 }
 function it_adds_a_sorter_to_the_query($qb, AttributeInterface $metric)
 {
     $metric->getId()->willReturn(42);
     $metric->getCode()->willReturn('metric_code');
     $metric->getBackendType()->willReturn('metric');
     $metric->isLocalizable()->willReturn(false);
     $metric->isScopable()->willReturn(false);
     $condition = "sorterVmetric_code.attribute = 42";
     $qb->getRootAlias()->willReturn('r');
     $qb->leftJoin('r.values', 'sorterVmetric_code', 'WITH', $condition)->shouldBeCalled();
     $qb->leftJoin('sorterVmetric_code.metric', 'sorterMmetric_code')->shouldBeCalled();
     $qb->addOrderBy('sorterMmetric_code.baseData', 'DESC')->shouldBeCalled();
     $qb->addOrderBy('r.id')->shouldBeCalled();
     $this->addAttributeSorter($metric, 'DESC');
 }
 function it_adds_an_equal_filter_on_an_attribute_in_the_query($qb, $attrValidatorHelper, AttributeInterface $attribute, Expr $expr)
 {
     $attribute->getBackendType()->willReturn('backend_type');
     $attribute->getCode()->willReturn('code');
     $attribute->getId()->willReturn(42);
     $attribute->isLocalizable()->willReturn(false);
     $attribute->isScopable()->willReturn(false);
     $attrValidatorHelper->validateLocale($attribute, Argument::any())->shouldBeCalled();
     $attrValidatorHelper->validateScope($attribute, Argument::any())->shouldBeCalled();
     $qb->expr()->willReturn($expr);
     $qb->getRootAlias()->willReturn('p');
     $expr->eq(Argument::any(), true)->willReturn('filtercode.backend_type = true');
     $expr->literal(true)->willReturn(true);
     $qb->innerJoin('p.values', Argument::any(), 'WITH', Argument::any())->shouldBeCalled();
     $this->addAttributeFilter($attribute, '=', true);
 }
Ejemplo n.º 14
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;
 }
 function it_adds_a_sorter_to_the_query($qb, AttributeInterface $attribute, Expr $expr)
 {
     $attribute->getId()->willReturn('42');
     $attribute->getCode()->willReturn('entity_code');
     $attribute->isLocalizable()->willReturn(false);
     $attribute->isScopable()->willReturn(false);
     $attribute->getBackendType()->willReturn('entity');
     $qb->getRootAlias()->willReturn('r');
     $qb->expr()->willReturn($expr);
     $qb->leftJoin('r.values', 'sorterVentity_code', 'WITH', 'sorterVentity_code.attribute = 42')->shouldBeCalled();
     $qb->leftJoin('sorterVentity_code.entity', 'sorterOentity_code', 'WITH', 'sorterOentity_code.attribute = 42')->shouldBeCalled();
     $expr->literal('en_US')->shouldBeCalled()->willReturn('en_US');
     $qb->leftJoin('sorterOentity_code.optionValues', 'sorterOVentity_code', 'WITH', 'sorterOVentity_code.locale = en_US')->shouldBeCalled();
     $qb->addOrderBy('sorterOentity_code.code', 'DESC')->shouldBeCalled();
     $qb->addOrderBy('sorterOVentity_code.value', 'DESC')->shouldBeCalled();
     $qb->addOrderBy('r.id')->shouldBeCalled();
     $this->addAttributeSorter($attribute, 'DESC', 'en_US');
 }
Ejemplo n.º 16
0
 function it_adds_an_attribute_sorter_to_the_query($qb, AttributeInterface $sku)
 {
     $sku->getId()->willReturn(42);
     $sku->getCode()->willReturn('sku');
     $sku->getBackendType()->willReturn('varchar');
     $sku->isLocalizable()->willReturn(false);
     $sku->isScopable()->willReturn(false);
     $qb->expr()->willReturn(new Expr());
     $qb->getRootAlias()->willReturn('p');
     $qb->getDQLPart('join')->willReturn([]);
     $qb->resetDQLPart('join')->shouldBeCalled();
     $condition = "sorterVsku.attribute = 42";
     $qb->leftJoin('p.values', 'sorterVsku', 'WITH', $condition)->shouldBeCalled();
     $qb->addOrderBy('sorterVsku.varchar', 'DESC')->shouldBeCalled();
     $qb->getRootAlias()->willReturn('p');
     $qb->addOrderBy("p.id")->shouldBeCalled();
     $this->addAttributeSorter($sku, 'DESC');
 }
Ejemplo n.º 17
0
 /**
  * @param FamilyInterface    $family
  * @param AttributeInterface $attribute
  * @param string             $channelCode
  *
  * @return AttributeRequirementInterface
  */
 protected function createAttributeRequirement(FamilyInterface $family, AttributeInterface $attribute, $channelCode)
 {
     $channel = $this->channelRepository->findOneByIdentifier($channelCode);
     if (null === $channel) {
         throw new \InvalidArgumentException(sprintf('Channel with "%s" code does not exist', $channelCode));
     }
     $requirement = $this->requirementRepo->findOneBy(['attribute' => $attribute->getId(), 'channel' => $channel->getId(), 'family' => $family->getId()]);
     if (null === $requirement) {
         $requirement = $this->attrRequiFactory->createAttributeRequirement($attribute, $channel, true);
     }
     return $requirement;
 }
 /**
  * Hide the group field with a default value = "Other"
  *
  * @param FormInterface      $form Form
  * @param AttributeInterface $data
  */
 protected function hideGroupElement(FormInterface $form, AttributeInterface $data)
 {
     if (null !== $data->getId()) {
         $group = $data->getGroup();
     } else {
         $group = $this->groupRepository->findDefaultAttributeGroup();
     }
     $formField = $form->get('group');
     $options = $formField->getConfig()->getOptions();
     $newOptions = ['data' => $group, 'class' => $options['class'], 'choices' => [$group], 'required' => true, 'multiple' => false, 'read_only' => true, 'attr' => ['class' => 'hide']];
     $form->add('group', 'entity', $newOptions);
 }
 function it_adds_an_empty_filter_in_the_query($currencyManager, QueryBuilder $queryBuilder, AttributeInterface $price, Expr $expr, Comparison $comparison)
 {
     $price->getId()->willReturn(42);
     $price->getCode()->willReturn('price');
     $price->getBackendType()->willReturn('prices');
     $price->isLocalizable()->willReturn(false);
     $price->isScopable()->willReturn(false);
     $queryBuilder->expr()->willReturn(new Expr());
     $queryBuilder->getRootAlias()->willReturn('p');
     $value = ['data' => null, 'currency' => 'EUR'];
     $currencyManager->getActiveCodes()->willReturn(['EUR', 'USD']);
     $queryBuilder->leftJoin('p.values', Argument::any(), 'WITH', Argument::any())->shouldBeCalled();
     $queryBuilder->leftJoin(Argument::any(), Argument::any())->shouldBeCalled();
     $queryBuilder->expr()->willReturn($expr);
     $expr->literal('EUR')->willReturn('EUR');
     $expr->eq(Argument::any(), 'EUR')->willReturn($comparison);
     $expr->isNull(Argument::any())->willReturn('filterPprice.data IS NULL');
     $expr->isNull(Argument::any())->willReturn('filterPprice.id IS NULL');
     $expr->orX(Argument::any(), Argument::any())->shouldBeCalled();
     $queryBuilder->andWhere(null)->shouldBeCalled();
     $this->addAttributeFilter($price, 'EMPTY', $value);
 }
 /**
  * {@inheritdoc}
  */
 public function findAllWithAttribute(AttributeInterface $attribute)
 {
     return $this->createQueryBuilder('p')->field('values.attribute')->equals((int) $attribute->getId())->getQuery()->execute()->toArray();
 }
 /**
  * Define custom properties used in attribute form
  *
  * Each property must be an array with a 'name' key that matches the name of the property
  * Optional 'fieldType', 'data' and 'options' keys can be provided for field customization
  *
  * @param AttributeInterface $attribute Attribute entity
  *
  * @return array:array:multitype $properties an array of custom properties
  */
 protected function defineCustomAttributeProperties(AttributeInterface $attribute)
 {
     return ['localizable' => ['name' => 'localizable', 'fieldType' => 'switch', 'options' => ['disabled' => (bool) $attribute->getId(), 'read_only' => (bool) $attribute->getId()]], 'availableLocales' => ['name' => 'availableLocales', 'fieldType' => 'pim_enrich_available_locales'], 'scopable' => ['name' => 'scopable', 'fieldType' => 'pim_enrich_scopable', 'options' => ['disabled' => (bool) $attribute->getId(), 'read_only' => (bool) $attribute->getId()]], 'unique' => ['name' => 'unique', 'fieldType' => 'switch', 'options' => ['disabled' => true, 'read_only' => true]]];
 }
 function it_generates_a_query_to_update_product_families(AttributeInterface $price)
 {
     $price->getId()->willReturn(12);
     $this->generateQuery($price, 'attributeAsLabel', 'sku', 'name')->shouldReturn([[['family' => 12], ['$set' => ['normalizedData.family.attributeAsLabel' => 'name']], ['multiple' => true]]]);
 }
Ejemplo n.º 23
0
 /**
  * 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;
 }
Ejemplo n.º 24
0
 /**
  * @param AttributeInterface $attribute
  *
  * @return array
  */
 protected function getChoiceUrlParams(AttributeInterface $attribute)
 {
     return ['class' => $this->optionRepoClass, 'dataLocale' => $this->userContext->getCurrentLocaleCode(), 'collectionId' => $attribute->getId()];
 }