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

受注編集時にすでに受注にセットされている顧客情報を書き換えない #4997

Merged
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
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());
}
}