From c248bdf48e7d44e852527eca576e773b3bb04a80 Mon Sep 17 00:00:00 2001 From: "h.matsuo" Date: Wed, 24 Nov 2021 13:54:52 +0900 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E3=81=AE=E3=82=BF=E3=82=B0?= =?UTF-8?q?=E5=90=8D=E3=81=AB=E3=82=88=E3=82=8B=E6=A4=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Repository/ProductRepository.php | 14 +++++- ...ositoryGetQueryBuilderBySearchDataTest.php | 47 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/Eccube/Repository/ProductRepository.php b/src/Eccube/Repository/ProductRepository.php index f4bde076a9a..1875ad879d2 100644 --- a/src/Eccube/Repository/ProductRepository.php +++ b/src/Eccube/Repository/ProductRepository.php @@ -158,8 +158,18 @@ public function getQueryBuilderBySearchData($searchData) $qb ->andWhere(sprintf('NORMALIZE(p.name) LIKE NORMALIZE(:%s) OR NORMALIZE(p.search_word) LIKE NORMALIZE(:%s) OR - EXISTS (SELECT wpc%d FROM \Eccube\Entity\ProductClass wpc%d WHERE p = wpc%d.Product AND NORMALIZE(wpc%d.code) LIKE NORMALIZE(:%s))', - $key, $key, $index, $index, $index, $index, $key)) + EXISTS (SELECT wpc%d FROM \Eccube\Entity\ProductClass wpc%d WHERE p = wpc%d.Product AND NORMALIZE(wpc%d.code) LIKE NORMALIZE(:%s)) OR + EXISTS ( + SELECT wpt%d from \Eccube\Entity\ProductTag wpt%d + WHERE p = wpt%d.Product AND + wpt%d.Tag IN ( + SELECT wt%d FROM \Eccube\Entity\Tag wt%d + WHERE NORMALIZE(wt%d.name) LIKE NORMALIZE(:%s) + ) + )', + $key, $key, + $index, $index, $index, $index, $key, + $index, $index, $index, $index, $index, $index, $index, $key)) ->setParameter($key, '%'.$keyword.'%'); } } diff --git a/tests/Eccube/Tests/Repository/ProductRepositoryGetQueryBuilderBySearchDataTest.php b/tests/Eccube/Tests/Repository/ProductRepositoryGetQueryBuilderBySearchDataTest.php index 40ebe17b9f2..82f5838da38 100644 --- a/tests/Eccube/Tests/Repository/ProductRepositoryGetQueryBuilderBySearchDataTest.php +++ b/tests/Eccube/Tests/Repository/ProductRepositoryGetQueryBuilderBySearchDataTest.php @@ -393,4 +393,51 @@ public function test300ProductsList() } $this->verify(); } + + public function testTagSearch() + { + // データの事前準備 + // * 商品A に タグ 1 を設定 + // * 商品B に タグ 2, 2 を設定 + $Products = $this->productRepository->findAll(); + $Products[1]->setName('りんご'); + $this->setProductTags($Products[1], [1]); + $this->setProductTags($Products[2], [1, 2]); + $this->entityManager->flush(); + + // タグ 1 で検索 + $this->searchData = [ + 'name' => '新商品', + ]; + $this->scenario(); + $this->assertCount(2, $this->Results); + + // タグ 2 で検索 + $this->searchData = [ + 'name' => 'おすすめ商品', + ]; + $this->scenario(); + $this->assertCount(1, $this->Results); + + // タグ 1 and タグ 2 で検索 + $this->searchData = [ + 'name' => '新商品 おすすめ商品', + ]; + $this->scenario(); + $this->assertCount(1, $this->Results); + + // タグ 1 and 商品名 で検索 + $this->searchData = [ + 'name' => '新商品 りんご', + ]; + $this->scenario(); + $this->assertCount(1, $this->Results); + + // タグ 3 で検索 + $this->searchData = [ + 'name' => '限定品', + ]; + $this->scenario(); + $this->assertCount(0, $this->Results); + } }