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


PHP Collection::addAttributeToSelect方法代码示例

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


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

示例1: getProductIdBySku

 /**
  * Retrieve product ID by sku
  *
  * @param string $sku
  * @return int|null
  */
 protected function getProductIdBySku($sku)
 {
     if (empty($this->productIds)) {
         $this->productCollection->addAttributeToSelect('sku');
         foreach ($this->productCollection as $product) {
             $this->productIds[$product->getSku()] = $product->getId();
         }
     }
     if (isset($this->productIds[$sku])) {
         return $this->productIds[$sku];
     }
     return null;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:19,代码来源:Converter.php

示例2: getItems

 /**
  * @return array|\Magento\Framework\Data\Collection\AbstractDb
  */
 public function getItems()
 {
     $order = $this->getOrder();
     if (!$order) {
         return [];
     }
     $items = $order->getAllVisibleItems();
     $productIds = [];
     //get the product ids for the collection
     foreach ($items as $item) {
         $productIds[] = $item->getProductId();
     }
     $items = $this->productCollection->addAttributeToSelect('*')->addFieldToFilter('entity_id', ['in' => $productIds]);
     return $items;
 }
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:18,代码来源:Review.php

示例3: addGlobalAttribute

 /**
  * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @return $this
  */
 protected function addGlobalAttribute(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute, \Magento\Catalog\Model\ResourceModel\Product\Collection $collection)
 {
     $storeId = $this->storeManager->getStore()->getId();
     switch ($attribute->getBackendType()) {
         case 'decimal':
         case 'datetime':
         case 'int':
             $alias = 'at_' . $attribute->getAttributeCode();
             $collection->addAttributeToSelect($attribute->getAttributeCode(), 'inner');
             break;
         default:
             $alias = 'at_' . md5($this->getId()) . $attribute->getAttributeCode();
             $collection->getSelect()->join([$alias => $collection->getTable('catalog_product_index_eav')], "({$alias}.entity_id = e.entity_id) AND ({$alias}.store_id = {$storeId})" . " AND ({$alias}.attribute_id = {$attribute->getId()})", []);
     }
     $this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.value';
     return $this;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:22,代码来源:Product.php

示例4: collectValidatedAttributes

 /**
  * Collect validated attributes
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection
  * @return $this
  */
 public function collectValidatedAttributes($productCollection)
 {
     $attribute = $this->getAttribute();
     if ('category_ids' != $attribute) {
         $productCollection->addAttributeToSelect($attribute, 'left');
         if ($this->getAttributeObject()->isScopeGlobal()) {
             $attributes = $this->getRule()->getCollectedAttributes();
             $attributes[$attribute] = true;
             $this->getRule()->setCollectedAttributes($attributes);
         } else {
             $this->_entityAttributeValues = $productCollection->getAllAttributeValues($attribute);
         }
     }
     return $this;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:21,代码来源:AbstractProduct.php

示例5: filter

 /**
  * Filter product collection
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @param \Magento\Catalog\Model\Category $category
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function filter($collection, \Magento\Catalog\Model\Category $category)
 {
     $collection->addAttributeToSelect($this->catalogConfig->getProductAttributes())->setStore($this->storeManager->getStore())->addMinimalPrice()->addFinalPrice()->addTaxPercents()->addStoreFilter()->addUrlRewrite()->setVisibility($this->productVisibility->getVisibleInSearchIds())->setOrder('relevance', Select::SQL_DESC);
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:12,代码来源:CollectionFilter.php

示例6: filter

 /**
  * Filter product collection
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @param \Magento\Catalog\Model\Category $category
  * @return void
  */
 public function filter($collection, \Magento\Catalog\Model\Category $category)
 {
     $collection->addAttributeToSelect($this->catalogConfig->getProductAttributes())->addMinimalPrice()->addFinalPrice()->addTaxPercents()->addUrlRewrite($category->getId())->setVisibility($this->productVisibility->getVisibleInCatalogIds());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:11,代码来源:CollectionFilter.php


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