當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Config::getEntityAttributeCodes方法代碼示例

本文整理匯總了PHP中Magento\Eav\Model\Config::getEntityAttributeCodes方法的典型用法代碼示例。如果您正苦於以下問題:PHP Config::getEntityAttributeCodes方法的具體用法?PHP Config::getEntityAttributeCodes怎麽用?PHP Config::getEntityAttributeCodes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Eav\Model\Config的用法示例。


在下文中一共展示了Config::getEntityAttributeCodes方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: checkAndInitAttributes

 /**
  * @param AbstractEntity $resource
  * @param DataObject|null $object
  * @return array
  */
 private function checkAndInitAttributes(AbstractEntity $resource, DataObject $object = null)
 {
     $attributeCodes = $this->config->getEntityAttributeCodes($resource->getEntityType(), $object);
     $attributes = [];
     /**
      * Check and init default attributes
      */
     $defaultAttributes = $resource->getDefaultAttributes();
     foreach ($defaultAttributes as $attributeCode) {
         $attributeIndex = array_search($attributeCode, $attributeCodes);
         if ($attributeIndex !== false) {
             $attribute = $resource->getAttribute($attributeCodes[$attributeIndex]);
             $attributes[] = $attribute;
             unset($attributeCodes[$attributeIndex]);
         } else {
             $attribute = $this->_getDefaultAttribute($resource, $attributeCode);
             $attributes[] = $attribute;
             $resource->addAttribute($attribute);
         }
     }
     foreach ($attributeCodes as $code) {
         $attribute = $resource->getAttribute($code);
         $attributes[] = $attribute;
     }
     return $attributes;
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:31,代碼來源:AttributeLoader.php

示例2: getAllAttributeCodes

 /**
  * Get all attribute codes for a given entity type and attribute set
  *
  * @param string $entityType
  * @param int $attributeSetId
  * @param string|null $storeId
  * @return array Attribute codes
  */
 public function getAllAttributeCodes($entityType, $attributeSetId = 0, $storeId = null)
 {
     if (null === $storeId) {
         $storeId = $this->storeManager->getStore()->getId();
     }
     $object = new \Magento\Framework\DataObject(['store_id' => $storeId, 'attribute_set_id' => $attributeSetId]);
     return $this->eavConfig->getEntityAttributeCodes($entityType, $object);
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:16,代碼來源:AttributeMetadataDataProvider.php

示例3: afterGetUsedProductCollection

 /**
  * Returns Configurable Products Collection with added swatch attributes
  *
  * @param ConfigurableProduct $subject
  * @param Collection $result
  * @return Collection
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterGetUsedProductCollection(ConfigurableProductType $subject, Collection $result)
 {
     $attributeCodes = ['image'];
     $entityType = $result->getEntity()->getType();
     foreach ($this->eavConfig->getEntityAttributeCodes($entityType) as $code) {
         $attribute = $this->eavConfig->getAttribute($entityType, $code);
         if ($this->swatchHelper->isVisualSwatch($attribute) || $this->swatchHelper->isTextSwatch($attribute)) {
             $attributeCodes[] = $code;
         }
     }
     $result->addAttributeToSelect($attributeCodes);
     return $result;
 }
開發者ID:rafaelstz,項目名稱:magento2,代碼行數:22,代碼來源:Configurable.php

示例4: getProductAttributes

 /**
  *
  * @return array
  */
 public function getProductAttributes()
 {
     if (is_null($this->prodAttributes)) {
         $this->prodAttributes = $this->eavConfig->getEntityAttributeCodes(\Magento\Catalog\Model\Product::ENTITY);
     }
     return $this->prodAttributes;
 }
開發者ID:shipperhq,項目名稱:module-shipper,代碼行數:11,代碼來源:Data.php

示例5: getFilterArray

 /**
  * Get filters from request
  *
  * @param array $request
  * @return array
  */
 protected function getFilterArray(array $request)
 {
     $filterArray = [];
     $attributeCodes = $this->eavConfig->getEntityAttributeCodes(\Magento\Catalog\Model\Product::ENTITY);
     foreach ($request as $code => $value) {
         if (in_array($code, $attributeCodes)) {
             $attribute = $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $code);
             if ($attribute->getId() && $this->canReplaceImageWithSwatch($attribute)) {
                 $filterArray[$code] = $value;
             }
         }
     }
     return $filterArray;
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:20,代碼來源:ProductImage.php

示例6: getAllAttributeSetMetadata

 /**
  * {@inheritdoc}
  */
 public function getAllAttributeSetMetadata($entityType, $attributeSetId = 0, $storeId = null)
 {
     if (null === $storeId) {
         $storeId = $this->_storeManager->getStore()->getId();
     }
     $object = new \Magento\Framework\Object(['store_id' => $storeId, 'attribute_set_id' => $attributeSetId]);
     $attributeCodes = $this->_eavConfig->getEntityAttributeCodes($entityType, $object);
     $attributesMetadata = [];
     foreach ($attributeCodes as $attributeCode) {
         try {
             $attributesMetadata[] = $this->getAttributeMetadata($entityType, $attributeCode);
         } catch (NoSuchEntityException $e) {
             //If no such entity, skip
         }
     }
     return $attributesMetadata;
 }
開發者ID:Atlis,項目名稱:docker-magento2,代碼行數:20,代碼來源:CustomerMetadataService.php

示例7: loadAllAttributes

 /**
  * Retrieve configuration for all attributes
  *
  * @param null|\Magento\Framework\Object $object
  * @return $this
  */
 public function loadAllAttributes($object = null)
 {
     $attributeCodes = $this->_eavConfig->getEntityAttributeCodes($this->getEntityType(), $object);
     /**
      * Check and init default attributes
      */
     $defaultAttributes = $this->getDefaultAttributes();
     foreach ($defaultAttributes as $attributeCode) {
         $attributeIndex = array_search($attributeCode, $attributeCodes);
         if ($attributeIndex !== false) {
             $this->getAttribute($attributeCodes[$attributeIndex]);
             unset($attributeCodes[$attributeIndex]);
         } else {
             $this->addAttribute($this->_getDefaultAttribute($attributeCode));
         }
     }
     foreach ($attributeCodes as $code) {
         $this->getAttribute($code);
     }
     return $this;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:27,代碼來源:AbstractEntity.php

示例8: _removeNotApplicableAttributes

 /**
  * Remove don't applicable attributes data
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return void
  */
 protected function _removeNotApplicableAttributes($product)
 {
     $entityType = $product->getResource()->getEntityType();
     foreach ($this->_eavConfig->getEntityAttributeCodes($entityType, $product) as $attributeCode) {
         $attribute = $this->_eavConfig->getAttribute($entityType, $attributeCode);
         $applyTo = $attribute->getApplyTo();
         if (is_array($applyTo) && count($applyTo) > 0 && !in_array($product->getTypeId(), $applyTo)) {
             $product->unsetData($attribute->getAttributeCode());
         }
     }
 }
開發者ID:koliaGI,項目名稱:magento2,代碼行數:17,代碼來源:AbstractType.php

示例9: _processProductAttributes

 /**
  * Process product attributes on collection.
  *
  * @param $collection
  *
  * @return mixed
  */
 public function _processProductAttributes($collection)
 {
     //if no product attribute or collection empty return collection
     if (empty($this->productAttribute) or !$collection->getSize()) {
         return $collection;
     }
     foreach ($collection as $collectionItem) {
         $items = $collectionItem->getAllItems();
         foreach ($items as $item) {
             //loaded product
             $product = $item->getProduct();
             //attributes array from loaded product
             $attributes = $this->config->getEntityAttributeCodes(\Magento\Catalog\Model\Product::ENTITY, $product);
             foreach ($this->productAttribute as $productAttribute) {
                 $attribute = $productAttribute['attribute'];
                 $cond = $productAttribute['conditions'];
                 $value = $productAttribute['cvalue'];
                 if ($cond == 'null') {
                     if ($value == '0') {
                         $cond = 'neq';
                     } elseif ($value == '1') {
                         $cond = 'eq';
                     }
                     $value = '';
                 }
                 //if attribute is in product's attributes array
                 if (in_array($attribute, $attributes)) {
                     $attr = $this->config->getAttribute('catalog_product', $attribute);
                     //frontend type
                     $frontType = $attr->getFrontend()->getInputType();
                     //if type is select
                     if ($frontType == 'select' or $frontType == 'multiselect') {
                         $attributeValue = $product->getAttributeText($attribute);
                         //evaluate conditions on values. if true then unset item from collection
                         if ($this->_evaluate($value, $cond, $attributeValue)) {
                             $collection->removeItemByKey($collectionItem->getId());
                             continue 3;
                         }
                     } else {
                         $getter = 'get';
                         $exploded = explode('_', $attribute);
                         foreach ($exploded as $one) {
                             $getter .= ucfirst($one);
                         }
                         //@codingStandardsIgnoreStart
                         $attributeValue = call_user_func([$product, $getter]);
                         //@codingStandardsIgnoreEnd
                         //if retrieved value is an array then loop through all array values.
                         // example can be categories
                         if (is_array($attributeValue)) {
                             foreach ($attributeValue as $attrValue) {
                                 //evaluate conditions on values. if true then unset item from collection
                                 if ($this->_evaluate($value, $cond, $attrValue)) {
                                     $collection->removeItemByKey($collectionItem->getId());
                                     continue 3;
                                 }
                             }
                         } else {
                             //evaluate conditions on values. if true then unset item from collection
                             if ($this->_evaluate($value, $cond, $attributeValue)) {
                                 $collection->removeItemByKey($collectionItem->getId());
                                 continue 3;
                             }
                         }
                     }
                 }
             }
         }
     }
     return $collection;
 }
開發者ID:dotmailer,項目名稱:dotmailer-magento2-extension,代碼行數:78,代碼來源:Rules.php


注:本文中的Magento\Eav\Model\Config::getEntityAttributeCodes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。