Skip to content

Commit

Permalink
Merge pull request #4997 from yshirai-joolen/no_update_customer_info_…
Browse files Browse the repository at this point in the history
…when_edit_order

受注編集時にすでに受注にセットされている顧客情報を書き換えない
  • Loading branch information
matsuoshi authored Nov 16, 2021
2 parents e955010 + 035b001 commit 705a36f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/Eccube/Form/Type/Admin/OrderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,15 @@ public function copyFields(FormEvent $event)
$Order->setPaymentMethod($Payment->getMethod());
}

// 会員受注の場合、会員の性別/職業/誕生日をエンティティにコピーする
if ($Customer = $Order->getCustomer()) {
$Order->setSex($Customer->getSex());
$Order->setJob($Customer->getJob());
$Order->setBirth($Customer->getBirth());
}

// 新規登録時は, 新規受付ステータスで登録する.
if (null === $Order->getOrderStatus()) {
$Order->setOrderStatus($this->orderStatusRepository->find(OrderStatus::NEW));
// 会員受注の場合、会員の性別/職業/誕生日をエンティティにコピーする
if ($Customer = $Order->getCustomer()) {
$Order->setSex($Customer->getSex());
$Order->setJob($Customer->getJob());
$Order->setBirth($Customer->getBirth());
}
} else {
// 編集時は, mapped => falseで定義しているため, フォームから変更後データを取得する.
$form = $event->getForm();
Expand Down
35 changes: 35 additions & 0 deletions tests/Eccube/Tests/Web/Admin/Order/EditControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Eccube\Common\Constant;
use Eccube\Entity\BaseInfo;
use Eccube\Entity\Customer;
use Eccube\Entity\Master\Job;
use Eccube\Entity\Master\Sex;
use Eccube\Entity\Master\OrderStatus;
use Eccube\Entity\Master\RoundingType;
use Eccube\Entity\Order;
Expand Down Expand Up @@ -608,4 +610,37 @@ public function testChangeOrderItemTaxRate()
self::assertEquals(10, $Order->getProductOrderItems()[0]->getTaxRate());
self::assertEquals(100, $Order->getProductOrderItems()[0]->getTax());
}

public function testRoutingAdminOrderEditPostWithCustomerInfo()
{
$Customer = $this->createCustomer();
$Order = $this->createOrder($Customer);
$Order->setOrderStatus($this->entityManager->find(OrderStatus::class, OrderStatus::NEW));
$Order->setSex(null);
$Order->setJob(null);
$Order->setBirth(null);

$this->entityManager->flush($Order);

$Customer->setSex($this->entityManager->find(Sex::class, 1));
$Customer->setJob($this->entityManager->find(Job::class, 1));
$Customer->setBirth(new \DateTime());
$this->entityManager->flush($Customer);

$formData = $this->createFormData($Customer, $this->Product);
$this->client->request(
'POST',
$this->generateUrl('admin_order_edit', ['id' => $Order->getId()]),
[
'order' => $formData,
'mode' => 'register',
]
);
$this->assertTrue($this->client->getResponse()->isRedirect($this->generateUrl('admin_order_edit', ['id' => $Order->getId()])));

$EditedOrder = $this->orderRepository->find($Order->getId());
$this->assertNull($EditedOrder->getSex());
$this->assertNull($EditedOrder->getJob());
$this->assertNull($EditedOrder->getBirth());
}
}

0 comments on commit 705a36f

Please sign in to comment.