当前位置: 首页>>代码示例>>PHP>>正文


PHP AbstractAttribute::getSource方法代码示例

本文整理汇总了PHP中Magento\Eav\Model\Entity\Attribute\AbstractAttribute::getSource方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractAttribute::getSource方法的具体用法?PHP AbstractAttribute::getSource怎么用?PHP AbstractAttribute::getSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Eav\Model\Entity\Attribute\AbstractAttribute的用法示例。


在下文中一共展示了AbstractAttribute::getSource方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getAttributeOptions

 /**
  * 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;
 }
开发者ID:kid17,项目名称:magento2,代码行数:29,代码来源:AbstractEntity.php

示例2: getAttributeSelectElement

 /**
  * Build attribute select element html string
  *
  * @param AbstractAttribute $attribute
  * @return string
  */
 public function getAttributeSelectElement($attribute)
 {
     $extra = '';
     $options = $attribute->getSource()->getAllOptions(false);
     $name = $attribute->getAttributeCode();
     // 2 - avoid yes/no selects to be multiselects
     if (is_array($options) && count($options) > 2) {
         $extra = 'multiple="multiple" size="4"';
         $name .= '[]';
     } else {
         array_unshift($options, ['value' => '', 'label' => __('All')]);
     }
     return $this->_getSelectBlock()->setName($name)->setId($attribute->getAttributeCode())->setTitle($this->getAttributeLabel($attribute))->setExtraParams($extra)->setValue($this->getAttributeValue($attribute))->setOptions($options)->setClass('multiselect')->getHtml();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:20,代码来源:Form.php

示例3: createMetadataAttribute

 /**
  * @param  AbstractAttribute $attribute
  * @return Data\Eav\AttributeMetadata
  */
 private function createMetadataAttribute($attribute)
 {
     $data = $this->booleanPrefixMapper($attribute->getData());
     // fill options and validate rules
     $data[AttributeMetadata::OPTIONS] = $attribute->usesSource() ? $attribute->getSource()->getAllOptions() : array();
     $data[AttributeMetadata::VALIDATION_RULES] = $attribute->getValidateRules();
     // fill scope
     $data[AttributeMetadata::SCOPE] = $attribute->isScopeGlobal() ? 'global' : ($attribute->isScopeWebsite() ? 'website' : 'store');
     $data[AttributeMetadata::FRONTEND_LABEL] = [];
     $data[AttributeMetadata::FRONTEND_LABEL][0] = array(FrontendLabel::STORE_ID => 0, FrontendLabel::LABEL => $attribute->getFrontendLabel());
     if (is_array($attribute->getStoreLabels())) {
         foreach ($attribute->getStoreLabels() as $storeId => $label) {
             $data[AttributeMetadata::FRONTEND_LABEL][$storeId] = array(FrontendLabel::STORE_ID => $storeId, FrontendLabel::LABEL => $label);
         }
     }
     return $this->attributeMetadataBuilder->populateWithArray($data)->create();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:21,代码来源:MetadataService.php

示例4: getIncludedOptions

 /**
  * Get options for all product attribute values from used products
  *
  * @param \Magento\Catalog\Model\Product[] $usedProducts
  * @param AbstractAttribute $productAttribute
  * @return array
  */
 protected function getIncludedOptions(array $usedProducts, AbstractAttribute $productAttribute)
 {
     $attributeValues = [];
     foreach ($usedProducts as $associatedProduct) {
         $attributeValues[] = $associatedProduct->getData($productAttribute->getAttributeCode());
     }
     $options = $productAttribute->getSource()->getSpecificOptions(array_unique($attributeValues));
     return $options;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:16,代码来源:Collection.php


注:本文中的Magento\Eav\Model\Entity\Attribute\AbstractAttribute::getSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。