2016年4月20日水曜日

【ECCUBE 3】検索対象を増やす。

ECCUBE3のデフォルトで検索の対称となるのは「商品名」と「検索ワード」のみ。

ここに「商品説明(詳細)」を増やしたい。

検索は下記ファイル内で処理されています。
src/Eccube/Repository/ProductRepository.php


上記ファイル内のgetQueryBuilderBySearchData
if (isset($searchData['name']) && Str::isNotBlank($searchData['name'])) {
    $keywords = preg_split('/[\s ]+/u', $searchData['name'], -1, PREG_SPLIT_NO_EMPTY);
    foreach ($keywords as $index => $keyword) {
        $key = sprintf('keyword%s', $index);
        $qb
            ->andWhere(sprintf ('p.name LIKE :%s OR p.search_word LIKE :%s', $key, $key))
            ->setParameter($key, '%' . $keyword . '%');
    }
}

下記に書き換えればOK!!
andWhereの部分にdescription_detailを追加してます。

if (isset($searchData['name']) && Str::isNotBlank($searchData['name'])) {
    $keywords = preg_split('/[\s ]+/u', $searchData['name'], -1, PREG_SPLIT_NO_EMPTY);
    foreach ($keywords as $index => $keyword) {
        $key = sprintf('keyword%s', $index);
        $qb
            ->andWhere(sprintf ('p.name LIKE :%s OR p.search_word LIKE :%s OR p.description_detail LIKE :%s', $key, $key, $key))
            ->setParameter($key, '%' . $keyword . '%');
    }
}

0 コメント:

コメントを投稿