/** * {@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; }
/** * 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; }
/** * {@inheritDoc} */ public function setAttributeType($type) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setAttributeType', array($type)); return parent::setAttributeType($type); }
/** * 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)); }