Skip to content

Commit

Permalink
Fix bug EC-CUBE#1596 and add unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
lammn committed Jul 7, 2016
1 parent 7e8d72e commit 75d65de
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Eccube/Form/Type/Admin/OrderType.php
Expand Up @@ -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'];
}
}
}
Expand Down
62 changes: 61 additions & 1 deletion tests/Eccube/Tests/Web/Admin/Order/EditControllerTest.php
Expand Up @@ -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" => ""
)
)
)
)
Expand Down Expand Up @@ -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(
Expand All @@ -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()
Expand Down

0 comments on commit 75d65de

Please sign in to comment.