62 \
Magento\Framework\Data\Collection\AbstractDb $resourceCollection =
null,
65 $this->extensionAttributesFactory = $extensionFactory;
69 if (isset(
$data[
'id'])) {
72 if (isset(
$data[self::EXTENSION_ATTRIBUTES_KEY]) && is_array(
$data[self::EXTENSION_ATTRIBUTES_KEY])) {
73 $this->populateExtensionAttributes(
$data[self::EXTENSION_ATTRIBUTES_KEY]);
85 if (empty(
$data[self::CUSTOM_ATTRIBUTES])) {
90 (array)
$data[self::CUSTOM_ATTRIBUTES],
94 if (!(
$value instanceof \
Magento\Framework\Api\AttributeInterface)) {
96 ->setAttributeCode(
$code)
110 if (!isset($this->_data[self::CUSTOM_ATTRIBUTES]) || $this->customAttributesChanged) {
111 if (!empty($this->_data[self::CUSTOM_ATTRIBUTES])) {
114 $customAttributes = [];
118 foreach ($customAttributeCodes as $customAttributeCode) {
119 if (isset($this->_data[self::CUSTOM_ATTRIBUTES][$customAttributeCode])) {
120 $customAttribute = $this->customAttributeFactory->create()
121 ->setAttributeCode($customAttributeCode)
122 ->setValue($this->_data[self::CUSTOM_ATTRIBUTES][$customAttributeCode]->getValue());
123 $customAttributes[$customAttributeCode] = $customAttribute;
124 }
elseif (isset($this->_data[$customAttributeCode])) {
125 $customAttribute = $this->customAttributeFactory->create()
126 ->setAttributeCode($customAttributeCode)
127 ->setValue($this->_data[$customAttributeCode]);
128 $customAttributes[$customAttributeCode] = $customAttribute;
132 $this->customAttributesChanged =
false;
145 return array_values($this->_data[self::CUSTOM_ATTRIBUTES]);
176 $attribute = $this->customAttributeFactory->create();
178 ->setValue($attributeValue);
191 if (is_array($key)) {
193 }
elseif ($key == self::CUSTOM_ATTRIBUTES) {
197 $this->customAttributesChanged =
true;
198 parent::setData($key,
$value);
209 if (is_string($key) && isset($this->_data[self::CUSTOM_ATTRIBUTES][$key])) {
210 unset($this->_data[self::CUSTOM_ATTRIBUTES][$key]);
212 return parent::unsetData($key);
223 foreach ($customAttributes as
$attributeCode => $attributeValue) {
224 if ($attributeValue instanceof \
Magento\Framework\Api\AttributeValue) {
249 if ($key === self::CUSTOM_ATTRIBUTES) {
250 throw new \LogicException(
"Custom attributes array should be retrieved via getCustomAttributes() only.");
253 $customAttributes = isset($this->_data[self::CUSTOM_ATTRIBUTES])
257 $data = array_merge($this->_data, $customAttributes);
258 unset(
$data[self::CUSTOM_ATTRIBUTES]);
261 if (
$data ===
null) {
263 $data = isset($this->_data[self::CUSTOM_ATTRIBUTES][$key])
266 if (
$data instanceof \
Magento\Framework\Api\AttributeValue) {
298 protected function getEavAttributesCodes(\
Magento\Framework\Api\MetadataServiceInterface $metadataService)
301 $customAttributesMetadata = $metadataService->getCustomAttributesMetadata(get_class($this));
302 if (is_array($customAttributesMetadata)) {
304 foreach ($customAttributesMetadata as
$attribute) {
342 if (!$this->
getData(self::EXTENSION_ATTRIBUTES_KEY)) {
343 $this->populateExtensionAttributes([]);
345 return $this->
getData(self::EXTENSION_ATTRIBUTES_KEY);
354 private function populateExtensionAttributes(array $extensionAttributesData = [])
356 $extensionAttributes = $this->extensionAttributesFactory->create(get_class($this), $extensionAttributesData);
365 return array_diff(
parent::__sleep(), [
'extensionAttributesFactory',
'customAttributeFactory']);
375 $this->extensionAttributesFactory =
$objectManager->get(ExtensionAttributesFactory::class);
376 $this->customAttributeFactory =
$objectManager->get(AttributeValueFactory::class);
getCustomAttributesCodes()
_getExtensionAttributes()
setCustomAttributes(array $attributes)
elseif(isset( $params[ 'redirect_parent']))
setCustomAttribute($attributeCode, $attributeValue)
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
const EXTENSION_ATTRIBUTES_KEY
convertCustomAttributeValues(array &$customAttributes)
getCustomAttribute($attributeCode)
getData($key='', $index=null)
setData($key, $value=null)
filterCustomAttributes($data)
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
$extensionAttributesFactory
initializeCustomAttributes()