Exemplo n.º 1
0
 /**
  * Returns attributes all values in label-value or value-value pairs form. Labels are lower-cased.
  *
  * @param \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute
  * @return array
  */
 public function getAttributeOptions(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute)
 {
     $options = [];
     if ($attribute->usesSource()) {
         // should attribute has index (option value) instead of a label?
         $index = in_array($attribute->getAttributeCode(), $this->_indexValueAttributes) ? 'value' : 'label';
         // only default (admin) store values used
         $attribute->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
         try {
             foreach ($attribute->getSource()->getAllOptions(false) as $option) {
                 foreach (is_array($option['value']) ? $option['value'] : [$option] as $innerOption) {
                     if (strlen($innerOption['value'])) {
                         // skip ' -- Please Select -- ' option
                         $options[$innerOption['value']] = $innerOption[$index];
                     }
                 }
             }
         } catch (\Exception $e) {
             // ignore exceptions connected with source models
         }
     }
     return $options;
 }