From 75d65de123b03ee5ebf9bb95cc41992810211a31 Mon Sep 17 00:00:00 2001 From: lammn Date: Thu, 7 Jul 2016 16:17:53 +0700 Subject: [PATCH] Fix bug #1596 and add unittest --- src/Eccube/Form/Type/Admin/OrderType.php | 10 +-- .../Web/Admin/Order/EditControllerTest.php | 62 ++++++++++++++++++- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/Eccube/Form/Type/Admin/OrderType.php b/src/Eccube/Form/Type/Admin/OrderType.php index 13c4d4f604b..5be30b7e680 100644 --- a/src/Eccube/Form/Type/Admin/OrderType.php +++ b/src/Eccube/Form/Type/Admin/OrderType.php @@ -257,14 +257,14 @@ public function buildForm(FormBuilderInterface $builder, array $options) $orderDetailsCount = count($orderDetails); $shipmentItemsCount = count($shipmentItems); for ($i = 0; $i < $orderDetailsCount; $i++) { + $orderDetail = &$orderDetails[$i]; + $orderDetail['quantity'] = 0; for ($j = 0; $j < $shipmentItemsCount; $j++) { - $itemidx = &$shipmentItems[$j]['itemidx']; - if ($itemidx == $i) { + $productClass = &$shipmentItems[$j]['ProductClass']; + if ($productClass == $orderDetail['ProductClass']) { $shipmentItem = &$shipmentItems[$j]; $shipmentItem['price'] = $orderDetails[$i]['price']; - $orderDetail = &$orderDetails[$i]; - $orderDetail['quantity'] = $shipmentItems[$j]['quantity']; - break; + $orderDetail['quantity'] += $shipmentItems[$j]['quantity']; } } } diff --git a/tests/Eccube/Tests/Web/Admin/Order/EditControllerTest.php b/tests/Eccube/Tests/Web/Admin/Order/EditControllerTest.php index 1fd31c56ecc..1a70a7e83ca 100644 --- a/tests/Eccube/Tests/Web/Admin/Order/EditControllerTest.php +++ b/tests/Eccube/Tests/Web/Admin/Order/EditControllerTest.php @@ -131,6 +131,61 @@ public function createFormData($Customer, $Product) 'year' => $delivery_date->format('Y'), 'month' => $delivery_date->format('n'), 'day' => $delivery_date->format('j') + ), + 'ShipmentItems' => array( + 0 => array( + 'quantity' => 2, + 'Product' => $Product->getId(), + 'ProductClass' => $ProductClasses[0]->getId(), + 'price' => $ProductClasses[0]->getPrice02(), + "itemidx" => "" + ) + ) + ), + array( + 'name' => array( + 'name01' => $faker->lastName, + 'name02' => $faker->firstName, + ), + 'kana' => array( + 'kana01' => $faker->lastKanaName , + 'kana02' => $faker->firstKanaName, + ), + 'company_name' => $faker->company, + 'zip' => array( + 'zip01' => $faker->postcode1(), + 'zip02' => $faker->postcode2(), + ), + 'address' => array( + 'pref' => '5', + 'addr01' => $faker->city, + 'addr02' => $faker->streetAddress, + ), + 'tel' => array( + 'tel01' => $tel[0], + 'tel02' => $tel[1], + 'tel03' => $tel[2], + ), + 'fax' => array( + 'fax01' => $tel[0], + 'fax02' => $tel[1], + 'fax03' => $tel[2], + ), + 'Delivery' => 1, + 'DeliveryTime' => 1, + 'shipping_delivery_date' => array( + 'year' => $delivery_date->format('Y'), + 'month' => $delivery_date->format('n'), + 'day' => $delivery_date->format('j') + ), + 'ShipmentItems' => array( + 1 => array( + 'quantity' => 1, + 'Product' => $Product->getId(), + 'ProductClass' => $ProductClasses[0]->getId(), + 'price' => $ProductClasses[0]->getPrice02(), + "itemidx" => "" + ) ) ) ) @@ -172,7 +227,7 @@ public function testRoutingAdminOrderEditPost() $Customer = $this->createCustomer(); $Order = $this->createOrder($Customer); $formData = $this->createFormData($Customer, $this->Product); - $this->client->request( + $crawler = $this->client->request( 'POST', $this->app->url('admin_order_edit', array('id' => $Order->getId())), array( @@ -186,6 +241,11 @@ public function testRoutingAdminOrderEditPost() $this->expected = $formData['name']['name01']; $this->actual = $EditedOrder->getName01(); $this->verify(); + + $this->expected = $EditedOrder["OrderDetails"][0]["quantity"]; + $this->actual = 3; + $this->verify(); + } public function testSearchCustomer()