Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
CustomAttributesMapper Class Reference
Inheritance diagram for CustomAttributesMapper:
MapperInterface

Public Member Functions

 __construct (AttributeRepositoryInterface $attributeRepository, MetadataPool $metadataPool, SearchCriteriaBuilder $searchCriteriaBuilder)
 
 entityToDatabase ($entityType, $data)
 
 databaseToEntity ($entityType, $data)
 

Detailed Description

Class CustomAttributesMapper

Definition at line 18 of file CustomAttributesMapper.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( AttributeRepositoryInterface  $attributeRepository,
MetadataPool  $metadataPool,
SearchCriteriaBuilder  $searchCriteriaBuilder 
)
Parameters
AttributeRepositoryInterface$attributeRepository
MetadataPool$metadataPool
SearchCriteriaBuilder$searchCriteriaBuilder

Definition at line 45 of file CustomAttributesMapper.php.

49  {
50  $this->attributeRepository = $attributeRepository;
51  $this->metadataPool = $metadataPool;
52  $this->searchCriteriaBuilder = $searchCriteriaBuilder;
53  }

Member Function Documentation

◆ databaseToEntity()

databaseToEntity (   $entityType,
  $data 
)

{Map database field name to entity field name

Parameters
string$entityType
array$data
Returns
array
Exceptions
}

Implements MapperInterface.

Definition at line 81 of file CustomAttributesMapper.php.

82  {
83  $metadata = $this->metadataPool->getMetadata($entityType);
84  if (!$metadata->getEavEntityType()) {
85  return $data;
86  }
87  foreach ($this->getNonStaticAttributes($entityType) as $attribute) {
88  if (isset($data[$attribute->getAttributeCode()])) {
90  AttributeInterface::ATTRIBUTE_CODE => $attribute->getAttributeCode(),
91  AttributeInterface::VALUE => $data[$attribute->getAttributeCode()]
92  ];
93  }
94  }
95  return $data;
96  }

◆ entityToDatabase()

entityToDatabase (   $entityType,
  $data 
)

{Map entity field name to database field name

Parameters
string$entityType
array$data
Returns
array
Exceptions
}

Implements MapperInterface.

Definition at line 58 of file CustomAttributesMapper.php.

59  {
60  if (!$this->metadataPool->hasConfiguration($entityType)
61  || !$this->metadataPool->getMetadata($entityType)->getEavEntityType()
62  ) {
63  return $data;
64  }
66  foreach ($this->getNonStaticAttributes($entityType) as $attribute) {
67  foreach ($data[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES] as $key => $customAttribute) {
68  if ($customAttribute[AttributeInterface::ATTRIBUTE_CODE] == $attribute->getAttributeCode()) {
70  $data[$attribute->getAttributeCode()] = $customAttribute[AttributeInterface::VALUE];
71  }
72  }
73  }
74  }
75  return $data;
76  }

The documentation for this class was generated from the following file: