Skip to content

Commit

Permalink
Merge pull request #6100 from ji-eunsoo/features/fix_limit-delivery_i…
Browse files Browse the repository at this point in the history
…nput

上限を超えたお届け先の登録の修正
  • Loading branch information
dotani1111 authored Feb 21, 2024
2 parents 9bc3d4e + e51a550 commit 15af4b3
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
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

0 comments on commit 15af4b3

Please sign in to comment.