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


PHP Config::getAttribute方法代码示例

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


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

示例1: processQueryWithField

 /**
  * @param FilterInterface $filter
  * @param bool $isNegation
  * @param string $query
  * @return string
  */
 private function processQueryWithField(FilterInterface $filter, $isNegation, $query)
 {
     /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
     $attribute = $this->config->getAttribute(Product::ENTITY, $filter->getField());
     if ($filter->getField() === 'price') {
         $resultQuery = str_replace($this->connection->quoteIdentifier('price'), $this->connection->quoteIdentifier('price_index.min_price'), $query);
     } elseif ($filter->getField() === 'category_ids') {
         return 'category_ids_index.category_id = ' . $filter->getValue();
     } elseif ($attribute->isStatic()) {
         $alias = $this->tableMapper->getMappingAlias($filter);
         $resultQuery = str_replace($this->connection->quoteIdentifier($attribute->getAttributeCode()), $this->connection->quoteIdentifier($alias . '.' . $attribute->getAttributeCode()), $query);
     } elseif ($filter->getType() === FilterInterface::TYPE_TERM && in_array($attribute->getFrontendInput(), ['select', 'multiselect'], true)) {
         $alias = $this->tableMapper->getMappingAlias($filter);
         if (is_array($filter->getValue())) {
             $value = sprintf('%s IN (%s)', $isNegation ? 'NOT' : '', implode(',', $filter->getValue()));
         } else {
             $value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
         }
         $resultQuery = sprintf('%1$s.value %2$s', $alias, $value);
     } else {
         $table = $attribute->getBackendTable();
         $select = $this->connection->select();
         $ifNullCondition = $this->connection->getIfNullSql('current_store.value', 'main_table.value');
         $currentStoreId = $this->scopeResolver->getScope()->getId();
         $select->from(['main_table' => $table], 'entity_id')->joinLeft(['current_store' => $table], 'current_store.attribute_id = main_table.attribute_id AND current_store.store_id = ' . $currentStoreId, null)->columns([$filter->getField() => $ifNullCondition])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ?', Store::DEFAULT_STORE_ID)->having($query);
         $resultQuery = 'search_index.entity_id IN (
             select entity_id from  ' . $this->conditionManager->wrapBrackets($select) . ' as filter
         )';
     }
     return $resultQuery;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:37,代码来源:Preprocessor.php

示例2: run

 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing sales rules:');
     $file = 'SalesRule/sales_rules.csv';
     $fileName = $this->fixtureHelper->getPath($file);
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
     $attribute = $this->eavConfig->getAttribute('catalog_product', 'sku');
     if ($attribute->getIsUsedForPromoRules() == 0) {
         $attribute->setIsUsedForPromoRules('1')->save();
     }
     foreach ($csvReader as $row) {
         /** @var \Magento\SalesRule\Model\Resource\Rule\Collection $ruleCollection */
         $ruleCollection = $this->ruleCollectionFactory->create();
         $ruleCollection->addFilter('name', $row['name']);
         if ($ruleCollection->count() > 0) {
             continue;
         }
         $row['customer_group_ids'] = $this->catalogRule->getGroupIds();
         $row['website_ids'] = $this->catalogRule->getWebsiteIds();
         $row['conditions_serialized'] = $this->catalogRule->convertSerializedData($row['conditions_serialized']);
         $row['actions_serialized'] = $this->catalogRule->convertSerializedData($row['actions_serialized']);
         /** @var \Magento\SalesRule\Model\Rule $rule */
         $rule = $this->ruleFactory->create();
         $rule->loadPost($row);
         $rule->save();
         $this->logger->logInline('.');
     }
 }
开发者ID:vinai-drive-by-commits,项目名称:magento2-sample-data,代码行数:31,代码来源:Rule.php

