/** * test relatede method */ public function testAddMissingProductValues() { $builder = $this->getProductBuilder(); $product = new Product(); $this->assertEquals(count($product->getValues()), 0); $family = new Family(); $attribute = new Attribute(); $attribute->setCode('one'); $family->addAttribute($attribute); $product->setFamily($family); $builder->addMissingProductValues($product); $this->assertValues($product, array('one')); $attributeTwo = new Attribute(); $attributeTwo->setCode('two'); $attributeTwo->setLocalizable(true); $family->addAttribute($attributeTwo); $builder->addMissingProductValues($product); $this->assertValues($product, array('one', 'twoen_US', 'twofr_FR')); $attributeThree = new Attribute(); $attributeThree->setCode('three'); $attributeThree->setScopable(true); $family->addAttribute($attributeThree); $builder->addMissingProductValues($product); $this->assertValues($product, array('one', 'twoen_US', 'twofr_FR', 'threeecom', 'threeprint')); $attributeFour = new Attribute(); $attributeFour->setCode('four'); $attributeFour->setLocalizable(true); $attributeFour->setScopable(true); $family->addAttribute($attributeFour); $builder->addMissingProductValues($product); $this->assertValues($product, array('one', 'twoen_US', 'twofr_FR', 'threeecom', 'threeprint', 'fouren_USecom', 'fouren_USprint', 'fourfr_FRecom', 'fourfr_FRprint')); }
/** * {@inheritdoc} * * @return Family */ protected function createEntity(array $data) { $family = new Family(); $family->setCode('mycode'); foreach ($this->getLabels($data) as $locale => $label) { $translation = $family->getTranslation($locale); $translation->setLabel($label); $family->addTranslation($translation); } $codes = array('attribute1', 'attribute2', 'attribute3'); $attributes = array(); foreach ($codes as $code) { $attribute = new Attribute(); $attribute->setCode($code); $family->addAttribute($attribute); $attributes[] = $attribute; } $family->setAttributeAsLabel(current($attributes)); $channel1 = new Channel(); $channel1->setCode('channel1'); $channel2 = new Channel(); $channel2->setCode('channel2'); $requirements = array(array('attribute' => $attributes[0], 'channel' => $channel1, 'required' => true), array('attribute' => $attributes[1], 'channel' => $channel1, 'required' => true), array('attribute' => $attributes[2], 'channel' => $channel1, 'required' => false), array('attribute' => $attributes[0], 'channel' => $channel2, 'required' => true), array('attribute' => $attributes[1], 'channel' => $channel2, 'required' => false), array('attribute' => $attributes[2], 'channel' => $channel2, 'required' => true)); $attrRequirements = array(); foreach ($requirements as $requirement) { $attrRequirement = new AttributeRequirement(); $attrRequirement->setAttribute($requirement['attribute']); $attrRequirement->setChannel($requirement['channel']); $attrRequirement->setRequired($requirement['required']); $attrRequirements[] = $attrRequirement; } $family->setAttributeRequirements($attrRequirements); return $family; }
/** * Test related methods */ public function testGuessUpdates() { $attribute = new Attribute(); $attribute->setCode('my_attribute'); $value = new ProductValue(); $value->setAttribute($attribute); $product = new Product(); $product->addValue($value); $guesser = new ProductValueUpdateGuesser(); $em = $this->getEntityManagerMock(); $updates = $guesser->guessUpdates($em, $value, UpdateGuesserInterface::ACTION_UPDATE_ENTITY); $this->assertEquals(1, count($updates)); $this->assertEquals($product, $updates[0]); $attribute = new Attribute(); $attribute->setCode('my_price'); $price = new ProductPrice(); $value = new ProductValue(); $value->setAttribute($attribute); $value->addPrice($price); $product = new Product(); $product->addValue($value); $updates = $guesser->guessUpdates($em, $price, UpdateGuesserInterface::ACTION_UPDATE_ENTITY); $this->assertEquals(1, count($updates)); $this->assertEquals($product, $updates[0]); }
function it_throws_an_error_if_axis_is_updated(GroupInterface $variantGroup) { $variantGroup->setCode('mycode')->shouldBeCalled(); $variantGroup->getId()->willReturn(42); $attribute = new Attribute(); $attribute->setCode('other'); $variantGroup->getAxisAttributes()->willReturn(new ArrayCollection([$attribute])); $values = ['code' => 'mycode', 'axis' => ['main_color']]; $this->shouldThrow(new \InvalidArgumentException('Attributes: This property cannot be changed.'))->during('update', [$variantGroup, $values, []]); }
/** * Get attributes * @param array $data * * @return Attribute[] */ protected function getAttributes($data) { $attributes = array(); foreach ($data['attributes'] as $code) { $attribute = new Attribute(); $attribute->setCode($code); $attributes[] = $attribute; } return $attributes; }
/** * {@inheritdoc} * * @return AttributeOption */ protected function createEntity(array $data) { $attribute = new Attribute(); $attribute->setCode($data['attribute']); $option = new AttributeOption(); $option->setCode($data['code']); $option->setAttribute($attribute); $this->addAttributeOptionLabels($option, $data); return $option; }
/** * Test related methods */ public function testGuessUpdates() { $versionables = array('Pim\\Bundle\\CatalogBundle\\Entity\\Attribute', 'Pim\\Bundle\\CatalogBundle\\Entity\\Family'); $attribute = new Attribute(); $attribute->setCode('my code'); $guesser = new VersionableUpdateGuesser($versionables); $em = $this->getEntityManagerMock(); $updates = $guesser->guessUpdates($em, $attribute, UpdateGuesserInterface::ACTION_UPDATE_ENTITY); $this->assertEquals(1, count($updates)); $this->assertEquals($attribute, $updates[0]); $family = new Family(); $family->setCode('my code'); $updates = $guesser->guessUpdates($em, $family, UpdateGuesserInterface::ACTION_UPDATE_ENTITY); $this->assertEquals(1, count($updates)); $this->assertEquals($family, $updates[0]); }
function let(ChannelManager $channelManager, ProductNormalizer $productNormalizer, PriceMappingManager $priceMappingManager, MappingCollection $categoryMapping, MappingCollection $attributeMapping, MappingCollection $storeViewMapping, ProductInterface $product, Channel $channel, Locale $localeFR, Locale $localeEN, Group $group, Attribute $attribute) { $this->beConstructedWith($channelManager, $productNormalizer, $priceMappingManager, 4); $this->globalContext = ['attributeSetId' => 0, 'magentoAttributes' => ['attribute_code' => ['attribute_id' => 42]], 'magentoAttributesOptions' => [], 'storeViewMapping' => $storeViewMapping, 'magentoStoreViews' => [['code' => 'fr_fr']], 'defaultLocale' => 'default_locale', 'website' => 'website', 'channel' => 'channel', 'categoryMapping' => $categoryMapping, 'attributeCodeMapping' => $attributeMapping, 'create' => true, 'defaultStoreView' => 'default', 'smallImageAttribute' => 'smallImageAttr', 'baseImageAttribute' => 'baseImageAttr', 'thumbnailAttribute' => 'thumbnailAttr', 'pimGrouped' => 'grouped_product_code', 'urlKey' => false, 'skuFirst' => false]; $productNormalizer->getNormalizedImages($product, 'conf-group_code', 'smallImageAttr', 'baseImageAttr', 'thumbnailAttr')->willReturn([]); $productNormalizer->getValues(Argument::cetera())->willReturn([ProductNormalizer::URL_KEY => 'my-url-key']); $channelManager->getChannelByCode('channel')->willReturn($channel); $channel->getLocales()->willReturn([$localeEN, $localeFR]); $localeEN->getCode()->willReturn('default_locale'); $localeFR->getCode()->willReturn('fr_FR'); $channel->getCode()->willReturn('channel_code'); $storeViewMapping->getTarget('default_locale')->willReturn('default_locale'); $storeViewMapping->getTarget('fr_FR')->willReturn('fr_fr'); $group->getId()->willReturn(44); $group->getCode()->willReturn('group_code'); $product->getIdentifier()->willReturn('sku-000'); $attribute->setCode('attribute_code'); $group->getAttributes()->willReturn([$attribute]); $attribute->getCode()->willReturn('attribute_code'); $attributeMapping->getTarget('attribute_code')->willReturn('attribute_code'); }
/** * {@inheritDoc} */ public function setCode($code) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setCode', array($code)); return parent::setCode($code); }
/** * Return the generated attributes as Attribute object * * @return array */ public function getAttributeObjects() { $attributeObjects = []; foreach ($this->attributes as $code => $attribute) { $attributeObject = new Attribute(); $attributeObject->setCode($code); $attributeObject->setAttributeType($attribute['type']); if (isset($attribute['localizable'])) { $attributeObject->setLocalizable($attribute['localizable']); } if (isset($attribute['localizable'])) { $attributeObject->setScopable($attribute['scopable']); } $attributeObjects[$code] = $attributeObject; } return $attributeObjects; }
/** * Data provider for wrong simple data * * @return array */ public static function dataProviderWithWrongSimpleData() { $attribute = new Attribute(); $attribute->setCode('price'); $attribute->setAttributeType('pim_catalog_price_collection')->setBackendType('prices'); $price = new ProductPrice(); $price->setCurrency('EUR'); $price->setData(null); return array(array('null' => null), array('empty string' => ''), array('empty option collection' => new ArrayCollection()), array('unexpected price collection' => new ArrayCollection(array($price)), $attribute)); }