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

[受注一覧]個別出荷済み処理の実装 #3369

Merged
merged 7 commits into from
Jul 24, 2018
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
47 changes: 44 additions & 3 deletions codeception/_support/Page/Admin/OrderManagePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ public function 検索($value = '')
return $this;
}

public function 詳細検索設定()
{
$this->tester->click(self::$詳細検索ボタン);
$this->tester->waitForElementVisible(['id' => 'searchDetail']);
$this->tester->wait(0.5);
return $this;
}

public function 入力_ご注文者お名前($value)
{
$this->tester->fillField(['id' => 'admin_search_order_name'], $value);
return $this;
}

public function 入力_ご注文者お名前フリガナ($value)
{
$this->tester->fillField(['id' => 'admin_search_order_kana'], $value);
return $this;
}

public function 詳細検索_電話番号($value = '')
{
$this->tester->click(self::$詳細検索ボタン);
Expand Down Expand Up @@ -166,8 +186,29 @@ public function 受注ステータス変更($option = [])
{
$this->tester->selectOption('#option_bulk_status', $option);
$this->tester->click('#form_bulk #btn_bulk_status');
$this->tester->waitForElementVisible('#confirmBulkModal', 5);
$this->tester->click('#confirmBulkModal button[data-action="execute"]');
return $this;
}
}

public function 出荷済にする($rowNum)
{
$this->tester->click("#search_result > tbody > tr:nth-child($rowNum) a[data-type='status']");
$this->tester->waitForElementVisible(['id' => 'sentUpdateModal']);
$this->tester->wait(2);
$this->tester->click(['id' => 'notificationMail']);
$this->tester->scrollTo(['id' => 'bulkChange']);
$this->tester->click(['id' => 'bulkChange']);
$this->tester->wait(5);
$this->tester->waitForElementVisible(['id' => 'bulkChangeComplete']);
return $this;
}

public function 取得_出荷伝票番号($rowNum)
{
return $this->tester->grabValueFrom("#search_result > tbody > tr:nth-child(${rowNum}) > td:nth-child(8) > div > input");
}

public function 取得_出荷日($rowNum)
{
return $this->tester->grabTextFrom("#search_result > tbody > tr:nth-child(${rowNum}) > td:nth-child(7)");
}
}
10 changes: 0 additions & 10 deletions codeception/_support/Page/Admin/ShippingManagePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,4 @@ public function 一覧_チェックボックス($rowNum)
{
$this->tester->click(['xpath' => "//*[@id='form_bulk']/div[2]/div/table/tbody/tr[${rowNum}]/td[1]/input"]);
}

public function 取得_出荷伝票番号($rowNum)
{
return $this->tester->grabTextFrom("#form_bulk table > tbody > tr:nth-child(${rowNum}) > td:nth-child(3)");
}

public function 取得_出荷日($rowNum)
{
return $this->tester->grabTextFrom("#form_bulk table > tbody > tr:nth-child(${rowNum}) > td:nth-child(7)");
}
}
60 changes: 58 additions & 2 deletions codeception/acceptance/EA04OrderCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ public function order_受注登録(\AcceptanceTester $I)

public function order_ー括受注のステータス変更(\AcceptanceTester $I)
{
$I->getScenario()->incomplete('ステータス変更処理の再実装待ち');

$I->wantTo('EA0405-UC06-T01_ー括受注のステータス変更');

// 新規受付ステータスをキャンセルに変更する
Expand Down Expand Up @@ -319,4 +317,62 @@ public function order_ー括受注のステータス変更(\AcceptanceTester $I)
OrderManagePage::go($I)->受注ステータス検索(OrderStatus::DELIVERED);
$I->see('検索結果:'.(count($DeliveredOrders) + count($NewOrders)).'件が該当しました', OrderManagePage::$検索結果_メッセージ);
}

