/** * {@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; }
/** * Return the generated attribute groups as AttributeGroup object. * * @return array */ public function getAttributeGroupObjects() { $attrGroupObjects = []; foreach ($this->attributeGroups as $code => $attributeGroup) { $attrGroupObject = new AttributeGroup(); $attrGroupObject->setCode($code); $attrGroupObjects[$code] = $attrGroupObject; } return $attrGroupObjects; }
/** * {@inheritdoc} * @return AttributeGroupInterface */ protected function createEntity(array $data) { $group = new AttributeGroup(); $group->setCode($data['code']); foreach ($this->getLabels($data) as $locale => $label) { $translation = $group->getTranslation($locale); $translation->setLabel($label); $group->addTranslation($translation); } $group->setSortOrder($data['sortOrder']); foreach ($this->getAttributes($data) as $attribute) { $group->addAttribute($attribute); } return $group; }
/** * Test for _toString method */ public function testToString() { // Change value and assert new $newCode = 'code'; $expectedCode = '[' . $newCode . ']'; $this->group->setCode($newCode); $this->assertEquals($expectedCode, $this->group->__toString()); $newLabel = 'test-label'; $this->assertEntity($this->group->setLocale('en_US')); $this->assertEntity($this->group->setLabel($newLabel)); $this->assertEquals($newLabel, $this->group->__toString()); // if no translation, assert the expected code is returned $this->group->setLocale('fr_FR'); $this->assertEquals($expectedCode, $this->group->__toString()); // if empty translation, assert the expected code is returned $this->group->setLabel(''); $this->assertEquals($expectedCode, $this->group->__toString()); }
/** * {@inheritDoc} */ public function setCode($code) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setCode', array($code)); return parent::setCode($code); }