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

Feature/#4716 管理者ページ-受注一覧における検索条件の修正 #4766

Merged
merged 6 commits into from
Nov 17, 2020
17 changes: 11 additions & 6 deletions src/Eccube/Repository/OrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,19 @@ public function getQueryBuilderBySearchDataForAdmin($searchData)
}
// multi
if (isset($searchData['multi']) && StringUtil::isNotBlank($searchData['multi'])) {
$multi = preg_match('/^\d{0,10}$/', $searchData['multi']) ? $searchData['multi'] : null;
//スペース除去
$clean_key_multi = preg_replace('/\s+|[ ]+/u', '', $searchData['multi']);
$multi = preg_match('/^\d{0,10}$/', $clean_key_multi) ? $clean_key_multi : null;
if ($multi && $multi > '2147483647' && $this->isPostgreSQL()) {
$multi = null;
}
$qb
->andWhere('o.id = :multi OR o.name01 LIKE :likemulti OR o.name02 LIKE :likemulti OR '.
'o.kana01 LIKE :likemulti OR o.kana02 LIKE :likemulti OR o.company_name LIKE :likemulti OR '.
->andWhere('o.id = :multi OR CONCAT(o.name01, o.name02) LIKE :likemulti OR '.
'CONCAT(o.kana01, o.kana02) LIKE :likemulti OR o.company_name LIKE :company_name OR '.
'o.order_no LIKE :likemulti OR o.email LIKE :likemulti OR o.phone_number LIKE :likemulti')
->setParameter('multi', $multi)
->setParameter('likemulti', '%'.$searchData['multi'].'%');
->setParameter('likemulti', '%'.$clean_key_multi.'%')
->setParameter('company_name', '%'.$searchData['multi'].'%'); // 会社名はスペースを除去せず検索
}

// order_id_end
Expand Down Expand Up @@ -149,16 +152,18 @@ public function getQueryBuilderBySearchDataForAdmin($searchData)

// name
if (isset($searchData['name']) && StringUtil::isNotBlank($searchData['name'])) {
$clean_name = preg_replace('/\s+|[ ]+/u', '', $searchData['name']);
$qb
->andWhere('CONCAT(o.name01, o.name02) LIKE :name')
->setParameter('name', '%'.$searchData['name'].'%');
->setParameter('name', '%'.$clean_name.'%');
}

// kana
if (isset($searchData['kana']) && StringUtil::isNotBlank($searchData['kana'])) {
$clean_kana = preg_replace('/\s+|[ ]+/u', '', $searchData['kana']);
$qb
->andWhere('CONCAT(o.kana01, o.kana02) LIKE :kana')
->setParameter('kana', '%'.$searchData['kana'].'%');
->setParameter('kana', '%'.$clean_kana.'%');
}

// email
Expand Down
73 changes: 71 additions & 2 deletions tests/Eccube/Tests/Repository/OrderRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
namespace Eccube\Tests\Repository;

use Eccube\Entity\Customer;
use Eccube\Entity\Order;
use Eccube\Entity\Master\OrderStatus;
use Eccube\Entity\Order;
use Eccube\Repository\OrderRepository;
use Eccube\Tests\EccubeTestCase;

Expand Down Expand Up @@ -125,12 +125,81 @@ public function testGetQueryBuilderBySearchDataForAdmin_multi_2147483648()
$Order = $this->createOrder($this->createCustomer('[email protected]'));
$Order->setOrderStatus($this->entityManager->find(OrderStatus::class, OrderStatus::NEW));
$this->orderRepository->save($Order);
$this->entityManager->flush();;
$this->entityManager->flush();

$actual = $this->orderRepository->getQueryBuilderBySearchDataForAdmin(['multi' => '2147483648'])
->getQuery()
->getResult();

self::assertEquals($Order, $actual[0]);
}

/**
* @dataProvider dataGetQueryBuilderBySearchDataForAdmin_nameProvider
*/
public function testGetQueryBuilderBySearchDataForAdmin_name(string $formName, string $searchWord, int $expected)
{
$this->Order
->setOrderStatus($this->entityManager->find(OrderStatus::class, OrderStatus::NEW))
->setName01('姓')
->setName02('名')
->setKana01('セイ')
->setKana02('メイ')
->setCompanyName('株式会社 会社名'); // 全角スペース
$this->orderRepository->save($this->Order);
$this->entityManager->flush();

$actual = $this->orderRepository->getQueryBuilderBySearchDataForAdmin([$formName => $searchWord])
->getQuery()
->getResult();

self::assertCount($expected, $actual);
}

public function dataGetQueryBuilderBySearchDataForAdmin_nameProvider()
{
return [
['multi', '姓', 1],
['multi', '名', 1],
['multi', '姓名', 1],
['multi', '姓 名', 1],
['multi', '姓 名', 1],
['multi', 'セイ', 1],
['multi', 'メイ', 1],
['multi', 'セイメイ', 1],
['multi', 'セイ メイ', 1],
['multi', 'セイ メイ', 1],
['multi', '株式会社', 1],
['multi', '会社名', 1],
['multi', '株式会社会社名', 0],
['multi', '株式会社 会社名', 0], // 半角スペース
['multi', '株式会社 会社名', 1], // 全角スペース
['multi', '石', 0],
['multi', 'キューブ', 0],
['multi', '姓 球部', 0],
['multi', 'セイ 名', 0],
['multi', '姓 メイ', 0],
['name', '姓', 1],
['name', '名', 1],
['name', '姓名', 1],
['name', '姓 名', 1],
['name', '姓 名', 1],
['name', 'セイ', 0],
['name', '株式会社 会社名', 0],
['kana', 'セイ', 1],
['kana', 'メイ', 1],
['kana', 'セイメイ', 1],
['kana', 'セイ メイ', 1],
['kana', 'セイ メイ', 1],
['kana', '姓', 0],
['kana', '株式会社 会社名', 0],
['company_name', '株式会社', 1],
['company_name', '会社名', 1],
['company_name', '株式会社会社名', 0],
['company_name', '株式会社 会社名', 0], // 半角スペース
['company_name', '株式会社 会社名', 1], // 全角スペース
['company_name', '姓', 0],
['company_name', 'セイ', 0],
];
}
}