Пример #1
0
 /**
  * Normalize the attributes
  *
  * @param FamilyInterface $family
  *
  * @return array
  */
 protected function normalizeAttributes(FamilyInterface $family)
 {
     $filteredAttributes = $this->collectionFilter ? $this->collectionFilter->filterCollection($family->getAttributes(), 'pim.internal_api.attribute.view') : $family->getAttributes();
     $normalizedAttributes = [];
     foreach ($filteredAttributes as $attribute) {
         $normalizedAttributes[] = $attribute->getCode();
     }
     return $normalizedAttributes;
 }
 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);
 }
 /**
  * Normalize the attributes
  *
  * @param FamilyInterface $family
  *
  * @return array
  */
 protected function normalizeAttributes(FamilyInterface $family)
 {
     $attributes = array();
     foreach ($family->getAttributes() as $attribute) {
         $attributes[] = $attribute->getCode();
     }
     return $attributes;
 }
 public function let(AttributeRequirementFactory $requirementFactory, LifecycleEventArgs $eventArgs, ChannelInterface $channel, EntityManagerInterface $entityManager, EntityRepository $repository, FamilyInterface $family)
 {
     $this->beConstructedWith($requirementFactory);
     $eventArgs->getEntity()->willReturn($channel);
     $eventArgs->getEntityManager()->willReturn($entityManager);
     $entityManager->getRepository(Argument::exact('PimCatalogBundle:Family'))->willReturn($repository);
     $repository->findAll()->willReturn([$family]);
     $family->getAttributes()->willReturn([]);
 }
 /**
  * {@inheritdoc}
  */
 public function isAttributeRemovable(AttributeInterface $attribute)
 {
     if ('pim_catalog_identifier' === $attribute->getAttributeType()) {
         return false;
     }
     if (null !== $this->family && $this->family->getAttributes()->contains($attribute)) {
         return false;
     }
     foreach ($this->groups as $group) {
         if ($group->getType()->isVariant()) {
             if ($group->getAttributes()->contains($attribute)) {
                 return false;
             }
             $template = $group->getProductTemplate();
             if (null !== $template && $template->hasValueForAttribute($attribute)) {
                 return false;
             }
         }
     }
     return true;
 }
Пример #6
0
 function it_is_not_attribute_removable_with_family_containing_attribute(AttributeInterface $attribute, FamilyInterface $family, ArrayCollection $familyAttributes)
 {
     $familyAttributes->contains($attribute)->willReturn(true);
     $family->getId()->willReturn(42);
     $family->getAttributes()->willReturn($familyAttributes);
     $this->setFamily($family);
     $this->isAttributeRemovable($attribute)->shouldReturn(false);
 }
 public function it_throws_an_exception_if_attribute_does_not_exist($attributeRepository, FamilyInterface $family, AttributeInterface $priceAttribute)
 {
     $data = ['code' => 'mycode', 'attributes' => ['sku', 'name', 'description', 'price'], 'attribute_as_label' => 'name', 'requirements' => ['mobile' => ['sku', 'name'], 'print' => ['sku', 'name', 'description']], 'labels' => ['fr_FR' => 'Moniteurs', 'en_US' => 'PC Monitors']];
     $family->setCode('mycode')->shouldBeCalled();
     $family->getAttributes()->willReturn([$priceAttribute]);
     $family->removeAttribute($priceAttribute)->shouldBeCalled();
     $attributeRepository->findOneByIdentifier('sku')->willReturn(null);
     $this->shouldThrow(new \InvalidArgumentException(sprintf('Attribute with "%s" code does not exist', 'sku')))->during('update', [$family, $data]);
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function hasAttributeInFamily(AttributeInterface $attribute)
 {
     return null !== $this->family && $this->family->getAttributes()->contains($attribute);
 }
Пример #9
0
 /**
  * @param FamilyInterface $family
  * @param array           $data
  *
  * @throws \InvalidArgumentException
  */
 protected function addAttributes(FamilyInterface $family, array $data)
 {
     foreach ($family->getAttributes() as $attribute) {
         if (AttributeTypes::IDENTIFIER !== $attribute->getAttributeType()) {
             $family->removeAttribute($attribute);
         }
     }
     foreach ($data as $attributeCode) {
         if (null !== ($attribute = $this->attributeRepository->findOneByIdentifier($attributeCode))) {
             $family->addAttribute($attribute);
         } else {
             throw new \InvalidArgumentException(sprintf('Attribute with "%s" code does not exist', $attributeCode));
         }
     }
 }