Esempio n. 1
0
 /**
  * Retrieve configuration for all attributes
  *
  * @param AbstractEntity $resource
  * @param DataObject|null $object
  * @return AbstractEntity
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function loadAllAttributes(AbstractEntity $resource, DataObject $object = null)
 {
     $suffix = $this->getLoadAllAttributesCacheSuffix($object);
     $typeCode = $resource->getEntityType()->getEntityTypeCode();
     $attributes = $this->cache->getAttributes($typeCode, $suffix);
     if ($attributes) {
         foreach ($attributes as $attribute) {
             $resource->addAttribute($attribute);
         }
         return $resource;
     }
     $attributes = $this->checkAndInitAttributes($resource, $object);
     $this->cache->saveAttributes($typeCode, $attributes, $suffix);
     return $resource;
 }
Esempio n. 2
0
 /**
  * Retrieve configuration for all attributes
  *
  * @param AbstractEntity $resource
  * @param DataObject|null $object
  * @return AbstractEntity
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function loadAllAttributes(AbstractEntity $resource, DataObject $object = null)
 {
     $attributeCodes = $this->config->getEntityAttributeCodes($resource->getEntityType(), $object);
     /**
      * Check and init default attributes
      */
     $defaultAttributes = $resource->getDefaultAttributes();
     foreach ($defaultAttributes as $attributeCode) {
         $attributeIndex = array_search($attributeCode, $attributeCodes);
         if ($attributeIndex !== false) {
             $resource->getAttribute($attributeCodes[$attributeIndex]);
             unset($attributeCodes[$attributeIndex]);
         } else {
             $resource->addAttribute($this->_getDefaultAttribute($resource, $attributeCode));
         }
     }
     foreach ($attributeCodes as $code) {
         $resource->getAttribute($code);
     }
     return $resource;
 }