Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/experimental/sf' into feat-adm…
Browse files Browse the repository at this point in the history
…in-multi-shipping

# Conflicts:
#	src/Eccube/Controller/Admin/Order/OrderController.php
  • Loading branch information
okazy committed Jul 24, 2018
2 parents 36f23bb + 93516f7 commit 2061933
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 33 deletions.
43 changes: 12 additions & 31 deletions src/Eccube/Controller/Admin/Order/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,12 @@ public function updateOrderStatus(Request $request, Shipping $Shipping)

$result = [];
try {
// 発送済みに変更された場合は、関連する出荷がすべて出荷済みになったら OrderStatus を変更する
if (OrderStatus::DELIVERED == $OrderStatus->getId()) {
if (!$Shipping->getShippingDate()) {
$Shipping->setShippingDate(new \DateTime());
if ($Order->getOrderStatus()->getId() == $OrderStatus->getId()) {
log_info('対応状況一括変更スキップ');
$result = ['message' => sprintf('%s: ステータス変更をスキップしました', $Shipping->getId())];
} else {
if ($this->orderStateMachine->can($Order, $OrderStatus)) {
$this->orderStateMachine->apply($Order, $OrderStatus);

if ($request->get('notificationMail')) { // for SimpleStatusUpdate
$this->mailService->sendShippingNotifyMail($Shipping);
Expand All @@ -478,42 +480,21 @@ public function updateOrderStatus(Request $request, Shipping $Shipping)
$result['mail'] = false;
}
$this->entityManager->flush($Shipping);
}
$this->entityManager->flush($Order);

$RelateShippings = $Order->getShippings();
$allShipped = true;
foreach ($RelateShippings as $RelateShipping) {
if (!$RelateShipping->getShippingDate()) {
$allShipped = false;
break;
}
}
if ($allShipped) {
if ($this->orderStateMachine->can($Order, $OrderStatus)) {
$this->orderStateMachine->apply($Order, $OrderStatus);
} else {
$from = $Order->getOrderStatus()->getName();
$to = $OrderStatus->getName();
$result = ['message' => sprintf('%s: %s から %s へのステータス変更はできません', $Shipping->getId(), $from, $to)];
// 会員の場合、購入回数、購入金額などを更新
if ($Customer = $Order->getCustomer()) {
$this->orderRepository->updateOrderSummary($Customer);
$this->entityManager->flush($Customer);
}
}
} else {
if ($this->orderStateMachine->can($Order, $OrderStatus)) {
$this->orderStateMachine->apply($Order, $OrderStatus);
} else {
$from = $Order->getOrderStatus()->getName();
$to = $OrderStatus->getName();
$result = ['message' => sprintf('%s: %s から %s へのステータス変更はできません', $Shipping->getId(), $from, $to)];
}
}
$this->entityManager->flush($Order);

// 会員の場合、購入回数、購入金額などを更新
if ($Customer = $Order->getCustomer()) {
$this->orderRepository->updateOrderSummary($Customer);
$this->entityManager->flush($Customer);
log_info('対応状況一括変更処理完了', [$Order->getId()]);
}
log_info('対応状況一括変更処理完了', [$Order->getId()]);
} catch (\Exception $e) {
log_error('予期しないエラーです', [$e->getMessage()]);

Expand Down
6 changes: 4 additions & 2 deletions src/Eccube/Service/OrderStateMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ public function updateShippingDate(Event $event)
/* @var Order $Order */
$Order = $event->getSubject();
foreach ($Order->getShippings() as $Shipping) {
$Shipping->setShippingDate(new \DateTime());
if (!$Shipping->getShippingDate()) {
$Shipping->setShippingDate(new \DateTime());
}
}
}

Expand Down Expand Up @@ -242,7 +244,7 @@ public function onCompleted(Event $event)

// XXX このまま EntityManager::flush() をコールすると、 OrderStatus::id が更新されてしまうため元に戻す
$TransitionlStatus = $Order->getOrderStatus();
$this->entityManager->detach($TransitionlStatus);
$this->entityManager->refresh($TransitionlStatus);

$CompletedOrderStatus = $this->orderStatusRepository->find($OrderStatusId);
$Order->setOrderStatus($CompletedOrderStatus);
Expand Down

0 comments on commit 2061933

Please sign in to comment.