Skip to content

Commit

Permalink
Merge pull request #5558 from kurozumi/issue-5549
Browse files Browse the repository at this point in the history
注文時に支払い方法が非表示に変更された場合エラーが発生するよう修正
  • Loading branch information
chihiro-adachi authored Aug 18, 2022
2 parents ff66d0a + af1ee74 commit b2b8067
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/config/eccube/packages/purchaseflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ services:
arguments:
- #
- '@Eccube\Service\PurchaseFlow\Processor\AddPointProcessor' # 加算ポイントの計算
- '@Eccube\Service\PurchaseFlow\Processor\PaymentValidator'
- '@Eccube\Service\PurchaseFlow\Processor\PaymentTotalLimitValidator'
- '@Eccube\Service\PurchaseFlow\Processor\PaymentTotalNegativeValidator'
- '@Eccube\Service\PurchaseFlow\Processor\PaymentChargeChangeValidator' # 手数料の変更検知
Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Resource/locale/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ front.shopping.price_changed: 'The selling price of %product% has been changed.'
front.shopping.payment_total_invalid: The total amount is invalid.
front.shopping.different_payment_methods: Sorry, your order includes items with different purchase methods, which are unable to be processed in one order.
front.shopping.payment_method_unselected: Please select the payment method.
front.shopping.not_available_payment_method: The payment method you have selected is not available.
front.shopping.payment_method_not_fount: Sorry, you have no payment options. If you have selected multiple delivery methods, you can only select the same payment option for them all.
front.under_maintenance: The site is currently under maintenance.

Expand Down
1 change: 1 addition & 0 deletions src/Eccube/Resource/locale/messages.ja.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ front.shopping.price_changed: '「%product%」の販売価格が変更されま
front.shopping.payment_total_invalid: 合計金額が不正です。
front.shopping.different_payment_methods: 支払い方法が異なる商品が含まれているため、同時に購入することはできません。
front.shopping.payment_method_unselected: お支払い方法を選択してください。
front.shopping.not_available_payment_method: 選択したお支払い方法はご利用できません。
front.shopping.payment_method_not_fount: 選択できるお支払い方法がありません。配送方法が異なる場合は同じ配送方法を選んでください。
front.under_maintenance: メンテナンスモードが有効になっています。

Expand Down
12 changes: 12 additions & 0 deletions src/Eccube/Service/PurchaseFlow/Processor/PaymentValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Eccube\Entity\Delivery;
use Eccube\Entity\ItemHolderInterface;
use Eccube\Entity\Master\SaleType;
use Eccube\Entity\Order;
use Eccube\Entity\Payment;
use Eccube\Repository\DeliveryRepository;
use Eccube\Service\PurchaseFlow\ItemHolderValidator;
Expand Down Expand Up @@ -76,6 +77,17 @@ protected function validate(ItemHolderInterface $itemHolder, PurchaseContext $co
if (empty($paymentIds)) {
$this->throwInvalidItemException('front.shopping.different_payment_methods');
}

if ($itemHolder instanceof Order) {
if (null === $itemHolder->getPayment()) {
return;
}

// 支払い方法が非表示の場合はエラー
if (false === $itemHolder->getPayment()->isVisible()) {
$this->throwInvalidItemException('front.shopping.not_available_payment_method');
}
}
}

private function getDeliveries(SaleType $SaleType)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eccube\Tests\Service\PurchaseFlow\Processor;

use Eccube\Entity\Delivery;
use Eccube\Service\PurchaseFlow\Processor\PaymentValidator;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Tests\EccubeTestCase;

class PaymentValidatorTest extends EccubeTestCase
{
/**
* @var PaymentValidator
*/
private $validator;

/**
* @var $Order
*/
private $Order;

protected function setUp(): void
{
parent::setUp();

$deliveryRepository = $this->entityManager->getRepository(Delivery::class);
$this->validator = new PaymentValidator($deliveryRepository);

$Customer = $this->createCustomer();
$this->Order = $this->createOrder($Customer);
}

public function testInstance()
{
self::assertInstanceOf(PaymentValidator::class, $this->validator);
}

public function testValidatePaymentVisibleFalse()
{
$this->Order->getPayment()->setVisible(false);

$result = $this->validator->execute($this->Order, new PurchaseContext());

self::assertTrue($result->isError());
}
}

0 comments on commit b2b8067

Please sign in to comment.