From b3444cf7a6a02b705df63981790418a81cff77d1 Mon Sep 17 00:00:00 2001 From: shinya Date: Fri, 4 Aug 2023 13:01:28 +0900 Subject: [PATCH 01/14] =?UTF-8?q?=E9=87=8D=E8=A4=87=E3=81=97=E3=81=A6?= =?UTF-8?q?=E5=9C=A8=E5=BA=AB=E3=81=8C=E7=99=BB=E9=8C=B2=E3=81=95=E3=82=8C?= =?UTF-8?q?=E3=81=A6=E3=81=97=E3=81=BE=E3=81=86=E5=95=8F=E9=A1=8C=E3=81=AB?= =?UTF-8?q?=E5=AF=BE=E5=87=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Eccube/Controller/Admin/Product/ProductClassController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Eccube/Controller/Admin/Product/ProductClassController.php b/src/Eccube/Controller/Admin/Product/ProductClassController.php index a6588b73d03..79c6beefd98 100644 --- a/src/Eccube/Controller/Admin/Product/ProductClassController.php +++ b/src/Eccube/Controller/Admin/Product/ProductClassController.php @@ -348,6 +348,7 @@ protected function saveProductClasses(Product $Product, $ProductClasses = []) 'create_date', 'update_date', 'Creator', + 'ProductStock', ]); $pc = $ExistsProductClass; } From 28de6f60cc50184a8efeb238190c563d7372347f Mon Sep 17 00:00:00 2001 From: daichi_otani Date: Thu, 21 Sep 2023 11:37:58 +0900 Subject: [PATCH 02/14] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Page/Admin/ProductClassEditPage.php | 32 +++++++++ codeception/acceptance/EA03ProductCest.php | 68 ++++++++++++++++++- 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/codeception/_support/Page/Admin/ProductClassEditPage.php b/codeception/_support/Page/Admin/ProductClassEditPage.php index e1e588981cd..4f603370243 100644 --- a/codeception/_support/Page/Admin/ProductClassEditPage.php +++ b/codeception/_support/Page/Admin/ProductClassEditPage.php @@ -51,6 +51,22 @@ public function 入力_規格1($value) return $this; } + public function 無効_規格($rowNum) + { + --$rowNum; + $this->tester->uncheckOption(['id' => "product_class_matrix_product_classes_${rowNum}_checked"]); + + return $this; + } + + public function 有効_規格($rowNum) + { + --$rowNum; + $this->tester->checkOption(['id' => "product_class_matrix_product_classes_${rowNum}_checked"]); + + return $this; + } + public function 入力_在庫数無制限($rowNum) { --$rowNum; @@ -59,6 +75,14 @@ public function 入力_在庫数無制限($rowNum) return $this; } + public function 無効_在庫数無制限($rowNum) + { + --$rowNum; + $this->tester->uncheckOption(['id' => "product_class_matrix_product_classes_${rowNum}_stock_unlimited"]); + + return $this; + } + public function 入力_販売価格($rowNum, $value) { --$rowNum; @@ -67,6 +91,14 @@ public function 入力_販売価格($rowNum, $value) return $this; } + public function 入力_個数($rowNum, $value) + { + --$rowNum; + $this->tester->fillField(['id' => "product_class_matrix_product_classes_${rowNum}_stock"], $value); + + return $this; + } + public function 選択($rowNum) { --$rowNum; diff --git a/codeception/acceptance/EA03ProductCest.php b/codeception/acceptance/EA03ProductCest.php index db3e71ddbc2..04159c4b02a 100644 --- a/codeception/acceptance/EA03ProductCest.php +++ b/codeception/acceptance/EA03ProductCest.php @@ -12,6 +12,9 @@ */ use Codeception\Util\Fixtures; +use Doctrine\DBAL\Connection; +use Doctrine\ORM\EntityManager; +use Eccube\Repository\ProductStockRepository; use Page\Admin\CategoryCsvUploadPage; use Page\Admin\CategoryManagePage; use Page\Admin\ClassCategoryManagePage; @@ -31,14 +34,28 @@ */ class EA03ProductCest { - const ページタイトル = '#main .page-header'; - const ページタイトルStyleGuide = '.c-pageTitle'; + /** @var EntityManager */ + private EntityManager $em; + + /** @var Connection */ + private $conn; + + /** @var ProductStockRepository */ + private ProductStockRepository $productStockRepository; + + public const ページタイトル = '#main .page-header'; + public const ページタイトルStyleGuide = '.c-pageTitle'; public function _before(AcceptanceTester $I) { // すべてのテストケース実施前にログインしておく // ログイン後は管理アプリのトップページに遷移している $I->loginAsAdmin(); + + // DB接続 + $this->em = Fixtures::get('entityManager'); + $this->conn = $this->em->getConnection(); + $this->productStockRepository = $this->em->getRepository(\Eccube\Entity\ProductStock::class); } public function _after(AcceptanceTester $I) @@ -1006,4 +1023,51 @@ public function product_詳細検索_タグ(AcceptanceTester $I) $I->see('検索結果:1件が該当しました', ProductManagePage::$検索結果_メッセージ); } + + public function product_一覧からの規格編集規格あり3(AcceptanceTester $I) + { + $I->wantTo('EA0310-UC03-T01 一覧からの規格編集 規格あり3'); + + $findProducts = Fixtures::get('findProducts'); + $Products = array_filter($findProducts(), function ($Product) { + return $Product->hasProductClass(); + }); + $Product = array_pop($Products); + + // 先頭のproductClass要素に対してStockを登録する + ProductManagePage::go($I) + ->検索($Product->getName()) + ->検索結果_選択(1); + + ProductEditPage::at($I) + ->規格管理(); + + ProductClassEditPage::at($I) + ->入力_在庫数無制限(1) + ->登録(); + + ProductClassEditPage::at($I) + ->無効_在庫数無制限(1) + ->入力_個数(1, 100) + ->登録(); + + ProductClassEditPage::at($I) + ->無効_規格(1) + ->登録(); + + ProductClassEditPage::at($I) + ->有効_規格(1) + ->入力_個数(1, 10) + ->入力_販売価格(1, 5000) + ->登録(); + + // 個数を取得 + $ProductClasses = $Product->getProductClasses(); + $ProductClass = $ProductClasses[0]; + $stock = $ProductClass->getStock(); + + // 個数のズレがないか検査 + $I->assertEquals(10, $stock, 'Stockが一致'); + $I->see('保存しました', ProductClassEditPage::$登録完了メッセージ); + } } From a8e6368f446c8f952ccddb236bfa448c5aea302a Mon Sep 17 00:00:00 2001 From: daichi_otani Date: Thu, 21 Sep 2023 19:42:42 +0900 Subject: [PATCH 03/14] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codeception/acceptance/EA03ProductCest.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/codeception/acceptance/EA03ProductCest.php b/codeception/acceptance/EA03ProductCest.php index 04159c4b02a..e7ee85bde10 100644 --- a/codeception/acceptance/EA03ProductCest.php +++ b/codeception/acceptance/EA03ProductCest.php @@ -56,6 +56,7 @@ public function _before(AcceptanceTester $I) $this->em = Fixtures::get('entityManager'); $this->conn = $this->em->getConnection(); $this->productStockRepository = $this->em->getRepository(\Eccube\Entity\ProductStock::class); + $this->productClassRepository = $this->em->getRepository(\Eccube\Entity\ProductClass::class); } public function _after(AcceptanceTester $I) @@ -1024,6 +1025,11 @@ public function product_詳細検索_タグ(AcceptanceTester $I) $I->see('検索結果:1件が該当しました', ProductManagePage::$検索結果_メッセージ); } + /** + * @throws \Doctrine\ORM\OptimisticLockException + * @throws \Doctrine\ORM\TransactionRequiredException + * @throws \Doctrine\ORM\Exception\ORMException + */ public function product_一覧からの規格編集規格あり3(AcceptanceTester $I) { $I->wantTo('EA0310-UC03-T01 一覧からの規格編集 規格あり3'); @@ -1061,13 +1067,17 @@ public function product_一覧からの規格編集規格あり3(AcceptanceTeste ->入力_販売価格(1, 5000) ->登録(); + // EntityManagerをクリア + $this->em->refresh($Product); + $this->em->clear(); + // 個数を取得 $ProductClasses = $Product->getProductClasses(); $ProductClass = $ProductClasses[0]; $stock = $ProductClass->getStock(); // 個数のズレがないか検査 - $I->assertEquals(10, $stock, 'Stockが一致'); + $I->assertEquals('10', $stock, 'Stockが一致'); $I->see('保存しました', ProductClassEditPage::$登録完了メッセージ); } } From 25c46549f67c37ee85c013b29ab65b9883e2bf16 Mon Sep 17 00:00:00 2001 From: daichi_otani Date: Mon, 25 Sep 2023 11:44:37 +0900 Subject: [PATCH 04/14] =?UTF-8?q?=E3=82=A8=E3=83=B3=E3=83=86=E3=82=A3?= =?UTF-8?q?=E3=83=86=E3=82=A3=E3=82=92=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8B?= =?UTF-8?q?=E9=9A=9B=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E3=80=81=E3=83=86=E3=82=B9=E3=83=88=E5=90=8D=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codeception/acceptance/EA03ProductCest.php | 23 +++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/codeception/acceptance/EA03ProductCest.php b/codeception/acceptance/EA03ProductCest.php index e7ee85bde10..b4a5b480039 100644 --- a/codeception/acceptance/EA03ProductCest.php +++ b/codeception/acceptance/EA03ProductCest.php @@ -43,8 +43,8 @@ class EA03ProductCest /** @var ProductStockRepository */ private ProductStockRepository $productStockRepository; - public const ページタイトル = '#main .page-header'; - public const ページタイトルStyleGuide = '.c-pageTitle'; + const ページタイトル = '#main .page-header'; + const ページタイトルStyleGuide = '.c-pageTitle'; public function _before(AcceptanceTester $I) { @@ -282,9 +282,9 @@ public function product_一覧からの規格編集規格なし_(AcceptanceTeste $I->seeElement(ProductClassEditPage::$初期化ボタン); } - public function product_一覧からの規格編集規格あり2(AcceptanceTester $I) + public function product_一覧からの規格編集_規格あり_規格登録(AcceptanceTester $I) { - $I->wantTo('EA0310-UC02-T02 一覧からの規格編集 規格あり2'); + $I->wantTo('EA0310-UC02-T02 一覧からの規格編集 規格あり 規格登録'); $findProducts = Fixtures::get('findProducts'); $Products = array_filter($findProducts(), function ($Product) { @@ -375,9 +375,9 @@ public function product_商品の廃止(AcceptanceTester $I) /** * ATTENTION 削除すると後続の規格編集関連のテストが失敗するため、最後に実行する */ - public function product_一覧からの規格編集規格あり1(AcceptanceTester $I) + public function product_一覧からの規格編集規格あり(AcceptanceTester $I) { - $I->wantTo('EA0310-UC02-T01 一覧からの規格編集 規格あり1'); + $I->wantTo('EA0310-UC02-T01 一覧からの規格編集 規格あり'); $findProducts = Fixtures::get('findProducts'); $Products = array_filter($findProducts(), function ($Product) { @@ -1030,9 +1030,9 @@ public function product_詳細検索_タグ(AcceptanceTester $I) * @throws \Doctrine\ORM\TransactionRequiredException * @throws \Doctrine\ORM\Exception\ORMException */ - public function product_一覧からの規格編集規格あり3(AcceptanceTester $I) + public function product_一覧からの規格編集_規格あり_規格操作(AcceptanceTester $I) { - $I->wantTo('EA0310-UC03-T01 一覧からの規格編集 規格あり3'); + $I->wantTo('EA0310-UC02-T03 一覧からの規格編集 規格あり 規格操作'); $findProducts = Fixtures::get('findProducts'); $Products = array_filter($findProducts(), function ($Product) { @@ -1067,12 +1067,11 @@ public function product_一覧からの規格編集規格あり3(AcceptanceTeste ->入力_販売価格(1, 5000) ->登録(); - // EntityManagerをクリア - $this->em->refresh($Product); - $this->em->clear(); - // 個数を取得 $ProductClasses = $Product->getProductClasses(); + $this->em->refresh($Product); + $this->em->refresh($ProductClasses[0]); + $ProductClass = $ProductClasses[0]; $stock = $ProductClass->getStock(); From c325ce59c219598c9e3f8ebf16f029b941164c1d Mon Sep 17 00:00:00 2001 From: daichi_otani Date: Mon, 25 Sep 2023 16:26:22 +0900 Subject: [PATCH 05/14] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codeception/acceptance/EA03ProductCest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/codeception/acceptance/EA03ProductCest.php b/codeception/acceptance/EA03ProductCest.php index b4a5b480039..2c07380c86c 100644 --- a/codeception/acceptance/EA03ProductCest.php +++ b/codeception/acceptance/EA03ProductCest.php @@ -56,7 +56,6 @@ public function _before(AcceptanceTester $I) $this->em = Fixtures::get('entityManager'); $this->conn = $this->em->getConnection(); $this->productStockRepository = $this->em->getRepository(\Eccube\Entity\ProductStock::class); - $this->productClassRepository = $this->em->getRepository(\Eccube\Entity\ProductClass::class); } public function _after(AcceptanceTester $I) From d3d05077808602967e8713da1725c68aa6f19a6d Mon Sep 17 00:00:00 2001 From: daichi_otani Date: Mon, 25 Sep 2023 16:29:11 +0900 Subject: [PATCH 06/14] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=81=AE=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codeception/acceptance/EA03ProductCest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/codeception/acceptance/EA03ProductCest.php b/codeception/acceptance/EA03ProductCest.php index 2c07380c86c..9ba3beb9ba0 100644 --- a/codeception/acceptance/EA03ProductCest.php +++ b/codeception/acceptance/EA03ProductCest.php @@ -14,7 +14,6 @@ use Codeception\Util\Fixtures; use Doctrine\DBAL\Connection; use Doctrine\ORM\EntityManager; -use Eccube\Repository\ProductStockRepository; use Page\Admin\CategoryCsvUploadPage; use Page\Admin\CategoryManagePage; use Page\Admin\ClassCategoryManagePage; @@ -40,9 +39,6 @@ class EA03ProductCest /** @var Connection */ private $conn; - /** @var ProductStockRepository */ - private ProductStockRepository $productStockRepository; - const ページタイトル = '#main .page-header'; const ページタイトルStyleGuide = '.c-pageTitle'; @@ -55,7 +51,6 @@ public function _before(AcceptanceTester $I) // DB接続 $this->em = Fixtures::get('entityManager'); $this->conn = $this->em->getConnection(); - $this->productStockRepository = $this->em->getRepository(\Eccube\Entity\ProductStock::class); } public function _after(AcceptanceTester $I) From 9510a175e690df6e7bad1814582743202c0de79f Mon Sep 17 00:00:00 2001 From: daichi_otani Date: Tue, 26 Sep 2023 10:19:27 +0900 Subject: [PATCH 07/14] =?UTF-8?q?=E3=83=AC=E3=83=93=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codeception/acceptance/EA03ProductCest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/codeception/acceptance/EA03ProductCest.php b/codeception/acceptance/EA03ProductCest.php index 9ba3beb9ba0..0496106fa68 100644 --- a/codeception/acceptance/EA03ProductCest.php +++ b/codeception/acceptance/EA03ProductCest.php @@ -48,9 +48,7 @@ public function _before(AcceptanceTester $I) // ログイン後は管理アプリのトップページに遷移している $I->loginAsAdmin(); - // DB接続 $this->em = Fixtures::get('entityManager'); - $this->conn = $this->em->getConnection(); } public function _after(AcceptanceTester $I) @@ -1020,11 +1018,13 @@ public function product_詳細検索_タグ(AcceptanceTester $I) } /** + * @see https://github.com/EC-CUBE/ec-cube/pull/6029 + * * @throws \Doctrine\ORM\OptimisticLockException * @throws \Doctrine\ORM\TransactionRequiredException * @throws \Doctrine\ORM\Exception\ORMException */ - public function product_一覧からの規格編集_規格あり_規格操作(AcceptanceTester $I) + public function product_一覧からの規格編集_規格あり_重複在庫の修正(AcceptanceTester $I) { $I->wantTo('EA0310-UC02-T03 一覧からの規格編集 規格あり 規格操作'); @@ -1061,12 +1061,12 @@ public function product_一覧からの規格編集_規格あり_規格操作(Ac ->入力_販売価格(1, 5000) ->登録(); - // 個数を取得 + // テストデータ投入時に、上記の規格在庫操作が反映されないためリフレッシュする。 $ProductClasses = $Product->getProductClasses(); $this->em->refresh($Product); $this->em->refresh($ProductClasses[0]); - $ProductClass = $ProductClasses[0]; + $stock = $ProductClass->getStock(); // 個数のズレがないか検査 From fc39d746833da2af69c1042284a60463541b0d4e Mon Sep 17 00:00:00 2001 From: daichi_otani Date: Wed, 27 Sep 2023 08:53:44 +0900 Subject: [PATCH 08/14] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codeception/acceptance/EA03ProductCest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codeception/acceptance/EA03ProductCest.php b/codeception/acceptance/EA03ProductCest.php index 0496106fa68..4031d0f7783 100644 --- a/codeception/acceptance/EA03ProductCest.php +++ b/codeception/acceptance/EA03ProductCest.php @@ -1026,7 +1026,7 @@ public function product_詳細検索_タグ(AcceptanceTester $I) */ public function product_一覧からの規格編集_規格あり_重複在庫の修正(AcceptanceTester $I) { - $I->wantTo('EA0310-UC02-T03 一覧からの規格編集 規格あり 規格操作'); + $I->wantTo('EA0310-UC02-T03 一覧からの規格編集 規格あり 重複在庫の修正'); $findProducts = Fixtures::get('findProducts'); $Products = array_filter($findProducts(), function ($Product) { From 19ad1fb1117bb8c17e8eb27a8af14af5a167fc26 Mon Sep 17 00:00:00 2001 From: daichi_otani Date: Wed, 27 Sep 2023 17:20:46 +0900 Subject: [PATCH 09/14] =?UTF-8?q?DB=E3=81=8B=E3=82=89=E5=8F=96=E5=BE=97?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codeception/acceptance/EA03ProductCest.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/codeception/acceptance/EA03ProductCest.php b/codeception/acceptance/EA03ProductCest.php index 4031d0f7783..4190f0ba10d 100644 --- a/codeception/acceptance/EA03ProductCest.php +++ b/codeception/acceptance/EA03ProductCest.php @@ -49,6 +49,7 @@ public function _before(AcceptanceTester $I) $I->loginAsAdmin(); $this->em = Fixtures::get('entityManager'); + $this->conn = $this->em->getConnection(); } public function _after(AcceptanceTester $I) @@ -1023,6 +1024,7 @@ public function product_詳細検索_タグ(AcceptanceTester $I) * @throws \Doctrine\ORM\OptimisticLockException * @throws \Doctrine\ORM\TransactionRequiredException * @throws \Doctrine\ORM\Exception\ORMException + * @throws \Doctrine\DBAL\Exception */ public function product_一覧からの規格編集_規格あり_重複在庫の修正(AcceptanceTester $I) { @@ -1061,16 +1063,22 @@ public function product_一覧からの規格編集_規格あり_重複在庫の ->入力_販売価格(1, 5000) ->登録(); - // テストデータ投入時に、上記の規格在庫操作が反映されないためリフレッシュする。 + $I->see('保存しました', ProductClassEditPage::$登録完了メッセージ); + + /** 重複して在庫が登録されていないのかチェック **/ + // idを取得 $ProductClasses = $Product->getProductClasses(); - $this->em->refresh($Product); - $this->em->refresh($ProductClasses[0]); $ProductClass = $ProductClasses[0]; + $id = $ProductClass->getId(); - $stock = $ProductClass->getStock(); + // DBからレコード数とStockを取得 + $sql = 'SELECT count(*), stock FROM dtb_product_stock WHERE product_class_id = ?'; + $result = $this->conn->fetchAssociative($sql, [$id]); + $count = $result['count(*)']; + $stock = $result['stock']; // 個数のズレがないか検査 $I->assertEquals('10', $stock, 'Stockが一致'); - $I->see('保存しました', ProductClassEditPage::$登録完了メッセージ); + $I->assertEquals('1', $count, '該当データは1件です'); } } From 72c5d4504dae4a00c8cc303cb4af57ccabbbfac7 Mon Sep 17 00:00:00 2001 From: daichi_otani Date: Wed, 27 Sep 2023 18:35:42 +0900 Subject: [PATCH 10/14] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codeception/acceptance/EA03ProductCest.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/codeception/acceptance/EA03ProductCest.php b/codeception/acceptance/EA03ProductCest.php index 4190f0ba10d..8d0b846c057 100644 --- a/codeception/acceptance/EA03ProductCest.php +++ b/codeception/acceptance/EA03ProductCest.php @@ -37,7 +37,7 @@ class EA03ProductCest private EntityManager $em; /** @var Connection */ - private $conn; + private Connection $conn; const ページタイトル = '#main .page-header'; const ページタイトルStyleGuide = '.c-pageTitle'; @@ -1071,14 +1071,12 @@ public function product_一覧からの規格編集_規格あり_重複在庫の $ProductClass = $ProductClasses[0]; $id = $ProductClass->getId(); - // DBからレコード数とStockを取得 - $sql = 'SELECT count(*), stock FROM dtb_product_stock WHERE product_class_id = ?'; - $result = $this->conn->fetchAssociative($sql, [$id]); - $count = $result['count(*)']; - $stock = $result['stock']; + // 該当IDの商品が1つか確認 + $count = $this->conn->fetchOne('SELECT COUNT(*) FROM dtb_product_stock WHERE product_class_id = ?', [$id]); + $I->assertEquals('1', $count, '該当データは1件です'); - // 個数のズレがないか検査 + // 個数のズレがないか確認 + $stock = $this->conn->fetchOne('SELECT stock FROM dtb_product_stock WHERE product_class_id = ?', [$id]); $I->assertEquals('10', $stock, 'Stockが一致'); - $I->assertEquals('1', $count, '該当データは1件です'); } } From 5dbaaa05efcc4486cd769125829918d3e578313b Mon Sep 17 00:00:00 2001 From: daichi_otani Date: Thu, 28 Sep 2023 14:11:34 +0900 Subject: [PATCH 11/14] =?UTF-8?q?=E9=87=8D=E8=A4=87=E5=9C=A8=E5=BA=AB?= =?UTF-8?q?=E3=81=AE=E6=83=85=E5=A0=B1=E3=82=92=E5=89=8A=E9=99=A4=E3=81=99?= =?UTF-8?q?=E3=82=8Bsql=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Version20230928014611.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 app/DoctrineMigrations/Version20230928014611.php diff --git a/app/DoctrineMigrations/Version20230928014611.php b/app/DoctrineMigrations/Version20230928014611.php new file mode 100644 index 00000000000..189e9b9580b --- /dev/null +++ b/app/DoctrineMigrations/Version20230928014611.php @@ -0,0 +1,51 @@ +connection->fetchAllKeyValue(" +SELECT id,product_class_id, product_class_id_count +FROM ( + SELECT + id, + product_class_id, + COUNT(product_class_id) AS product_class_id_count + FROM + dtb_product_stock + GROUP BY + product_class_id + ) AS subquery +WHERE product_class_id_count > 1; +"); + + // 重複在庫がある場合、dtb_product_class.stockを正として、それ以外の在庫情報は削除する + if (count($exists) != 0) { + foreach ($exists as $id => $pc_id) { + $stock = $this->connection->fetchOne("SELECT stock FROM dtb_product_class WHERE id = :id", ["id" => $pc_id]); + $this->addSql("DELETE FROM dtb_product_stock WHERE product_class_id = :pc_id", ["pc_id" => $pc_id]); + $this->addSql("insert into dtb_product_stock (product_class_id, creator_id, stock, create_date, update_date, discriminator_type) VALUES (:pc_id, null, $stock, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'productstock')", ["pc_id" => $pc_id]); + } + } + } + + public function down(Schema $schema): void + { + } +} From 4e1c8635c1015aac8768b3a315c3cbad6c67caf0 Mon Sep 17 00:00:00 2001 From: daichi_otani Date: Thu, 28 Sep 2023 17:40:11 +0900 Subject: [PATCH 12/14] =?UTF-8?q?sql=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DoctrineMigrations/Version20230928014611.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/DoctrineMigrations/Version20230928014611.php b/app/DoctrineMigrations/Version20230928014611.php index 189e9b9580b..151f0fe2117 100644 --- a/app/DoctrineMigrations/Version20230928014611.php +++ b/app/DoctrineMigrations/Version20230928014611.php @@ -21,10 +21,9 @@ public function up(Schema $schema): void { // 重複した在庫がdtb_product_stockにあるのか確認する。 $exists = $this->connection->fetchAllKeyValue(" -SELECT id,product_class_id, product_class_id_count +SELECT product_class_id, product_class_id_count FROM ( SELECT - id, product_class_id, COUNT(product_class_id) AS product_class_id_count FROM @@ -37,10 +36,10 @@ public function up(Schema $schema): void // 重複在庫がある場合、dtb_product_class.stockを正として、それ以外の在庫情報は削除する if (count($exists) != 0) { - foreach ($exists as $id => $pc_id) { + foreach ($exists as $pc_id => $value) { $stock = $this->connection->fetchOne("SELECT stock FROM dtb_product_class WHERE id = :id", ["id" => $pc_id]); $this->addSql("DELETE FROM dtb_product_stock WHERE product_class_id = :pc_id", ["pc_id" => $pc_id]); - $this->addSql("insert into dtb_product_stock (product_class_id, creator_id, stock, create_date, update_date, discriminator_type) VALUES (:pc_id, null, $stock, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'productstock')", ["pc_id" => $pc_id]); + $this->addSql("INSERT INTO dtb_product_stock (product_class_id, creator_id, stock, create_date, update_date, discriminator_type) VALUES (:pc_id, NULL, :stock, CURRENT_TIME, CURRENT_TIME, 'productstock')", ["pc_id" => $pc_id, "stock" => $stock]); } } } From ac528c84a78e6720084b44992dbcdee77bf88ecf Mon Sep 17 00:00:00 2001 From: daichi_otani Date: Thu, 28 Sep 2023 19:34:18 +0900 Subject: [PATCH 13/14] =?UTF-8?q?sql=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DoctrineMigrations/Version20230928014611.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/DoctrineMigrations/Version20230928014611.php b/app/DoctrineMigrations/Version20230928014611.php index 151f0fe2117..e192acc6444 100644 --- a/app/DoctrineMigrations/Version20230928014611.php +++ b/app/DoctrineMigrations/Version20230928014611.php @@ -39,7 +39,7 @@ public function up(Schema $schema): void foreach ($exists as $pc_id => $value) { $stock = $this->connection->fetchOne("SELECT stock FROM dtb_product_class WHERE id = :id", ["id" => $pc_id]); $this->addSql("DELETE FROM dtb_product_stock WHERE product_class_id = :pc_id", ["pc_id" => $pc_id]); - $this->addSql("INSERT INTO dtb_product_stock (product_class_id, creator_id, stock, create_date, update_date, discriminator_type) VALUES (:pc_id, NULL, :stock, CURRENT_TIME, CURRENT_TIME, 'productstock')", ["pc_id" => $pc_id, "stock" => $stock]); + $this->addSql("INSERT INTO dtb_product_stock (product_class_id, creator_id, stock, create_date, update_date, discriminator_type) VALUES (:pc_id, NULL, :stock, CURRENT_DATE, CURRENT_DATE, 'productstock')", ["pc_id" => $pc_id, "stock" => $stock]); } } } From 2fc2b8117b88d95e0f0fe1a0d98608baea2f9a2c Mon Sep 17 00:00:00 2001 From: shinya Date: Fri, 29 Sep 2023 11:01:04 +0900 Subject: [PATCH 14/14] =?UTF-8?q?=E6=99=82=E5=88=BB=E3=82=82=E7=99=BB?= =?UTF-8?q?=E9=8C=B2=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=80=81?= =?UTF-8?q?CURRENT=5FTIMESTAMP=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DoctrineMigrations/Version20230928014611.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/DoctrineMigrations/Version20230928014611.php b/app/DoctrineMigrations/Version20230928014611.php index e192acc6444..21ee6ffb328 100644 --- a/app/DoctrineMigrations/Version20230928014611.php +++ b/app/DoctrineMigrations/Version20230928014611.php @@ -39,7 +39,7 @@ public function up(Schema $schema): void foreach ($exists as $pc_id => $value) { $stock = $this->connection->fetchOne("SELECT stock FROM dtb_product_class WHERE id = :id", ["id" => $pc_id]); $this->addSql("DELETE FROM dtb_product_stock WHERE product_class_id = :pc_id", ["pc_id" => $pc_id]); - $this->addSql("INSERT INTO dtb_product_stock (product_class_id, creator_id, stock, create_date, update_date, discriminator_type) VALUES (:pc_id, NULL, :stock, CURRENT_DATE, CURRENT_DATE, 'productstock')", ["pc_id" => $pc_id, "stock" => $stock]); + $this->addSql("INSERT INTO dtb_product_stock (product_class_id, creator_id, stock, create_date, update_date, discriminator_type) VALUES (:pc_id, NULL, :stock, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, 'productstock')", ["pc_id" => $pc_id, "stock" => $stock]); } } }