/** * 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]); }
/** * 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; }
/** * {@inheritdoc} * * @return AttributeInterface */ protected function createEntity(array $data) { $attribute = new Attribute(); $attribute->setAttributeType($data['type']); $this->addLabels($attribute, $data); if ($data['group'] !== '') { $group = new AttributeGroup(); $group->setCode($data['group']); $attribute->setGroup($group); } $attribute->setCode($data['code']); $attribute->setSortOrder($data['sort_order']); $attribute->setRequired($data['required']); $attribute->setUnique($data['unique']); $attribute->setLocalizable($data['localizable']); $attribute->setScopable(strtolower($data['scope']) !== 'global'); $attribute->setUseableAsGridFilter((bool) $data['useable_as_grid_filter']); $attribute->setMetricFamily($data['metric_family']); $attribute->setDefaultMetricUnit($data['default_metric_unit']); $this->addAvailableLocales($attribute, $data); $this->addOptions($attribute, $data); foreach ($this->getOptionalProperties() as $property) { if (isset($data[$property]) && $data[$property] !== '') { $method = 'set' . implode('', array_map(function ($item) { return ucfirst($item); }, explode('_', $property))); $attribute->{$method}($data[$property]); } } return $attribute; }
function it_does_not_build_violation_for_configured_multiselect_reference_data($registry, $context, Attribute $attribute, IsReferenceDataConfigured $constraint) { $attribute->getAttributeType()->willReturn('pim_reference_data_multiselect'); $attribute->getProperty('reference_data_name')->willReturn('foo'); $registry->has('foo')->willReturn(true); $registry->all()->shouldNotBeCalled(); $context->buildViolation(Argument::any())->shouldNotBeCalled(); $this->validate($attribute, $constraint); }
/** * {@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; }
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; }
/** * Test related methods */ public function testGuessUpdates() { $option = new AttributeOption(); $attribute = new Attribute(); $attribute->addOption($option); $guesser = new AttributeOptionUpdateGuesser(); $em = $this->getEntityManagerMock(); $updates = $guesser->guessUpdates($em, $option, UpdateGuesserInterface::ACTION_UPDATE_ENTITY); $this->assertEquals(1, count($updates)); $this->assertEquals($attribute, $updates[0]); }
/** * @param Attribute $attribute * @return array|mixed * @throws InvalidItemException */ public function process($attribute) { $result = ['code' => $attribute->getCode(), 'labels' => array(), 'options' => array()]; foreach ($attribute->getTranslations() as $trans) { $result['labels'][$trans->getLocale()] = $trans->getLabel(); } foreach ($attribute->getOptions() as $attributeOption) { $result['options'][$attributeOption->getCode()] = $this->normalizeOption($attributeOption, $this->globalContext); } return $result; }
/** * Test related methods */ public function testGuessUpdates() { $attribute = new Attribute(); $group = new AttributeGroup(); $attribute->setGroup($group); $guesser = new AttributeGroupUpdateGuesser(); $em = $this->getEntityManagerMock($group); $em->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($this->getUnitOfWorkMock($group))); $updates = $guesser->guessUpdates($em, $attribute, UpdateGuesserInterface::ACTION_UPDATE_ENTITY); $this->assertEquals(2, count($updates)); $this->assertEquals($attribute, $updates[0]); $this->assertEquals($group, $updates[1]); }
function let(ProductValueNormalizer $productValueNormalizer, Attribute $attribute, MappingCollection $attributeMapping, MappingCollection $storeViewMapping) { $this->beConstructedWith($productValueNormalizer); $attribute->isUnique()->willReturn(true); $attribute->isRequired()->willReturn(false); $attribute->isLocalizable()->willReturn(true); $attributeMapping->getTarget('attribute_code')->willReturn('attribute_code_mapped'); $attributeMapping->getTarget('Attribute_code')->willReturn('Attribute_code_mapped'); $attributeMapping->getTarget('2ttribute_code')->willReturn('2ttribute_code'); $attributeMapping->getTarget('attributeCode')->willReturn('attributeCode'); $this->baseContext['attributeCodeMapping'] = $attributeMapping; $this->baseContext['storeViewMapping'] = $storeViewMapping; }
/** * 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'); }
function let(Group $group, Product $product1, Product $product2, Product $product3, Attribute $attribute1, Attribute $attribute2, AttributeOption $attributeOption11, AttributeOption $attributeOption12, AttributeOption $attributeOption21, AttributeOption $attributeOption22, ProductValue $productValueOption11, ProductValue $productValueOption12, ProductValue $productValueOption21, ProductValue $productValueOption22, ProductValue $productValuePrice1, ProductPrice $productPrice1, ProductValue $productValuePrice2, ProductPrice $productPrice2, ProductValue $productValuePrice3, ProductPrice $productPrice3, MappingCollection $attributeMapping) { $this->beConstructedWith('locale', 'currency'); $group->getAttributes()->willReturn([$attribute1, $attribute2]); //get attribute options $attribute1->getOptions()->willReturn([$attributeOption11, $attributeOption12]); $attribute1->getCode()->willReturn('attribute_1'); $attributeOption11->getAttribute()->willReturn($attribute1); $attributeOption11->getCode()->willReturn('attribute_1_option_1'); $productValueOption11->getData()->willReturn($attributeOption11); $attributeOption12->getAttribute()->willReturn($attribute1); $attributeOption12->getCode()->willReturn('attribute_1_option_2'); $productValueOption12->getData()->willReturn($attributeOption12); $attribute2->getOptions()->willReturn([$attributeOption21, $attributeOption22]); $attribute2->getCode()->willReturn('attribute_2'); $attributeOption21->getAttribute()->willReturn($attribute2); $attributeOption21->getCode()->willReturn('attribute_2_option_1'); $productValueOption21->getData()->willReturn($attributeOption21); $attributeOption22->getAttribute()->willReturn($attribute2); $attributeOption22->getCode()->willReturn('attribute_2_option_2'); $productValueOption22->getData()->willReturn($attributeOption22); //Get product prices $product1->getValue('price', 'locale')->willReturn($productValuePrice1); $product1->getIdentifier()->willReturn('product_1'); $productValuePrice1->getPrice('currency')->willReturn($productPrice1); $productPrice1->getData()->willReturn(5.0); $product2->getValue('price', 'locale')->willReturn($productValuePrice2); $product2->getIdentifier()->willReturn('product_2'); $productValuePrice2->getPrice('currency')->willReturn($productPrice2); $productPrice2->getData()->willReturn(15.0); $product3->getValue('price', 'locale')->willReturn($productValuePrice3); $product3->getIdentifier()->willReturn('product_3'); $productValuePrice3->getPrice('currency')->willReturn($productPrice3); $productPrice3->getData()->willReturn(10.0); $attributeMapping->getSource('attribute_1')->willReturn('attribute_1'); $attributeMapping->getSource('attribute_2')->willReturn('attribute_2'); $attributeMapping->getTarget('attribute_1')->willReturn('attribute_1'); $attributeMapping->getTarget('attribute_2')->willReturn('attribute_2'); }
/** * {@inheritDoc} */ public function isBackendTypeReferenceData() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'isBackendTypeReferenceData', array()); return parent::isBackendTypeReferenceData(); }
/** * 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)); }
/** * 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; }
/** * Test getter for attribute ids */ public function testGetAttributeIds() { $expectedIds = array(1, 4, 6); foreach ($expectedIds as $id) { $attribute = new Attribute(); $attribute->setId($id); $this->group->addAttribute($attribute); } $this->assertEquals($expectedIds, $this->group->getAttributeIds()); }
function it_raises_an_exception_if_an_error_occures_during_normalization_process($attributeMappingMerger, $clientParametersRegistry, $groupManager, $normalizerGuesser, $storeViewMappingMerger, $webservice, $webserviceGuesser, Attribute $attribute, AttributeNormalizer $attributeNormalizer, GroupRepository $groupRepository, MagentoSoapClientParameters $clientParameters, MappingCollection $attributeMapping, MappingCollection $storeViewMapping, Webservice $webservice) { $clientParametersRegistry->getInstance(Argument::cetera())->willReturn($clientParameters); $storeViewList = [0 => ['store_id' => '1', 'code' => 'default', 'website_id' => '1', 'group_id' => '1', 'name' => 'Default Store View', 'sort_order' => '0', 'is_active' => '1'], 1 => ['store_id' => '2', 'code' => 'fr_fr', 'website_id' => '1', 'group_id' => '1', 'name' => 'French Store View', 'sort_order' => '0', 'is_active' => '1']]; $normalizerGuesser->getAttributeNormalizer($clientParameters)->willReturn($attributeNormalizer); $webserviceGuesser->getWebservice($clientParameters)->willReturn($webservice); $attribute->getCode()->willReturn('attribute_code'); $storeViewMappingMerger->getMapping()->willReturn($storeViewMapping); $webservice->getAllAttributes()->willReturn([]); $webservice->getAllAttributesOptions()->willReturn([]); $attributeMappingMerger->getMapping()->willReturn($attributeMapping); $webservice->getStoreViewsList()->willReturn($storeViewList); $groupManager->getRepository()->willReturn($groupRepository); $groupRepository->getAxisAttributes()->willReturn([['code' => 'configurable_attribute_code']]); $attributeMapping->getTarget('attribute_code')->willReturn('attribute_code_mapped'); $context = ['defaultLocale' => null, 'storeViewMapping' => $storeViewMapping, 'defaultStoreView' => 'default', 'magentoAttributes' => [], 'magentoAttributesOptions' => [], 'attributeCodeMapping' => $attributeMapping, 'magentoStoreViews' => $storeViewList, 'axisAttributes' => ['configurable_attribute_code'], 'create' => true]; $attributeNormalizer->normalize($attribute, 'MagentoArray', $context)->willThrow(new InvalidItemException('Something goes horribly wrong!', [[]])); $this->shouldThrow(new InvalidItemException('Something goes horribly wrong!', [[]]))->during('process', [$attribute]); }
function it_creates_default_product_for_default_option(Attribute $attribute) { $attribute->getDefaultValue()->shouldBeCalled()->willReturn(null); $this->createProductValueForDefaultOption($attribute)->shouldReturnAnInstanceOf('Pim\\Bundle\\CatalogBundle\\Model\\ProductValue'); }
/** * Create a Attribute entity * @param string $attributeType * @param array $properties * * @return \Pim\Bundle\CatalogBundle\Model\AbstractAttribute */ protected function createAttribute($attributeType, $properties = array()) { $attribute = new Attribute(); $attribute->setAttributeType($attributeType); foreach ($properties as $property => $value) { $set = 'set' . ucfirst($property); if (method_exists($attribute, $set)) { $attribute->{$set}($value); } } return $attribute; }
/** * Test getter for max attribute sort order */ public function testGetMaxAttributeSortOrder() { $max = 5; for ($i = 1; $i <= $max; $i++) { $attribute = new Attribute(); $attribute->setSortOrder($i); $this->group->addAttribute($attribute); } $this->assertEquals($this->group->getMaxAttributeSortOrder(), $max); }
public function let(ObjectManager $objectManager, EntityRepository $entityRepository, Attribute $attribute) { $this->beConstructedWith($objectManager, 'Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoAttributeMapping'); $objectManager->getRepository('Pim\\Bundle\\MagentoConnectorBundle\\Entity\\MagentoAttributeMapping')->willReturn($entityRepository); $attribute->getCode()->willReturn(12); }