public function order_個別出荷済みステータス変更(\AcceptanceTester $I)
{
$I->wantTo('EA0405-UC06-T02_個別出荷済みステータス変更');

$I->resetEmails();

// 新規受付ステータスをキャンセルに変更する
$entityManager = Fixtures::get('entityManager');
$findOrders = Fixtures::get('findOrders');
$NewOrders = array_filter($findOrders(), function ($Order) {
return $Order->getOrderStatus()->getId() == OrderStatus::NEW;
});
$CancelStatus = $entityManager->getRepository('Eccube\Entity\Master\OrderStatus')->find(OrderStatus::CANCEL);
foreach ($NewOrders as $newOrder) {
$newOrder->setOrderStatus($CancelStatus);
}
$entityManager->flush();

// 新規受付ステータスの受注を作る
$createCustomer = Fixtures::get('createCustomer');
$createOrders = Fixtures::get('createOrders');
$newOrders = $createOrders($createCustomer(), 2, array());
$Status = $entityManager->getRepository('Eccube\Entity\Master\OrderStatus')->find(OrderStatus::NEW);
foreach ($newOrders as $newOrder) {
$newOrder->setOrderStatus($Status);
}
$entityManager->flush();

$DeliveredOrders = array_filter($findOrders(), function ($Order) {
return $Order->getOrderStatus()->getId() == OrderStatus::DELIVERED;
});
OrderManagePage::go($I)->受注ステータス検索(OrderStatus::DELIVERED);
$I->see('検索結果:'.count($DeliveredOrders).'件が該当しました', OrderManagePage::$検索結果_メッセージ);

$NewOrders = array_filter($findOrders(), function ($Order) {
return $Order->getOrderStatus()->getId() == OrderStatus::NEW;
});
OrderManagePage::go($I)->受注ステータス検索(OrderStatus::NEW);
$I->see('検索結果:'.count($NewOrders).'件が該当しました', OrderManagePage::$検索結果_メッセージ);

OrderManagePage::go($I)->受注ステータス検索(OrderStatus::NEW)
->出荷済にする(1);

$I->seeEmailCount(2);
$I->seeInLastEmailSubjectTo('admin@example.com', '[EC-CUBE SHOP] 商品出荷のお知らせ');

OrderManagePage::go($I)->受注ステータス検索(OrderStatus::NEW);
$I->see('検索結果:1件が該当しました', OrderManagePage::$検索結果_メッセージ);
}
}








41 changes: 21 additions & 20 deletions codeception/acceptance/EA09ShippingCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Eccube\Entity\Customer;
use Eccube\Entity\Order;
use Page\Admin\OrderEditPage;
use Page\Admin\OrderManagePage;
use Page\Admin\ShippingCsvUploadPage;
use Page\Admin\ShippingEditPage;
use Page\Admin\ShippingManagePage;
Expand Down Expand Up @@ -219,20 +220,20 @@ public function shipping_出荷CSV登録(\AcceptanceTester $I)
* 出荷再検索 出荷日/伝票番号が登録されていないことを確認
*/

$ShippingManagePage = ShippingManagePage::go($I)
$OrderManagePage = OrderManagePage::go($I)
->詳細検索設定()
->入力_ご注文者お名前($Customer->getName01().$Customer->getName02())
->入力_ご注文者お名前フリガナ($Customer->getKana01().$Customer->getKana02())
->検索();

$I->see('検索結果 : 3 件が該当しました', ShippingManagePage::$検索結果_メッセージ);
$I->see('検索結果:3件が該当しました', OrderManagePage::$検索結果_メッセージ);

$I->assertEquals('未登録', $ShippingManagePage->取得_出荷伝票番号(1));
$I->assertEquals('未登録', $ShippingManagePage->取得_出荷伝票番号(2));
$I->assertEquals('未登録', $ShippingManagePage->取得_出荷伝票番号(3));
$I->assertEquals('-', $ShippingManagePage->取得_出荷日(1));
$I->assertEquals('-', $ShippingManagePage->取得_出荷日(2));
$I->assertEquals('-', $ShippingManagePage->取得_出荷日(3));
$I->assertEmpty($OrderManagePage->取得_出荷伝票番号(1));
$I->assertEmpty($OrderManagePage->取得_出荷伝票番号(2));
$I->assertEmpty($OrderManagePage->取得_出荷伝票番号(3));
$I->assertEquals('未発送', $OrderManagePage->取得_出荷日(1));
$I->assertEquals('未発送', $OrderManagePage->取得_出荷日(2));
$I->assertEquals('未発送', $OrderManagePage->取得_出荷日(3));