示例3: processQueryWithField

 /**
  * @param FilterInterface $filter
  * @param bool $isNegation
  * @param string $query
  * @param QueryContainer $queryContainer
  * @return string
  */
 private function processQueryWithField(FilterInterface $filter, $isNegation, $query, QueryContainer $queryContainer)
 {
     $currentStoreId = $this->scopeResolver->getScope()->getId();
     $attribute = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $filter->getField());
     $select = $this->getConnection()->select();
     $table = $attribute->getBackendTable();
     if ($filter->getField() == 'price') {
         $query = str_replace('price', 'min_price', $query);
         $select->from(['main_table' => $this->resource->getTableName('catalog_product_index_price')], 'entity_id')->where($query);
     } elseif ($filter->getField() == 'category_ids') {
         return 'category_index.category_id = ' . $filter->getValue();
     } else {
         if ($attribute->isStatic()) {
             $select->from(['main_table' => $table], 'entity_id')->where($query);
         } else {
             if ($filter->getType() == FilterInterface::TYPE_TERM) {
                 if (is_array($filter->getValue())) {
                     $value = sprintf('%s IN (%s)', $isNegation ? 'NOT' : '', implode(',', $filter->getValue()));
                 } else {
                     $value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
                 }
                 $filterQuery = sprintf('cpie.store_id = %d AND cpie.attribute_id = %d AND cpie.value %s', $this->scopeResolver->getScope()->getId(), $attribute->getId(), $value);
                 $queryContainer->addFilter($filterQuery);
                 return '';
             }
             $ifNullCondition = $this->getConnection()->getIfNullSql('current_store.value', 'main_table.value');
             $select->from(['main_table' => $table], 'entity_id')->joinLeft(['current_store' => $table], 'current_store.attribute_id = main_table.attribute_id AND current_store.store_id = ' . $currentStoreId, null)->columns([$filter->getField() => $ifNullCondition])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID)->having($query);
         }
     }
     return 'search_index.entity_id IN (
         select entity_id from  ' . $this->conditionManager->wrapBrackets($select) . ' as filter
         )';
 }
开发者ID:nja78,项目名称:magento2,代码行数:40,代码来源:Preprocessor.php

示例4: processQueryWithField

 /**
  * @param FilterInterface $filter
  * @param bool $isNegation
  * @param string $query
  * @return string
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 private function processQueryWithField(FilterInterface $filter, $isNegation, $query)
 {
     $currentStoreId = $this->scopeResolver->getScope()->getId();
     $attribute = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $filter->getField());
     $select = $this->getSelect();
     $table = $attribute->getBackendTable();
     if ($filter->getField() == 'price') {
         $query = str_replace('price', 'min_price', $query);
         $select->from(['main_table' => $this->resource->getTableName('catalog_product_index_price')], 'entity_id')->where($query);
     } elseif ($filter->getField() == 'category_ids') {
         return 'category_index.category_id = ' . $filter->getValue();
     } else {
         if ($attribute->isStatic()) {
             $select->from(['main_table' => $table], 'entity_id')->where($query);
         } else {
             if ($filter->getType() == FilterInterface::TYPE_TERM) {
                 $field = $filter->getField();
                 $mapper = function ($value) use($field, $isNegation) {
                     return ($isNegation ? '-' : '') . $this->attributePrefix . $field . '_' . $value;
                 };
                 if (is_array($filter->getValue())) {
                     $value = implode(' ', array_map($mapper, $filter->getValue()));
                 } else {
                     $value = $mapper($filter->getValue());
                 }
                 return 'MATCH (data_index) AGAINST (' . $this->getConnection()->quote($value) . ' IN BOOLEAN MODE)';
             }
             $ifNullCondition = $this->getConnection()->getIfNullSql('current_store.value', 'main_table.value');
             $select->from(['main_table' => $table], 'entity_id')->joinLeft(['current_store' => $table], 'current_store.attribute_id = main_table.attribute_id AND current_store.store_id = ' . $currentStoreId, null)->columns([$filter->getField() => $ifNullCondition])->where('main_table.attribute_id = ?', $attribute->getAttributeId())->where('main_table.store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID)->having($query);
         }
     }
     return 'search_index.product_id IN (
         select entity_id from  ' . $this->conditionManager->wrapBrackets($select) . ' as filter
         )';
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:42,代码来源:Preprocessor.php

示例5: afterSave

 /**
  * Save EAV default value after save
  *
  * @return $this
  */
 public function afterSave()
 {
     $result = parent::afterSave();
     $attributeObject = $this->eavConfig->getAttribute('customer', 'disable_auto_group_change');
     $attributeObject->setData('default_value', $this->getValue());
     $attributeObject->save();
     return $result;
 }
