コード例 #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)
 {
     $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;
 }