/**
  * Don't allow creating an identifier attribute if one already exists
  *
  * @param AbstractAttribute $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_provides_available_axis_as_a_sorted_choice($registry, AttributeRepository $attRepository, AbstractAttribute $attribute1, AbstractAttribute $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']);
 }
Пример #3
0
 /**
  * Prepare join to attribute condition with current locale and scope criterias
  *
  * @param AbstractAttribute $attribute the attribute
  * @param string            $joinAlias the value join alias
  *
  * @return string
  */
 public function prepareCondition(AbstractAttribute $attribute, $joinAlias)
 {
     $condition = $joinAlias . '.attribute = ' . $attribute->getId();
     if ($attribute->isLocalizable()) {
         $condition .= ' AND ' . $joinAlias . '.locale = ' . $this->qb->expr()->literal($this->context->getLocaleCode());
     }
     if ($attribute->isScopable()) {
         $condition .= ' AND ' . $joinAlias . '.scope = ' . $this->qb->expr()->literal($this->context->getScopeCode());
     }
     return $condition;
 }
 function it_adds_a_like_filter_in_the_query(QueryBuilder $queryBuilder, AbstractAttribute $sku)
 {
     $sku->getId()->willReturn(42);
     $sku->getCode()->willReturn('sku');
     $sku->getBackendType()->willReturn('varchar');
     $sku->isLocalizable()->willReturn(false);
     $sku->isScopable()->willReturn(false);
     $queryBuilder->expr()->willReturn(new Expr());
     $queryBuilder->getRootAlias()->willReturn('p');
     $condition = "filtersku1.attribute = 42 AND filtersku1.varchar LIKE 'My Sku'";
     $queryBuilder->innerJoin('p.values', 'filtersku1', 'WITH', $condition)->shouldBeCalled();
     $this->addAttributeFilter($sku, 'LIKE', 'My Sku');
 }
 function it_normalizes_a_product_value_into_mongodb_document($mongoFactory, $serializer, AbstractProductValue $value, AbstractAttribute $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_adds_a_sorter_in_the_query(QueryBuilder $queryBuilder, AbstractAttribute $sku)
 {
     $sku->getId()->willReturn(42);
     $sku->getCode()->willReturn('sku');
     $sku->getBackendType()->willReturn('varchar');
     $sku->isLocalizable()->willReturn(false);
     $sku->isScopable()->willReturn(false);
     $queryBuilder->expr()->willReturn(new Expr());
     $queryBuilder->getRootAlias()->willReturn('p');
     $queryBuilder->getDQLPart('join')->willReturn([]);
     $queryBuilder->resetDQLPart('join')->shouldBeCalled();
     $condition = "sorterVsku1.attribute = 42";
     $queryBuilder->leftJoin('p.values', 'sorterVsku1', 'WITH', $condition)->shouldBeCalled();
     $queryBuilder->addOrderBy('sorterVsku1.varchar', 'DESC')->shouldBeCalled();
     $this->addAttributeSorter($sku, 'DESC');
 }
 function it_generates_a_query_to_update_product_families(AbstractAttribute $price)
 {
     $price->getId()->willReturn(12);
     $this->generateQuery($price, 'attributeAsLabel', 'sku', 'name')->shouldReturn([[['family' => 12], ['$set' => ['normalizedData.family.attributeAsLabel' => 'name']], ['multiple' => true]]]);
 }
 /**
  * Prepare attribute view
  *
  * @param AbstractAttribute     $attribute
  * @param ProductValueInterface $value
  * @param FormView              $view
  *
  * @return array
  */
 protected function prepareAttributeView(AbstractAttribute $attribute, ProductValueInterface $value, FormView $view)
 {
     $attributeView = array('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()), array($value->getScope() => $view));
         ksort($attributeView['values']);
     } else {
         $attributeView['value'] = $view;
     }
     $classes = $this->getAttributeClasses($attribute);
     if (!empty($classes)) {
         $attributeView['classes'] = $classes;
     }
     return $attributeView;
 }
 /**
  * @param AbstractAttribute $attribute
  *
  * @return string[]
  */
 public function findAllIdsForAttribute(AbstractAttribute $attribute)
 {
     $qb = $this->createQueryBuilder('p')->hydrate(false)->field('values.attribute')->equals((int) $attribute->getId())->select('_id');
     $results = $qb->getQuery()->execute()->toArray();
     return array_keys($results);
 }
 /**
  * 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 AbstractAttribute $attribute Attribute entity
  *
  * @return array:array:multitype $properties an array of custom properties
  */
 protected function defineCustomAttributeProperties(AbstractAttribute $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]]];
 }