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

受注編集の画面で、金額にエラーがあると、課税区分のカッコ内が表示されなくなる 不具合の修正 #5761

Merged
merged 12 commits into from
Jul 20, 2023
6 changes: 6 additions & 0 deletions src/Eccube/Controller/Admin/Order/EditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ public function index(Request $request, RouterInterface $router, $id = null)

$form->handleRequest($request);
$purchaseContext = new PurchaseContext($OriginOrder, $OriginOrder->getCustomer());

foreach ($TargetOrder->getOrderItems() as $orderItem) {
if ($orderItem->getTaxDisplayType() == null) {
$orderItem->setTaxDisplayType($this->orderHelper->getTaxDisplayType($orderItem->getOrderItemType()));
}
}

if ($form->isSubmitted() && $form['OrderItems']->isValid()) {
$event = new EventArgs(
Expand Down
36 changes: 36 additions & 0 deletions src/Eccube/Service/OrderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Eccube\Entity\Order;
use Eccube\Entity\OrderItem;
use Eccube\Entity\Shipping;
use Eccube\Entity\Master\TaxDisplayType;
use Eccube\EventListener\SecurityListener;
use Eccube\Repository\DeliveryRepository;
use Eccube\Repository\Master\DeviceTypeRepository;
Expand Down Expand Up @@ -528,4 +529,39 @@ private function getUser(): ?UserInterface

return $user;
}

/**
* 税表示区分を取得する.
*
* - 商品: 税抜
* - 送料: 税込
* - 値引き: 税抜
* - 手数料: 税込
* - ポイント値引き: 税込
*
* @param $OrderItemType
*
* @return TaxDisplayType
*/
public function getTaxDisplayType($OrderItemType)
{
if ($OrderItemType instanceof OrderItemType) {
$OrderItemType = $OrderItemType->getId();
}

switch ($OrderItemType) {
case OrderItemType::PRODUCT:
return $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::EXCLUDED);
case OrderItemType::DELIVERY_FEE:
return $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::INCLUDED);
case OrderItemType::DISCOUNT:
return $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::EXCLUDED);
case OrderItemType::CHARGE:
return $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::INCLUDED);
case OrderItemType::POINT:
return $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::INCLUDED);
default:
return $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::EXCLUDED);
}
}
}
34 changes: 13 additions & 21 deletions src/Eccube/Service/PurchaseFlow/Processor/TaxProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Eccube\Service\PurchaseFlow\ItemHolderPreprocessor;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\TaxRuleService;
use Eccube\Service\OrderHelper;

class TaxProcessor implements ItemHolderPreprocessor
{
Expand All @@ -41,6 +42,11 @@ class TaxProcessor implements ItemHolderPreprocessor
*/
protected $taxRuleService;

/**
* @var OrderHelper
*/
protected $orderHelper;

/**
* TaxProcessor constructor.
*
Expand All @@ -50,11 +56,13 @@ class TaxProcessor implements ItemHolderPreprocessor
public function __construct(
EntityManagerInterface $entityManager,
TaxRuleRepository $taxRuleRepository,
TaxRuleService $taxRuleService
TaxRuleService $taxRuleService,
OrderHelper $orderHelper
) {
$this->entityManager = $entityManager;
$this->taxRuleRepository = $taxRuleRepository;
$this->taxRuleService = $taxRuleService;
$this->orderHelper = $orderHelper;
}

/**
Expand All @@ -77,7 +85,7 @@ public function process(ItemHolderInterface $itemHolder, PurchaseContext $contex
$item->setTaxType($this->getTaxType($OrderItemType));
}
if (!$item->getTaxDisplayType()) {
$item->setTaxDisplayType($this->getTaxDisplayType($OrderItemType));
$item->setTaxDisplayType($this->orderHelper->getTaxDisplayType($OrderItemType));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shinya
phpstanの指摘修正お願いします。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

メンバ変数の宣言が漏れている、という指摘であってますでしょうか?
そちら反映いたしました(認識違いあればおっしゃってください。)

}

// 税区分: 非課税, 不課税
Expand Down Expand Up @@ -152,28 +160,12 @@ protected function getTaxType($OrderItemType)
* - ポイント値引き: 税込
*
* @param $OrderItemType
* @deprecated OrderHelper::getTaxDisplayTypeを使用してください
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecatedのアノテーションを追加お願いします。
以下のように記載いただければ。

@deprecated OrderHelper::getTaxDisplayTypeを使用してください

* @return TaxType
* @return TaxDisplayType
*/
protected function getTaxDisplayType($OrderItemType)
kiy0taka marked this conversation as resolved.
Show resolved Hide resolved
{
if ($OrderItemType instanceof OrderItemType) {
$OrderItemType = $OrderItemType->getId();
}

switch ($OrderItemType) {
case OrderItemType::PRODUCT:
return $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::EXCLUDED);
case OrderItemType::DELIVERY_FEE:
return $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::INCLUDED);
case OrderItemType::DISCOUNT:
return $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::EXCLUDED);
case OrderItemType::CHARGE:
return $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::INCLUDED);
case OrderItemType::POINT:
return $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::INCLUDED);
default:
return $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::EXCLUDED);
}
return $this->orderHelper->getTaxDisplayType($OrderItemType);
}
}
32 changes: 32 additions & 0 deletions tests/Eccube/Tests/Service/OrderHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
use Eccube\Entity\Order;
use Eccube\Service\OrderHelper;
use Eccube\Tests\EccubeTestCase;
use Eccube\Entity\Master\TaxDisplayType;
use Eccube\Entity\Master\OrderItemType;


class OrderHelperTest extends EccubeTestCase
{
Expand Down Expand Up @@ -69,4 +72,33 @@ public function testUpdateCustomerInfoNewCustomer()
self::assertNotNull($Order->getName01());
self::assertSame($Order->getName01(), $Customer->getName01());
}

/**
* 税表示区分が問題ないかを確認する
* @dataProvider taxDisplayTypeProvider
*/
public function testTaxDisplayType($OrderItemType, $TaxDisplayType)
{
$TaxDisplayType = $this->entityManager->find(TaxDisplayType::class, $TaxDisplayType);

self::assertSame($this->helper->getTaxDisplayType($OrderItemType), $TaxDisplayType);
}

public function taxDisplayTypeProvider()
{
// - 商品: 税抜
// - 送料: 税込
// - 手数料: 税込
// - 値引き: 税抜
// - 税: 税抜
// - ポイント値引き: 税込
return [
[OrderItemType::PRODUCT, TaxDisplayType::EXCLUDED],
[OrderItemType::DELIVERY_FEE, TaxDisplayType::INCLUDED],
[OrderItemType::CHARGE, TaxDisplayType::INCLUDED],
[OrderItemType::DISCOUNT, TaxDisplayType::EXCLUDED],
[OrderItemType::TAX, TaxDisplayType::EXCLUDED],
[OrderItemType::POINT, TaxDisplayType::INCLUDED],
];
}
}
Loading