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

上限を超えたお届け先の登録の修正 #6100

Merged
merged 4 commits into from
Feb 21, 2024
Merged
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
90 changes: 90 additions & 0 deletions codeception/acceptance/EF05MypageCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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 退会手続き 未実施');
Expand Down
9 changes: 9 additions & 0 deletions src/Eccube/Controller/ShoppingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Loading