/** * @param DataObject|null $object * @return string */ private function getLoadAllAttributesCacheSuffix(DataObject $object = null) { $attributeSetId = 0; $storeId = 0; if (null !== $object) { $attributeSetId = $object->getAttributeSetId() ?: $attributeSetId; $storeId = $object->getStoreId() ?: $storeId; } $suffix = $storeId . '-' . $attributeSetId; return $suffix; }
/** * Retrieve select object for loading entity attributes values * Join attribute store value * * @param \Magento\Framework\DataObject $object * @param string $table * @return \Magento\Framework\DB\Select */ protected function _getLoadAttributesSelect($object, $table) { /** * This condition is applicable for all cases when we was work in not single * store mode, customize some value per specific store view and than back * to single store mode. We should load correct values */ if ($this->_storeManager->hasSingleStore()) { $storeId = (int) $this->_storeManager->getStore(true)->getId(); } else { $storeId = (int) $object->getStoreId(); } $setId = $object->getAttributeSetId(); $storeIds = [$this->getDefaultStoreId()]; if ($storeId != $this->getDefaultStoreId()) { $storeIds[] = $storeId; } $select = $this->getConnection()->select()->from(['attr_table' => $table], [])->where("attr_table.{$this->getEntityIdField()} = ?", $object->getId())->where('attr_table.store_id IN (?)', $storeIds); if ($setId) { $select->join(['set_table' => $this->getTable('eav_entity_attribute')], $this->getConnection()->quoteInto('attr_table.attribute_id = set_table.attribute_id' . ' AND set_table.attribute_set_id = ?', $setId), []); } return $select; }
/** * Get codes of all entity type attributes * * @param mixed $entityType * @param \Magento\Framework\DataObject $object * @return array * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function getEntityAttributeCodes($entityType, $object = null) { $entityType = $this->getEntityType($entityType); $attributeSetId = 0; $storeId = 0; if ($object instanceof \Magento\Framework\DataObject) { $attributeSetId = $object->getAttributeSetId() ?: $attributeSetId; $storeId = $object->getStoreId() ?: $storeId; } $cacheKey = self::ATTRIBUTES_CODES_CACHE_ID . $entityType->getId() . '-' . $storeId . '-' . $attributeSetId; if (isset($this->_attributeCodes[$cacheKey])) { return $this->_attributeCodes[$cacheKey]; } if ($this->isCacheEnabled() && ($attributes = $this->_cache->load($cacheKey))) { $this->_attributeCodes[$cacheKey] = unserialize($attributes); return $this->_attributeCodes[$cacheKey]; } if ($attributeSetId) { $attributesInfo = $this->_universalFactory->create($entityType->getEntityAttributeCollection())->setEntityTypeFilter($entityType)->setAttributeSetFilter($attributeSetId)->addStoreLabel($storeId)->getData(); $attributes = []; foreach ($attributesInfo as $attributeData) { $attributes[] = $attributeData['attribute_code']; $this->_createAttribute($entityType, $attributeData); } } else { $this->_initAttributes($entityType); $attributes = array_keys($this->_attributeData[$entityType->getEntityTypeCode()]); } $this->_attributeCodes[$cacheKey] = $attributes; if ($this->isCacheEnabled()) { $this->_cache->save(serialize($attributes), $cacheKey, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]); } return $attributes; }