/** * Retrieve select object for loading entity attributes values * Join attribute store value * * @param \Magento\Framework\Object $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 = array($this->getDefaultStoreId()); if ($storeId != $this->getDefaultStoreId()) { $storeIds[] = $storeId; } $select = $this->_getReadAdapter()->select()->from(array('attr_table' => $table), array())->where("attr_table.{$this->getEntityIdField()} = ?", $object->getId())->where('attr_table.store_id IN (?)', $storeIds); if ($setId) { $select->join(array('set_table' => $this->getTable('eav_entity_attribute')), $this->_getReadAdapter()->quoteInto('attr_table.attribute_id = set_table.attribute_id' . ' AND set_table.attribute_set_id = ?', $setId), array()); } return $select; }
/** * Get codes of all entity type attributes * * @param mixed $entityType * @param \Magento\Framework\Object $object * @return array */ public function getEntityAttributeCodes($entityType, $object = null) { $entityType = $this->getEntityType($entityType); $attributeSetId = 0; if ($object instanceof \Magento\Framework\Object && $object->getAttributeSetId()) { $attributeSetId = $object->getAttributeSetId(); } $storeId = 0; if ($object instanceof \Magento\Framework\Object && $object->getStoreId()) { $storeId = $object->getStoreId(); } $cacheKey = sprintf('%d-%d', $entityType->getId(), $attributeSetId); if (isset($this->_attributeCodes[$cacheKey])) { return $this->_attributeCodes[$cacheKey]; } if ($attributeSetId) { $attributesInfo = $this->_universalFactory->create($entityType->getEntityAttributeCollection())->setEntityTypeFilter($entityType)->setAttributeSetFilter($attributeSetId)->addStoreLabel($storeId)->getData(); $attributes = array(); foreach ($attributesInfo as $attributeData) { $attributes[] = $attributeData['attribute_code']; $this->_createAttribute($entityType, $attributeData); } } else { $this->_initAttributes($entityType); $attributes = $this->getEntityType($entityType)->getAttributeCodes(); } $this->_attributeCodes[$cacheKey] = $attributes; return $attributes; }
/** * Get codes of all entity type attributes * * @param mixed $entityType * @param \Magento\Framework\Object $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\Object) { $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; }