Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

フロント検索ボックス、商品のタグ名による絞り込み #4976

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Eccube/Repository/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'%');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ protected function createFavorites($Customer)
*/
protected function setProductTags(Product $Product, array $tagIds)
{
$ProductTags = $Product->getProductTag();
foreach ($ProductTags as $ProductTag) {
$Product->removeProductTag($ProductTag);
$this->entityManager->remove($ProductTag);
}

$Tags = $this->tagRepository->findBy(['id' => $tagIds]);
foreach ($Tags as $Tag) {
$ProductTag = new ProductTag();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ public function testTagSearch()
$Products[0]->setName('りんご');
$this->setProductTags($Products[0], [1]);
$this->setProductTags($Products[1], [1, 2]);
$this->setProductTags($Products[2], []);
$this->entityManager->flush();

// タグ 1 で検索
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,52 @@ public function test300ProductsList()
}
$this->verify();
}

public function testTagSearch()
{
// データの事前準備
// * 商品A に タグ 1 を設定
// * 商品B に タグ 2, 2 を設定
$Products = $this->productRepository->findAll();
$Products[1]->setName('りんご');
$this->setProductTags($Products[0], [1]);
$this->setProductTags($Products[1], [1, 2]);
$this->setProductTags($Products[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);
}
}