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


PHP Collection::addAttributeToFilter方法代碼示例

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


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

示例1: addFilterByAttributes

 /**
  * {@inheritDoc}
  */
 protected function addFilterByAttributes(ProductCollection $productCollection, array $attributes)
 {
     foreach ($attributes as $code => $option) {
         if (!is_array($option)) {
             $option = [$option];
         }
         $productCollection->addAttributeToFilter($code, ['in' => $option]);
     }
 }
開發者ID:smile-sa,項目名稱:elasticsuite,代碼行數:12,代碼來源:Swatches.php

示例2: prepareData

 /**
  * Prepare configurable data for export
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @param int $productIds
  * @return void
  */
 public function prepareData($collection, $productIds)
 {
     $collection->addAttributeToFilter('entity_id', ['in' => $productIds])->addAttributeToFilter('type_id', ['eq' => \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE]);
     while ($product = $collection->fetchItem()) {
         $productAttributesOptions = $product->getTypeInstance()->getConfigurableOptions($product);
         foreach ($productAttributesOptions as $productAttributeOption) {
             $this->configurableData[$product->getId()] = [];
             $variations = [];
             $variationsLabels = [];
             foreach ($productAttributeOption as $optValues) {
                 $variations[$optValues['sku']][] = $optValues['attribute_code'] . '=' . $optValues['option_title'];
                 if (!empty($optValues['super_attribute_label'])) {
                     $variationsLabels[$optValues['attribute_code']] = $optValues['attribute_code'] . '=' . $optValues['super_attribute_label'];
                 }
             }
             foreach ($variations as $sku => $values) {
                 $variations[$sku] = 'sku=' . $sku . ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR . implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $values);
             }
             $variations = implode(ImportProduct::PSEUDO_MULTI_LINE_SEPARATOR, $variations);
             $variationsLabels = implode(ImportProduct::DEFAULT_GLOBAL_MULTI_VALUE_SEPARATOR, $variationsLabels);
             $this->configurableData[$product->getId()] = ['configurable_variations' => $variations, 'configurable_variation_labels' => $variationsLabels];
         }
     }
 }
開發者ID:whoople,項目名稱:magento2-testing,代碼行數:31,代碼來源:RowCustomizer.php

示例3: addCollectionFilters

 /**
  * Add specific filters
  *
  * @param Collection $collection
  * @return Collection
  */
 protected function addCollectionFilters(Collection $collection)
 {
     $relatedProducts = [];
     /** @var ProductLinkInterface $linkItem */
     foreach ($this->productLinkRepository->getList($this->getProduct()) as $linkItem) {
         if ($linkItem->getLinkType() !== $this->getLinkType()) {
             continue;
         }
         $relatedProducts[] = $this->productRepository->get($linkItem->getLinkedProductSku())->getId();
     }
     if ($relatedProducts) {
         $collection->addAttributeToFilter($collection->getIdFieldName(), ['nin' => [$relatedProducts]]);
     }
     return $collection;
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:21,代碼來源:AbstractDataProvider.php

示例4: prepareData

 /**
  * Prepare data for export
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @param int $productIds
  * @return $this
  */
 public function prepareData($collection, $productIds)
 {
     $collection->addAttributeToFilter('entity_id', ['in' => $productIds])->addAttributeToFilter('type_id', ['eq' => \Magento\Catalog\Model\Product\Type::TYPE_BUNDLE]);
     return $this->populateBundleData($collection);
 }
開發者ID:whoople,項目名稱:magento2-testing,代碼行數:12,代碼來源:RowCustomizer.php

示例5: addAttributeToFilter

 /**
  * Add attribute to filter
  *
  * @param AbstractAttribute|string $attribute
  * @param array|null $condition
  * @param string $joinType
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function addAttributeToFilter($attribute, $condition = null, $joinType = 'inner')
 {
     switch ($attribute) {
         case 'rt.review_id':
         case 'rt.created_at':
         case 'rt.status_id':
         case 'rdt.title':
         case 'rdt.nickname':
         case 'rdt.detail':
             $conditionSql = $this->_getConditionSql($attribute, $condition);
             $this->getSelect()->where($conditionSql);
             break;
         case 'stores':
             $this->setStoreFilter($condition);
             break;
         case 'type':
             if ($condition == 1) {
                 $conditionParts = [$this->_getConditionSql('rdt.customer_id', ['is' => new \Zend_Db_Expr('NULL')]), $this->_getConditionSql('rdt.store_id', ['eq' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])];
                 $conditionSql = implode(' AND ', $conditionParts);
             } elseif ($condition == 2) {
                 $conditionSql = $this->_getConditionSql('rdt.customer_id', ['gt' => 0]);
             } else {
                 $conditionParts = [$this->_getConditionSql('rdt.customer_id', ['is' => new \Zend_Db_Expr('NULL')]), $this->_getConditionSql('rdt.store_id', ['neq' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])];
                 $conditionSql = implode(' AND ', $conditionParts);
             }
             $this->getSelect()->where($conditionSql);
             break;
         default:
             parent::addAttributeToFilter($attribute, $condition, $joinType);
             break;
     }
     return $this;
 }
開發者ID:BlackIkeEagle,項目名稱:magento2-continuousphp,代碼行數:42,代碼來源:Collection.php

示例6: addFilterByAttributes

 /**
  * @param ProductCollection $productCollection
  * @param array $attributes
  * @return void
  */
 protected function addFilterByAttributes(ProductCollection $productCollection, array $attributes)
 {
     foreach ($attributes as $code => $option) {
         $productCollection->addAttributeToFilter($code, ['eq' => $option]);
     }
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:11,代碼來源:Data.php


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