當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。