/**
  * Test getter/setter for code property
  */
 public function testGetSetCode()
 {
     $this->assertEmpty($this->family->getCode());
     // Change value and assert new
     $newCode = 'test-code';
     $this->assertEntity($this->family->setCode($newCode));
     $this->assertEquals($newCode, $this->family->getCode());
 }
 /**
  * @param Family $family
  *
  * @return array
  */
 public function getAllSources(Family $family = null)
 {
     $sources = [];
     if ($this->isValid()) {
         $families = $this->familyManager->getFamilies();
         foreach ($families as $family) {
             $sources[] = ['id' => $family->getCode(), 'name' => $family->getCode()];
         }
     }
     return $sources;
 }
 /**
  * Register a new group mapping.
  *
  * @param AttributeGroup $pimGroup
  * @param Family         $pimFamily
  * @param integer        $magentoGroupId
  * @param string         $magentoUrl
  */
 public function registerGroupMapping(AttributeGroup $pimGroup, Family $pimFamily, $magentoGroupId, $magentoUrl)
 {
     $groupMapping = $this->getEntityRepository()->findOneBy(['pimGroupCode' => $pimGroup->getCode(), 'pimFamilyCode' => $pimFamily->getCode(), 'magentoUrl' => $magentoUrl]);
     $magentoGroupMapping = new $this->className();
     if ($groupMapping) {
         $magentoGroupMapping = $groupMapping;
     }
     $magentoGroupMapping->setPimGroupCode($pimGroup->getCode());
     $magentoGroupMapping->setPimFamilyCode($pimFamily->getCode());
     $magentoGroupMapping->setMagentoGroupId($magentoGroupId);
     $magentoGroupMapping->setMagentoUrl($magentoUrl);
     $this->objectManager->persist($magentoGroupMapping);
     $this->objectManager->flush();
 }
 public function let(ObjectManager $objectManager, EntityRepository $entityRepository, Family $family, AttributeGroup $group)
 {
     $this->beConstructedWith($objectManager, 'Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoAttributeMapping');
     $objectManager->getRepository('Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoAttributeMapping')->willReturn($entityRepository);
     $group->getCode()->willReturn(12);
     $family->getCode()->willReturn(5);
 }
 function it_returns_null_if_family_is_not_found(Family $family, $entityRepository, $mappingCollection)
 {
     $entityRepository->findOneBy(['family' => $family, 'magentoUrl' => ''])->willReturn(null);
     $mappingCollection->getTarget('colors')->willReturn('colors');
     $family->getCode()->willReturn('colors');
     $this->getIdFromFamily($family, '', $mappingCollection)->shouldReturn(null);
 }
 function it_normalizes_family($normalizer, Family $family, AbstractAttribute $sku)
 {
     $sku->getCode()->willReturn('sku');
     $family->getCode()->willReturn('mongo');
     $family->getAttributeAsLabel()->willReturn($sku);
     $normalizer->normalize($family, 'mongodb_json', [])->willReturn(['label' => 'translations']);
     $this->normalize($family, 'mongodb_json', [])->shouldReturn(['code' => 'mongo', 'label' => 'translations', 'attributeAsLabel' => 'sku']);
 }
