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


PHP Collection::addFieldToFilter方法代碼示例

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


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

示例1: tearDown

 /**
  * Execute per test cleanup
  */
 public function tearDown()
 {
     /** @var \Magento\Framework\Registry $registry */
     $registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\Registry');
     $registry->unregister('isSecureArea');
     $registry->register('isSecureArea', true);
     $this->productCollection->addFieldToFilter('entity_id', ['in' => [10, 11, 12]])->delete();
     unset($this->productCollection);
     $registry->unregister('isSecureArea');
     $registry->register('isSecureArea', false);
 }
開發者ID:whoople,項目名稱:magento2-testing,代碼行數:14,代碼來源:StockItemTest.php

示例2: addFieldToFilter

 /**
  * Add filtering
  *
  * @param string $field
  * @param null|string $condition
  * @return $this
  */
 public function addFieldToFilter($field, $condition = null)
 {
     if ($field == 'link_title') {
         $conditionSql = $this->_getConditionSql('l.title', $condition);
         $this->getSelect()->where($conditionSql);
     } else {
         parent::addFieldToFilter($field, $condition);
     }
     return $this;
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:17,代碼來源:Collection.php

示例3: addFilterGroupToCollection

 /**
  * Helper function that adds a FilterGroup to the collection.
  *
  * @param \Magento\Framework\Api\Search\FilterGroup $filterGroup
  * @param Collection $collection
  * @return void
  */
 protected function addFilterGroupToCollection(\Magento\Framework\Api\Search\FilterGroup $filterGroup, Collection $collection)
 {
     $fields = [];
     foreach ($filterGroup->getFilters() as $filter) {
         $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
         $fields[] = ['attribute' => $filter->getField(), $condition => $filter->getValue()];
     }
     if ($fields) {
         $collection->addFieldToFilter($fields);
     }
 }
開發者ID:nblair,項目名稱:magescotch,代碼行數:18,代碼來源:ProductRepository.php

示例4: addFilterGroupToCollection

    /**
     * Helper function that adds a FilterGroup to the collection.
     *
     * @param \Magento\Framework\Api\Search\FilterGroup $filterGroup
     * @param Collection $collection
     * @return void
     */
    protected function addFilterGroupToCollection(
        \Magento\Framework\Api\Search\FilterGroup $filterGroup,
        Collection $collection
    ) {
        $fields = [];
        $categoryFilter = [];
        foreach ($filterGroup->getFilters() as $filter) {
            $conditionType = $filter->getConditionType() ? $filter->getConditionType() : 'eq';

            if ($filter->getField() == 'category_id') {
                $categoryFilter[$conditionType][] = $filter->getValue();
                continue;
            }
            $fields[] = ['attribute' => $filter->getField(), $conditionType => $filter->getValue()];
        }

        if ($categoryFilter) {
            $collection->addCategoriesFilter($categoryFilter);
        }

        if ($fields) {
            $collection->addFieldToFilter($fields);
        }
    }
開發者ID:razbakov,項目名稱:magento2,代碼行數:31,代碼來源:ProductRepository.php


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