查看内容

Magento2默认搜索添加SKU或是自定义属性

2019-5-21 11:34| 发布者: lutish| 查看: 262| 评论: 0

修改文件
magento\Framework\Search\Adapter\Mysql\Query\Builder\Match.php


 $matchQuery = $this->fulltextHelper->getMatchQuery(
 前插入
   if ($this->dataHelper->allowExtension()) {
            $attribute = $this->attributeCollection->getItemByColumnValue('attribute_code', 'sku');
            $attributeId = $attribute ? $attribute->getId() : 0;
            if ($attributeId != 0) {
                $connection = $this->_resource->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);
                $mainFullTextScope = $this->fulltextResource->getMainTable() . "_scope" . $this->storeManager->getStore()->getId();
                $tblFullTextScope = $connection->getTableName($mainFullTextScope);
                $resultSku = $connection->fetchOne('SELECT count(entity_id) FROM `' . $tblFullTextScope . '` WHERE attribute_id=' . $attributeId . ' And data_index=\'' . $query->getValue() . '\'');
            }
        }
        if ($resultSku == 1) {
            $matchQuery = 'data_index=\'' . $query->getValue() . '\'';
        } else {
            $matchQuery = $this->fulltextHelper->getMatchQuery(
                $columns, $queryValue, $this->fulltextSearchMode
            );
        }
       
返回顶部