开发者ID:nja78,项目名称:magento2,代码行数:13,代码来源:DisableAutoGroupAssignDefault.php

示例6: doesEntityHaveOverriddenUrlKeyForStore

 /**
  * Check that entity has overridden url key for specific store
  *
  * @param int $storeId
  * @param int $entityId
  * @param string $entityType
  * @throws \InvalidArgumentException
  * @return bool
  */
 public function doesEntityHaveOverriddenUrlKeyForStore($storeId, $entityId, $entityType)
 {
     $attribute = $this->eavConfig->getAttribute($entityType, 'url_key');
     if (!$attribute) {
         throw new \InvalidArgumentException(sprintf('Cannot retrieve attribute for entity type "%s"', $entityType));
     }
     $select = $this->connection->select()->from($attribute->getBackendTable(), 'store_id')->where('attribute_id = ?', $attribute->getId())->where('entity_id = ?', $entityId);
     return in_array($storeId, $this->connection->fetchCol($select));
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:18,代码来源:StoreViewService.php

示例7: testGetAttributeCache

 /**
  * @param boolean $cacheEnabled
  * @param int $loadCalls
  * @param string $cachedValue
  * @param array $factoryCalls
  * @dataProvider getAttributeCacheDataProvider
  * @return void
  */
 public function testGetAttributeCache($cacheEnabled, $loadCalls, $cachedValue, $factoryCalls)
 {
     $this->stateMock->expects($this->atLeastOnce())->method('isEnabled')->with(\Magento\Eav\Model\Cache\Type::TYPE_IDENTIFIER)->willReturn($cacheEnabled);
     $this->cacheMock->expects($this->exactly($loadCalls))->method('load')->with(Config::ATTRIBUTES_CACHE_ID)->willReturn($cachedValue);
     $collectionStub = new Object([['entity_type_code' => 'type_code_1', 'entity_type_id' => 1]]);
     $this->collectionFactoryMock->expects($this->any())->method('create')->willReturn($collectionStub);
     $this->typeFactoryMock->expects($this->any())->method('create')->willReturn(new Object(['id' => 101]));
     $this->universalFactoryMock->expects($this->exactly(count($factoryCalls)))->method('create')->will($this->returnValueMap($factoryCalls));
     $entityType = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Type')->setMethods(['getEntity'])->disableOriginalConstructor()->getMock();
     $this->config->getAttribute($entityType, 'attribute_code_1');
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:19,代码来源:ConfigTest.php

示例8: doesEntityHaveOverriddenUrlAttributeForStore

 /**
  * Check that entity has overridden url attribute for specific store
  *
  * @param int $storeId
  * @param int $entityId
  * @param string $entityType
  * @param mixed $attributeName
  * @throws \InvalidArgumentException
  * @return bool
  */
 protected function doesEntityHaveOverriddenUrlAttributeForStore($storeId, $entityId, $entityType, $attributeName)
 {
     $attribute = $this->eavConfig->getAttribute($entityType, $attributeName);
     if (!$attribute) {
         throw new \InvalidArgumentException(sprintf('Cannot retrieve attribute for entity type "%s"', $entityType));
     }
     $linkFieldName = $attribute->getEntity()->getLinkField();
     if (!$linkFieldName) {
         $linkFieldName = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
     }
     $select = $this->connection->select()->from(['e' => $attribute->getEntity()->getEntityTable()], [])->join(['e_attr' => $attribute->getBackendTable()], "e.{$linkFieldName} = e_attr.{$linkFieldName}", 'store_id')->where('e_attr.attribute_id = ?', $attribute->getId())->where('e.entity_id = ?', $entityId);
     return in_array($storeId, $this->connection->fetchCol($select));
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:23,代码来源:StoreViewService.php

示例9: 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

示例10: afterDelete

 /**
  * Processing object after delete data
  *
  * @return \Magento\Framework\Model\AbstractModel
  */
 public function afterDelete()
 {
     $result = parent::afterDelete();
     if ($this->getScope() == \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES) {
         $attribute = $this->_eavConfig->getAttribute('customer_address', 'street');
         $website = $this->_storeManager->getWebsite($this->getScopeCode());
         $attribute->setWebsite($website);
         $attribute->load($attribute->getId());
         $attribute->setData('scope_multiline_count', null);
         $attribute->save();
     }
     return $result;
 }
开发者ID:opexsw,项目名称:magento2,代码行数:18,代码来源:Street.php

示例11: getAttributesUsedInRecommender

 /**
  * Retrieve Attributes used in product listing
  *
  * @return array
  */
 public function getAttributesUsedInRecommender()
 {
     if ($this->_usedInRecommender === null) {
         $this->_usedInRecommender = [];
         $entityType = \Magento\Catalog\Model\Product::ENTITY;
         $attributesData = $this->_getResource()->getAttributesUsedInRecommender();
         $this->_eavConfig->importAttributesData($entityType, $attributesData);
         foreach ($attributesData as $attributeData) {
             $attributeCode = $attributeData['attribute_code'];
             $this->_usedInRecommender[$attributeCode] = $this->_eavConfig->getAttribute($entityType, $attributeCode);
         }
     }
     return $this->_usedInRecommender;
 }
开发者ID:halk,项目名称:recowise-magento2-demo,代码行数:19,代码来源:Config.php

示例12: createConfigurableProduct

 protected function createConfigurableProduct()
 {
     $productId1 = 10;
     $productId2 = 20;
     $label = "color";
     $this->configurableAttribute = $this->eavConfig->getAttribute('catalog_product', 'test_configurable');
     $this->assertNotNull($this->configurableAttribute);
     $options = $this->getConfigurableAttributeOptions();
     $this->assertEquals(2, count($options));
     $configurableProductOptions = [["attribute_id" => $this->configurableAttribute->getId(), "label" => $label, "position" => 0, "values" => [["value_index" => $options[0]['option_id']], ["value_index" => $options[1]['option_id']]]]];
     $product = ["sku" => self::CONFIGURABLE_PRODUCT_SKU, "name" => self::CONFIGURABLE_PRODUCT_SKU, "type_id" => "configurable", "price" => 50, 'attribute_set_id' => 4, "custom_attributes" => [["attribute_code" => $this->configurableAttribute->getAttributeCode(), "value" => $options[0]['option_id']]], "extension_attributes" => ["configurable_product_options" => $configurableProductOptions, "configurable_product_links" => [$productId1, $productId2]]];
     $response = $this->createProduct($product);
     return $response;
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:14,代码来源:ProductRepositoryTest.php

示例13: build

 /**
  * {@inheritdoc}
  */
 public function build($productId)
 {
     $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
     $priceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'price');
     $productTable = $this->resource->getTableName('catalog_product_entity');
     $priceSelect = $this->resource->getConnection()->select()->from(['parent' => $productTable], '')->joinInner(['link' => $this->resource->getTableName('catalog_product_relation')], "link.parent_id = parent.{$linkField}", [])->joinInner(['child' => $productTable], "child.entity_id = link.child_id", ['entity_id'])->joinInner(['t' => $priceAttribute->getBackendTable()], "t.{$linkField} = child.{$linkField}", [])->where('parent.entity_id = ? ', $productId)->where('t.attribute_id = ?', $priceAttribute->getAttributeId())->where('t.value IS NOT NULL')->order('t.value ' . Select::SQL_ASC)->limit(1);
     $priceSelectDefault = clone $priceSelect;
     $priceSelectDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID);
     $select[] = $priceSelectDefault;
     if (!$this->catalogHelper->isPriceGlobal()) {
         $priceSelect->where('t.store_id = ?', $this->storeManager->getStore()->getId());
         $select[] = $priceSelect;
     }
     return $select;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:18,代码来源:LinkedProductSelectBuilderByBasePrice.php

示例14: add

 /**
  * {@inheritdoc}
  */
 public function add($productSku, Option $option)
 {
     $product = $this->productRepository->get($productSku);
     $allowedTypes = [ProductType::TYPE_SIMPLE, ProductType::TYPE_VIRTUAL, ConfigurableType::TYPE_CODE];
     if (!in_array($product->getTypeId(), $allowedTypes)) {
         throw new \InvalidArgumentException('Incompatible product type');
     }
     $eavAttribute = $this->eavConfig->getAttribute(Product::ENTITY, $option->getAttributeId());
     /** @var $configurableAttribute \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute */
     $configurableAttribute = $this->configurableAttributeFactory->create();
     $configurableAttribute->loadByProductAndAttribute($product, $eavAttribute);
     if ($configurableAttribute->getId()) {
         throw new CouldNotSaveException('Product already has this option');
     }
     try {
         $product->setTypeId(ConfigurableType::TYPE_CODE);
         $product->setConfigurableAttributesData([$this->optionConverter->convertArrayFromData($option)]);
         $product->setStoreId($this->storeManager->getStore(Store::ADMIN_CODE)->getId());
         $product->save();
     } catch (\Exception $e) {
         throw new CouldNotSaveException('An error occurred while saving option');
     }
     $configurableAttribute = $this->configurableAttributeFactory->create();
     $configurableAttribute->loadByProductAndAttribute($product, $eavAttribute);
     if (!$configurableAttribute->getId()) {
         throw new CouldNotSaveException('An error occurred while saving option');
     }
     return $configurableAttribute->getId();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:32,代码来源:WriteService.php

示例15: deleteEntity

 /**
  * Delete entity
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function deleteEntity(\Magento\Framework\Model\AbstractModel $object)
 {
     if (!$object->getEntityAttributeId()) {
         return $this;
     }
     $result = $this->getEntityAttribute($object->getEntityAttributeId());
     if ($result) {
         $attribute = $this->_eavConfig->getAttribute($object->getEntityTypeId(), $result['attribute_id']);
         try {
             $this->attrLockValidator->validate($attribute, $result['attribute_set_id']);
         } catch (\Magento\Framework\Exception\LocalizedException $exception) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Attribute \'%1\' is locked. %2', $attribute->getAttributeCode(), $exception->getMessage()));
         }
         $backendTable = $attribute->getBackend()->getTable();
         if ($backendTable) {
             $linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
             $select = $this->getConnection()->select()->from($attribute->getEntity()->getEntityTable(), $linkField)->where('attribute_set_id = ?', $result['attribute_set_id']);
             $clearCondition = ['attribute_id =?' => $attribute->getId(), $linkField . ' IN (?)' => $select];
             $this->getConnection()->delete($backendTable, $clearCondition);
         }
     }
     $condition = ['entity_attribute_id = ?' => $object->getEntityAttributeId()];
     $this->getConnection()->delete($this->getTable('eav_entity_attribute'), $condition);
     return $this;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:32,代码来源:Attribute.php


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