Skip to content

Commit

Permalink
Revert "管理画面 商品のタグでの絞り込み"
Browse files Browse the repository at this point in the history
This reverts commit 70813a4.
  • Loading branch information
chihiro-adachi committed Aug 31, 2021
1 parent ce55b43 commit 7233312
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 118 deletions.
26 changes: 2 additions & 24 deletions src/Eccube/Form/Type/Admin/SearchProductType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
use Eccube\Entity\Category;
use Eccube\Entity\Master\ProductStatus;
use Eccube\Entity\ProductStock;
use Eccube\Entity\Tag;
use Eccube\Form\Type\Master\CategoryType as MasterCategoryType;
use Eccube\Form\Type\Master\ProductStatusType;
use Eccube\Repository\CategoryRepository;
use Eccube\Repository\Master\ProductStatusRepository;
use Eccube\Repository\TagRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
Expand All @@ -42,26 +39,16 @@ class SearchProductType extends AbstractType
*/
protected $categoryRepository;

/**
* @var TagRepository
*/
protected $tagRepository;

/**
* SearchProductType constructor.
*
* @param ProductStatusRepository $productStatusRepository
* @param CategoryRepository $categoryRepository
* @param TagRepository $tagRepository
*/
public function __construct(
ProductStatusRepository $productStatusRepository,
CategoryRepository $categoryRepository,
TagRepository $tagRepository
) {
public function __construct(ProductStatusRepository $productStatusRepository, CategoryRepository $categoryRepository)
{
$this->productStatusRepository = $productStatusRepository;
$this->categoryRepository = $categoryRepository;
$this->tagRepository = $tagRepository;
}

/**
Expand Down Expand Up @@ -105,15 +92,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'expanded' => true,
'multiple' => true,
])
->add('tag_id', EntityType::class, [
'class' => Tag::class,
'label' => 'admin.product.tag',
'placeholder' => 'common.select__all_products',
'choice_label' => 'name',
'required' => false,
'multiple' => false,
'expanded' => false,
])
->add('create_date_start', DateType::class, [
'label' => 'admin.common.create_date__start',
'required' => false,
Expand Down
8 changes: 0 additions & 8 deletions src/Eccube/Repository/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,6 @@ public function getQueryBuilderBySearchDataForAdmin($searchData)
}
}

// tag
if (!empty($searchData['tag_id']) && $searchData['tag_id']) {
$qb
->innerJoin('p.ProductTag', 'pt')
->andWhere('pt.Tag = :tag_id')
->setParameter('tag_id', $searchData['tag_id']);
}

// crate_date
if (!empty($searchData['create_datetime_start']) && $searchData['create_datetime_start']) {
$date = $searchData['create_datetime_start'];
Expand Down
7 changes: 0 additions & 7 deletions src/Eccube/Resource/template/admin/Product/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,6 @@ file that was distributed with this source code.
</div>
</div>
<div class="col-6">
<div class="form-row mb-2">
<div class="col-6">
<label class="col-form-label">{{ 'admin.product.tag'|trans }}</label>
{{ form_widget(searchForm.tag_id) }}
{{ form_errors(searchForm.tag_id) }}
</div>
</div>
<div class="mb-2">
<label class="col-form-label">
{{ 'admin.common.create_date'|trans }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
namespace Eccube\Tests\Repository;

use Eccube\Entity\CustomerFavoriteProduct;
use Eccube\Entity\Product;
use Eccube\Entity\ProductTag;
use Eccube\Repository\ProductRepository;
use Eccube\Repository\TagRepository;
use Eccube\Tests\EccubeTestCase;
use Eccube\Repository\ProductRepository;

/**
* ProductRepository test cases.
Expand All @@ -32,11 +29,6 @@ abstract class AbstractProductRepositoryTestCase extends EccubeTestCase
*/
protected $productRepository;

/**
* @var TagRepository
*/
protected $tagRepository;

/**
* {@inheritdoc}
*/
Expand All @@ -45,7 +37,6 @@ public function setUp()
parent::setUp();

$this->productRepository = $this->entityManager->getRepository(\Eccube\Entity\Product::class);
$this->tagRepository = $this->entityManager->getRepository(\Eccube\Entity\Tag::class);

$tables = [
'dtb_product_image',
Expand Down Expand Up @@ -76,24 +67,4 @@ protected function createFavorites($Customer)
}
$this->entityManager->flush();
}

/**
* 商品にタグをつける
*
* @param Product $Product
* @param array $tagIds
*/
protected function setProductTags(Product $Product, array $tagIds)
{
$Tags = $this->tagRepository->findBy(['id' => $tagIds]);
foreach ($Tags as $Tag) {
$ProductTag = new ProductTag();
$ProductTag
->setProduct($Product)
->setTag($Tag);
$Product->addProductTag($ProductTag);
$this->entityManager->persist($ProductTag);
}
$this->entityManager->flush();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -366,53 +366,4 @@ public function testProductImage()
$this->verify();
}
}

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

// タグ 1 で検索
$this->searchData = [
'tag_id' => 1,
];
$this->scenario();
$this->assertCount(2, $this->Results);

// タグ 2 で検索
$this->searchData = [
'tag_id' => 2,
];
$this->scenario();
$this->assertCount(1, $this->Results);

// タグ 3 で検索
$this->searchData = [
'tag_id' => 3,
];
$this->scenario();
$this->assertCount(0, $this->Results);

// 文字列とのAND検索 → 結果あり
$this->searchData = [
'id' => 'りんご',
'tag_id' => 1,
];
$this->scenario();
$this->assertCount(1, $this->Results);

// 文字列とのAND検索 → 結果0件
$this->searchData = [
'id' => 'りんご',
'tag_id' => 2,
];
$this->scenario();
$this->assertCount(0, $this->Results);
}
}

0 comments on commit 7233312

Please sign in to comment.