diff --git a/src/Eccube/Form/Type/Admin/OrderType.php b/src/Eccube/Form/Type/Admin/OrderType.php index aab4d779ad5..dc60a6dee7e 100644 --- a/src/Eccube/Form/Type/Admin/OrderType.php +++ b/src/Eccube/Form/Type/Admin/OrderType.php @@ -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(); diff --git a/tests/Eccube/Tests/Web/Admin/Order/EditControllerTest.php b/tests/Eccube/Tests/Web/Admin/Order/EditControllerTest.php index a65cbfd48ae..d8c3a2f0ac2 100644 --- a/tests/Eccube/Tests/Web/Admin/Order/EditControllerTest.php +++ b/tests/Eccube/Tests/Web/Admin/Order/EditControllerTest.php @@ -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; @@ -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()); + } }