diff --git a/codeception/acceptance/EF05MypageCest.php b/codeception/acceptance/EF05MypageCest.php index 375e57d731b..54d0368b3a1 100644 --- a/codeception/acceptance/EF05MypageCest.php +++ b/codeception/acceptance/EF05MypageCest.php @@ -12,11 +12,16 @@ */ use Codeception\Util\Fixtures; +use Doctrine\DBAL\Connection; +use Doctrine\ORM\EntityManager; use Page\Front\CustomerAddressEditPage; use Page\Front\CustomerAddressListPage; use Page\Front\HistoryPage; use Page\Front\MyPage; use Page\Front\ProductDetailPage; +use Page\Front\ShoppingPage; +use Page\Front\CartPage; +use Eccube\Repository\CustomerAddressRepository; /** * @group front @@ -25,8 +30,21 @@ */ class EF05MypageCest { + /** @var EntityManager */ + private EntityManager $em; + + /** @var Connection */ + private Connection $conn; + + /** + * @var CustomerAddressRepository + */ + protected CustomerAddressRepository $customerAddressRepository; + public function _before(AcceptanceTester $I) { + $this->em = Fixtures::get('entityManager'); + $this->conn = $this->em->getConnection(); } public function _after(AcceptanceTester $I) @@ -287,6 +305,78 @@ public function mypage_お届け先編集削除(AcceptanceTester $I) $I->see('お届け先は登録されていません。', '#page_mypage_delivery > div.ec-layoutRole > div.ec-layoutRole__contents > main > div > div:nth-child(2) > p'); } + /** + * @see https://github.com/EC-CUBE/ec-cube/issues/6081 + */ + public function mypage_お届け先上限確認(AcceptanceTester $I) + { + $I->wantTo('EF0506-UC03-T02 Mypage お届け先上限確認'); + $createCustomer = Fixtures::get('createCustomer'); + $config = Fixtures::get('config'); + $max = $config['eccube_deliv_addr_max']; + + $customer = $createCustomer(); + $I->loginAsMember($customer->getEmail(), 'password'); + + // 19件のお届け先を登録 + /** @var \Doctrine\ORM\EntityManager $em */ + $em = Fixtures::get('entityManager'); + + $this->customerAddressRepository = $em->getRepository(\Eccube\Entity\CustomerAddress::class); + + for ($i = 0; $i < $max; $i++) { + $customerAddress = new \Eccube\Entity\CustomerAddress(); + $customerAddress + ->setCustomer($customer) + ->setName01($customer->getName01()) + ->setName02($customer->getName02()) + ->setKana01($customer->getKana01()) + ->setKana02($customer->getKana02()) + ->setCompanyName($customer->getCompanyName()) + ->setPhoneNumber($customer->getPhoneNumber()) + ->setPostalCode($customer->getPostalCode()) + ->setPref($customer->getPref()) + ->setAddr01($customer->getAddr01()) + ->setAddr02($customer->getAddr02()); + + $em->persist($customerAddress); + } + + $em->flush(); + + // TOPページ>マイページ>お届け先一覧で上限に達していることを確認 + MyPage::go($I)->お届け先編集(); + + $I->wait(1); + + $I->see(sprintf('お届け先登録の上限の%s件に達しています。お届け先を入力したい場合は、削除か変更を行ってください。', 20), '#page_mypage_delivery > div.ec-layoutRole > div.ec-layoutRole__contents > main > div > div:nth-child(3) > div > div'); + + // ご注文手続き画面で上限に達していることを確認 + ProductDetailPage::go($I, 2) + ->カートに入れる(1) + ->カートへ進む(); + + CartPage::go($I) + ->レジに進む(); + + ShoppingPage::at($I)->お届け先変更(); + + $I->wait(1); + + $I->see(sprintf('お届け先登録の上限の%s件に達しています。お届け先を入力したい場合は、削除か変更を行ってください。', 20), 'div.ec-registerRole > div > div > div '); + + // 受注に紐づくidに直接アクセスしても登録されないことを確認 + // URLから受注に紐づくIDを抽出 /shopping/shipping/{id} + $redirectUrl = $I->grabFromCurrentUrl(); + $shipping_id = preg_replace('/\/shopping\/shipping\/(\d+)/', '$1', $redirectUrl); + + // URLに直接アクセス /shopping/shipping_edit/{id} + $I->amOnPage('/shopping/shipping_edit/'.$shipping_id); + + // 404であることを確認 + $I->seeInTitle('ページがみつかりません'); + } + public function mypage_退会手続き未実施(AcceptanceTester $I) { $I->wantTo('EF0507-UC03-T01 Mypage 退会手続き 未実施'); diff --git a/src/Eccube/Controller/ShoppingController.php b/src/Eccube/Controller/ShoppingController.php index 5117fd9421d..1fae14132ef 100644 --- a/src/Eccube/Controller/ShoppingController.php +++ b/src/Eccube/Controller/ShoppingController.php @@ -40,6 +40,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\RateLimiter\RateLimiterFactory; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\RouterInterface; @@ -668,6 +669,14 @@ public function shippingEdit(Request $request, Shipping $Shipping) $CustomerAddress = new CustomerAddress(); if ($this->isGranted('IS_AUTHENTICATED_FULLY')) { + + $Customer = $this->getUser(); + $addressCurrNum = count($Customer->getCustomerAddresses()); + $addressMax = $this->eccubeConfig['eccube_deliv_addr_max']; + if ($addressCurrNum >= $addressMax) { + throw new NotFoundHttpException(); + } + // ログイン時は会員と紐付け $CustomerAddress->setCustomer($this->getUser()); } else {