112 private $attributeProto = [];
124 private $attributesPerSet = [];
144 $this->_entityTypeFactory = $entityTypeFactory;
146 $this->_cacheState = $cacheState;
147 $this->_universalFactory = $universalFactory;
169 $this->_entityTypeData =
null;
170 $this->_attributeData =
null;
171 $this->_objects =
null;
172 $this->attributes =
null;
173 $this->_references =
null;
174 $this->_attributeCodes =
null;
175 $this->attributesPerSet = [];
176 $this->_cache->clean(
193 return isset($this->_objects[
$id]) ? $this->_objects[
$id] :
null;
217 $this->_objects[
$id] = $obj;
243 $this->_references[
'entity'][
$id] =
$code;
255 return isset($this->_references[
'entity'][
$id]) ? $this->_references[
'entity'][
$id] :
null;
296 return 'ENTITY/' .
$code;
311 return 'ATTRIBUTE/' .
$entityTypeCode .
'/' . array_pop($codeSegments);
321 if ($this->_isCacheEnabled ===
null) {
322 $this->_isCacheEnabled = $this->_cacheState->isEnabled(\
Magento\Eav\Model\
Cache\Type::TYPE_IDENTIFIER);
334 if (is_array($this->_entityTypeData)) {
337 \Magento\Framework\Profiler::start(
'EAV: ' . __METHOD__, [
'group' =>
'EAV',
'method' => __METHOD__]);
340 $this->_entityTypeData = $this->serializer->unserialize(
$cache);
341 foreach ($this->_entityTypeData as $typeCode =>
$data) {
342 $typeId =
$data[
'entity_type_id'];
345 \Magento\Framework\Profiler::stop(
'EAV: ' . __METHOD__);
349 $entityTypesData = $this->entityTypeCollectionFactory->create()->getData();
350 foreach ($entityTypesData as $typeData) {
351 if (!isset($typeData[
'attribute_model'])) {
352 $typeData[
'attribute_model'] = \Magento\Eav\Model\Entity\Attribute::class;
355 $typeCode = $typeData[
'entity_type_code'];
356 $typeId = $typeData[
'entity_type_id'];
359 $this->_entityTypeData[$typeCode] = $typeData;
364 $this->serializer->serialize($this->_entityTypeData),
368 \Magento\Eav\Model\Entity\Attribute::CACHE_TAG
372 \Magento\Framework\Profiler::stop(
'EAV: ' . __METHOD__);
389 \Magento\Framework\Profiler::start(
'EAV: ' . __METHOD__, [
'group' =>
'EAV',
'method' => __METHOD__]);
391 if (is_numeric(
$code)) {
393 if ($entityCode !==
null) {
401 \Magento\Framework\Profiler::stop(
'EAV: ' . __METHOD__);
406 [
'data' => isset($this->_entityTypeData[
$code]) ? $this->_entityTypeData[
$code] : []]
409 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Invalid entity_type specified: %1',
$code));
414 \Magento\Framework\Profiler::stop(
'EAV: ' . __METHOD__);
429 if (is_array($this->_attributeData) && isset($this->_attributeData[
$entityTypeCode])) {
437 \Magento\Framework\Profiler::start(
'EAV: ' . __METHOD__, [
'group' =>
'EAV',
'method' => __METHOD__]);
439 $attributes = $this->_universalFactory->create(
441 )->setEntityTypeFilter(
451 $this->saveAttribute($attributeObject,
$entityTypeCode, $attributeObject->getAttributeCode());
460 \Magento\Eav\Model\Entity\Attribute::CACHE_TAG
465 \Magento\Framework\Profiler::stop(
'EAV: ' . __METHOD__);
498 \Magento\Framework\Profiler::start(
'EAV: ' . __METHOD__, [
'group' =>
'EAV',
'method' => __METHOD__]);
501 if (is_numeric(
$code)) {
506 \Magento\Framework\Profiler::stop(
'EAV: ' . __METHOD__);
521 \Magento\Framework\Profiler::stop(
'EAV: ' . __METHOD__);
531 private function createAttribute(
$model)
533 if (!isset($this->attributeProto[
$model])) {
535 $this->attributeProto[
$model] = $this->_universalFactory->create(
$model);
537 return clone $this->attributeProto[
$model];
577 if (isset($this->attributesPerSet[$cacheKey])) {
578 return $this->attributesPerSet[$cacheKey];
582 ? $this->serializer->unserialize($attributes)
590 )->setEntityTypeFilter(
592 )->setAttributeSetFilter(
608 \Magento\Eav\Model\Entity\Attribute::CACHE_TAG
618 $this->attributesPerSet[$cacheKey] = $attributes;
639 $existsFullAttribute =
$attribute->hasIsRequired();
640 $fullAttributeData = array_key_exists(
'is_required',
$attributeData);
642 if ($existsFullAttribute || !$existsFullAttribute && !$fullAttributeData) {
675 $requiredKeys = [
'attribute_id',
'attribute_code',
'entity_type_id',
'attribute_model'];
676 foreach ($requiredKeys as $key) {
728 && in_array(
$attribute->getAttributeCode(),
$entity->getDefaultAttributes(),
true)
742 private function initAttributesFromCache(Type
$entityType)
746 if ($this->
isCacheEnabled() && ($attributes = $this->_cache->load($cacheKey))) {
747 $attributes = $this->serializer->unserialize($attributes);
$entityTypeCollectionFactory
_initAttributes($entityType)
_getAttributeReference($id, $entityTypeCode)
_getEntityTypeReference($id)
_addEntityTypeReference($id, $code)
_getAttributeKey($entityTypeCode, $attributeCode)
getEntityAttributeCodes($entityType, $object=null)
__construct(\Magento\Framework\App\CacheInterface $cache, \Magento\Eav\Model\Entity\TypeFactory $entityTypeFactory, \Magento\Eav\Model\ResourceModel\Entity\Type\CollectionFactory $entityTypeCollectionFactory, \Magento\Framework\App\Cache\StateInterface $cacheState, \Magento\Framework\Validator\UniversalFactory $universalFactory, SerializerInterface $serializer=null)
getAttribute($entityType, $code)
const ATTRIBUTES_CODES_CACHE_ID
_validateAttributeData($attributeData=null)
_addAttributeReference($id, $code, $entityTypeCode)
getAttributes($entityType)
const ATTRIBUTES_CACHE_ID
importAttributesData($entityType, array $attributes)
getEntityAttributes($entityType, $object=null)