/*
* 出荷CSV登録
Expand Down Expand Up @@ -260,20 +261,20 @@ public function shipping_出荷CSV登録(\AcceptanceTester $I)
* 出荷再検索 出荷日/伝票番号が登録されたことを確認
*/

$ShippingManagePage = ShippingManagePage::go($I)
->詳細検索設定()
->入力_ご注文者お名前($Customer->getName01().$Customer->getName02())
->入力_ご注文者お名前フリガナ($Customer->getKana01().$Customer->getKana02())
->検索();
$OrderManagePage = OrderManagePage::go($I)
->詳細検索設定()
->入力_ご注文者お名前($Customer->getName01().$Customer->getName02())
->入力_ご注文者お名前フリガナ($Customer->getKana01().$Customer->getKana02())
->検索();

$I->see('検索結果 : 3 件が該当しました', ShippingManagePage::$検索結果_メッセージ);
$I->see('検索結果:3件が該当しました', OrderManagePage::$検索結果_メッセージ);

$I->assertEquals('00003', $ShippingManagePage->取得_出荷伝票番号(1));
$I->assertEquals('00002', $ShippingManagePage->取得_出荷伝票番号(2));
$I->assertEquals('00001', $ShippingManagePage->取得_出荷伝票番号(3));
$I->assertEquals('2018/03/03', $ShippingManagePage->取得_出荷日(1));
$I->assertEquals('2018/02/02', $ShippingManagePage->取得_出荷日(2));
$I->assertEquals('2018/01/01', $ShippingManagePage->取得_出荷日(3));
$I->assertEquals('00003', $OrderManagePage->取得_出荷伝票番号(1));
$I->assertEquals('00002', $OrderManagePage->取得_出荷伝票番号(2));
$I->assertEquals('00001', $OrderManagePage->取得_出荷伝票番号(3));
$I->assertEquals('2018/03/03', $OrderManagePage->取得_出荷日(1));
$I->assertEquals('2018/02/02', $OrderManagePage->取得_出荷日(2));
$I->assertEquals('2018/01/01', $OrderManagePage->取得_出荷日(3));

} finally {
if (file_exists($csvFileName)) {
Expand Down
116 changes: 24 additions & 92 deletions src/Eccube/Controller/Admin/Order/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Eccube\Repository\OrderRepository;
use Eccube\Repository\PaymentRepository;
use Eccube\Service\CsvExportService;
use Eccube\Service\MailService;
use Eccube\Service\OrderStateMachine;
use Eccube\Util\FormUtil;
use Knp\Component\Pager\PaginatorInterface;
Expand All @@ -43,9 +44,7 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Eccube\Entity\Order;
use Eccube\Entity\Shipping;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\PurchaseFlow\PurchaseFlow;
use Eccube\Service\PurchaseFlow\PurchaseException;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Validator\ValidatorInterface;

Expand Down Expand Up @@ -106,6 +105,11 @@ class OrderController extends AbstractController
*/
protected $orderStateMachine;

/**
* @var MailService
*/
protected $mailService;

/**
* OrderController constructor.
*
Expand All @@ -118,7 +122,8 @@ class OrderController extends AbstractController
* @param PageMaxRepository $pageMaxRepository
* @param ProductStatusRepository $productStatusRepository
* @param OrderRepository $orderRepository
* @param OrderStateMachine $orderStateMachine;
* @param OrderStateMachine $orderStateMachine
* @param MailService $mailService
*/
public function __construct(
PurchaseFlow $orderPurchaseFlow,
Expand All @@ -131,7 +136,8 @@ public function __construct(
ProductStatusRepository $productStatusRepository,
OrderRepository $orderRepository,
ValidatorInterface $validator,
OrderStateMachine $orderStateMachine
OrderStateMachine $orderStateMachine,
MailService $mailService
) {
$this->purchaseFlow = $orderPurchaseFlow;
$this->csvExportService = $csvExportService;
Expand All @@ -144,6 +150,7 @@ public function __construct(
$this->orderRepository = $orderRepository;
$this->validator = $validator;
$this->orderStateMachine = $orderStateMachine;
$this->mailService = $mailService;
}

/**
Expand Down Expand Up @@ -452,14 +459,27 @@ public function updateOrderStatus(Request $request, Shipping $Shipping)
$Order = $Shipping->getOrder();
$OrderStatus = $this->entityManager->find(OrderStatus::class, $request->get('order_status'));

if (!$OrderStatus) {
return $this->json(['status' => 'NG'], 400);
}

$result = [];
try {
// 発送済みに変更された場合は、関連する出荷がすべて出荷済みになったら OrderStatus を変更する
if (OrderStatus::DELIVERED == $OrderStatus->getId()) {
if (!$Shipping->getShippingDate()) {
$Shipping->setShippingDate(new \DateTime());

if ($request->get('notificationMail')) { // for SimpleStatusUpdate
$this->mailService->sendShippingNotifyMail($Shipping);
$Shipping->setMailSendDate(new \DateTime());
$result['mail'] = true;
} else {
$result['mail'] = false;
}
$this->entityManager->flush($Shipping);
}

$RelateShippings = $Order->getShippings();
$allShipped = true;
foreach ($RelateShippings as $RelateShipping) {
Expand Down Expand Up @@ -503,94 +523,6 @@ public function updateOrderStatus(Request $request, Shipping $Shipping)
return $this->json(array_merge(['status' => 'OK'], $result));
}

/**
* Bulk action to order status
*
* @Method("POST")
* @Route("/%eccube_admin_route%/order/bulk/order-status/{id}", requirements={"id" = "\d+"}, name="admin_order_bulk_order_status")
*
* @param Request $request
* @param OrderStatus $OrderStatus
*
* @return RedirectResponse
*
* @deprecated 使用していない
*/
public function bulkOrderStatus(Request $request, OrderStatus $OrderStatus)
{
$this->isTokenValid();

/** @var Order[] $Orders */
$Orders = $this->orderRepository->findBy(['id' => $request->get('ids')]);

$count = 0;
foreach ($Orders as $Order) {
try {
// TODO: should support event for plugin customize
// 編集前の受注情報を保持
$OriginOrder = clone $Order;

$Order->setOrderStatus($OrderStatus);

$purchaseContext = new PurchaseContext($OriginOrder, $OriginOrder->getCustomer());

$flowResult = $this->purchaseFlow->validate($Order, $purchaseContext);
if ($flowResult->hasWarning()) {
foreach ($flowResult->getWarning() as $warning) {
$msg = $this->translator->trans('admin.order.index.bulk_warning', [
'%orderId%' => $Order->getId(),
'%message%' => $warning->getMessage(),
]);
$this->addWarning($msg, 'admin');
}
}

if ($flowResult->hasError()) {
foreach ($flowResult->getErrors() as $error) {
$msg = $this->translator->trans('admin.order.index.bulk_error', [
'%orderId%' => $Order->getId(),
'%message%' => $error->getMessage(),
]);
$this->addError($msg, 'admin');
}
continue;
}

try {
$this->purchaseFlow->commit($Order, $purchaseContext);
} catch (PurchaseException $e) {
$msg = $this->translator->trans('admin.order.index.bulk_error', [
'%orderId%' => $Order->getId(),
'%message%' => $e->getMessage(),
]);
$this->addError($msg, 'admin');
continue;
}

$this->orderRepository->save($Order);

$count++;
} catch (\Exception $e) {
$this->addError('#'.$Order->getId().': '.$e->getMessage(), 'admin');
}
}
try {
if ($count) {
$this->entityManager->flush();
$msg = $this->translator->trans('admin.order.index.bulk_order_status_success_count', [
'%count%' => $count,
'%status%' => $OrderStatus->getName(),
]);
$this->addSuccess($msg, 'admin');
}
} catch (\Exception $e) {
log_error('Bulk order status error', [$e]);
$this->addError('admin.flash.register_failed', 'admin');
}

return $this->redirectToRoute('admin_order', ['resume' => Constant::ENABLED]);
}

/**
* Update to Tracking number.
*
Expand Down
Loading