Example #7
0
 function it_normalizes_a_family_and_its_attributes(Family $family, Collection $attributes, \Iterator $iterator, AbstractAttribute $attribute1)
 {
     $family->getCode()->willReturn('bar');
     $family->getAttributes()->willReturn($attributes);
     $attribute1->getCode()->willReturn('att1');
     $attributes->getIterator()->willReturn($iterator);
     $iterator->rewind()->willReturn($attribute1);
     $iterator->current()->willReturn($attribute1);
     $iterator->next()->willReturn($attribute1);
     $valueCount = 1;
     $iterator->valid()->will(function () use(&$valueCount) {
         return $valueCount-- > 0;
     });
     $this->normalize($family, 'json')->shouldReturn(['code' => 'bar', 'attributes' => ['att1']]);
 }
 /**
  * Get non-identifier attribute from family
  *
  * @param Family $family
  *
  * @return Attribute[]
  */
 protected function getAttributesFromFamily(Family $family)
 {
     $familyCode = $family->getCode();
     if (!isset($this->attributesByFamily[$familyCode])) {
         $this->attributesByFamily[$familyCode] = [];
         $attributes = $family->getAttributes();
         foreach ($attributes as $attribute) {
             if ($attribute->getCode() !== $this->identifierCode) {
                 $this->attributesByFamily[$familyCode][$attribute->getCode()] = $attribute;
             }
         }
     }
     return $this->attributesByFamily[$familyCode];
 }
 /**
  * Normalizes a family
  *
  * @param Family $family
  */
 protected function normalizeFamily(Family $family = null)
 {
     $this->results[self::FIELD_FAMILY] = $family ? $family->getCode() : '';
 }
 function it_normalizes_product_with_a_multiselect_value($filter, $serializer, ProductInterface $product, AbstractAttribute $skuAttribute, AbstractAttribute $colorsAttribute, AbstractProductValue $sku, AbstractProductValue $colors, AttributeOption $red, AttributeOption $blue, Collection $values, Family $family)
 {
     $family->getCode()->willReturn('shoes');
     $skuAttribute->getCode()->willReturn('sku');
     $skuAttribute->getAttributeType()->willReturn('pim_catalog_identifier');
     $skuAttribute->isLocalizable()->willReturn(false);
     $skuAttribute->isScopable()->willReturn(false);
     $sku->getAttribute()->willReturn($skuAttribute);
     $sku->getData()->willReturn('sku-001');
     $colorsAttribute->getCode()->willReturn('colors');
     $colorsAttribute->isLocalizable()->willReturn(false);
     $colorsAttribute->isScopable()->willReturn(false);
     $colors->getAttribute()->willReturn($colorsAttribute);
     $colors->getData()->willReturn([$red, $blue]);
     $product->getIdentifier()->willReturn($sku);
     $product->getFamily()->willReturn($family);
     $product->isEnabled()->willReturn(true);
     $product->getGroupCodes()->willReturn('');
     $product->getCategoryCodes()->willReturn('');
     $product->getAssociations()->willReturn([]);
     $product->getValues()->willReturn($values);
     $filter->filter($values, ['identifier' => $sku, 'scopeCode' => null, 'localeCodes' => []])->willReturn([$sku, $colors]);
     $serializer->normalize($sku, 'flat', Argument::any())->willReturn(['sku' => 'sku-001']);
     $serializer->normalize($colors, 'flat', Argument::any())->willReturn(['colors' => 'red, blue']);
     $this->normalize($product, 'flat', [])->shouldReturn(['sku' => 'sku-001', 'family' => 'shoes', 'groups' => '', 'categories' => '', 'colors' => 'red, blue', 'enabled' => 1]);
 }
 /**
  * {@inheritDoc}
  */
 public function getCode()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCode', array());
     return parent::getCode();
 }
 /**
  * Test if an attribute set exist on prestashop.
  *
  * @param Family $family               Family of attribute
  * @param array  $prestashopAttributesSet Attribute sets from prestashop
  *
  * @return boolean Return true if the family exist on prestashop
  */
 protected function prestashopAttributeSetExists(Family $family, array $prestashopAttributesSet)
 {
     return array_key_exists($family->getCode(), $prestashopAttributesSet);
 }
 function it_normalizes_a_family(Family $family)
 {
     $family->getCode()->willReturn('family_code');
     $this->normalize($family)->shouldReturn(['attributeSetName' => 'family_code']);
 }
 /**
  * Sets the requirements for a channel
  *
  * @param string $class
  * @param Family $family
  * @param string $channelCode
  * @param array  $attributeCodes
  */
 protected function setChannelRequirements($class, Family $family, $channelCode, $attributeCodes)
 {
     foreach ($attributeCodes as $attributeCode) {
         $data = array('attribute' => $attributeCode, 'channel' => $channelCode, 'required' => true);
         $requirement = $this->transformNestedEntity($class, 'requirements', $this->requirementClass, $data);
         if ($requirement->getAttribute() === null) {
             throw new \Exception(sprintf('The attribute "%s" used as requirement in family "%s" is not known', $attributeCode, $family->getCode()));
         }
         $family->addAttributeRequirement($requirement);
     }
 }
 /**
  * Returns the attribute codes for a family
  *
  * @param Family $family
  *
  * @return array
  */
 protected function getFamilyAttributeCodes(Family $family)
 {
     $code = $family->getCode();
     if (!isset($this->familyAttributeCodes[$code])) {
         $this->familyAttributeCodes[$code] = $this->getAttributeCodes($family);
     }
     return $this->familyAttributeCodes[$code];
 }
 /**
  * Test if an attribute set exist on magento.
  *
  * @param Family $family               Family of attribute
  * @param array  $magentoAttributesSet Attribute sets from magento
  *
  * @return boolean Return true if the family exist on magento
  */
 protected function magentoAttributeSetExists(Family $family, array $magentoAttributesSet)
 {
     return array_key_exists($family->getCode(), $magentoAttributesSet);
 }