Skip to content
Closed
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
91 changes: 89 additions & 2 deletions src/Eccube/Controller/Admin/Order/EditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace Eccube\Controller\Admin\Order;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\DBAL\LockMode;
use Eccube\Application;
use Eccube\Common\Constant;
use Eccube\Controller\AbstractController;
Expand Down Expand Up @@ -67,6 +68,7 @@ public function index(Application $app, Request $request, $id = null)
// 編集前の受注情報を保持
$OriginOrder = clone $TargetOrder;
$OriginalOrderDetails = new ArrayCollection();
$tempOriginalOrderDetails = new ArrayCollection();
// 編集前のお届け先情報を保持
$OriginalShippings = new ArrayCollection();
// 編集前のお届け先のアイテム情報を保持
Expand All @@ -81,6 +83,10 @@ public function index(Application $app, Request $request, $id = null)
$arrOldOrder['OrderDetails'][$OrderDetail->getId()]['quantity'] = $OrderDetail->getQuantity();
}

foreach ($TargetOrder->getOrderDetails() as $OrderDetail) {
$tempOriginalOrderDetails->add(clone $OrderDetail);
}

// 編集前の情報を保持
/** @var $tmpOriginalShippings Shipping*/
foreach ($TargetOrder->getShippings() as $key => $tmpOriginalShippings) {
Expand Down Expand Up @@ -134,10 +140,55 @@ public function index(Application $app, Request $request, $id = null)

log_info('受注登録開始', array($TargetOrder->getId()));

// 在庫チェック時の数量を取得
$stockQuantity = function ($orderDetail) use ($app, $tempOriginalOrderDetails) {
// 在庫チェック
// 在庫が無制限かチェックし、制限ありなら在庫数をチェック
if ($orderDetail->getProductClass()->getStockUnlimited() == Constant::DISABLED) {

$quantity = $orderDetail->getQuantity();

// 在庫チェックあり
// 在庫に対してロック(select ... for update)を実行
$productStock = $app['eccube.repository.product_stock']->find(
$orderDetail->getProductClass()->getProductStock()->getId(), LockMode::PESSIMISTIC_WRITE
);

foreach ($tempOriginalOrderDetails as $o) {
if ($orderDetail->getId() == $o->getId()) {
$quantity = $quantity - $o->getQuantity();
break;
}
}

return array(
'quantity' => $quantity,
'productStock' => $productStock,
);
}

return null;
};

// 在庫チェック
foreach ($TargetOrder->getOrderDetails() as $key => $orderDetail) {

$stock = $stockQuantity($orderDetail);

if ($stock) {
// 購入数量と在庫数をチェックして在庫がなければエラー
if ($stock['quantity'] > $stock['productStock']->getStock()) {
$form['OrderDetails'][$key]['quantity']->addError(new FormError($orderDetail->getProduct()->getName().'の在庫がありません。'));
}
}
}

if ($TargetOrder->getTotal() > $app['config']['max_total_fee']) {
log_info('受注登録入力チェックエラー', array($TargetOrder->getId()));
$form['charge']->addError(new FormError('合計金額の上限を超えております。'));
} elseif ($form->isValid()) {
}

if ($form->isValid()) {

$BaseInfo = $app['eccube.repository.base_info']->get();

Expand All @@ -160,8 +211,12 @@ public function index(Application $app, Request $request, $id = null)
$this->updateDate($app, $TargetOrder, $OriginOrder);

// 受注明細で削除されているものをremove
foreach ($OriginalOrderDetails as $OrderDetail) {
$removeOrderDetail = new ArrayCollection();
foreach ($OriginalOrderDetails as $key => $OrderDetail) {
if (false === $TargetOrder->getOrderDetails()->contains($OrderDetail)) {
$removeOrderDetail->add(clone $OrderDetail);
$OriginalOrderDetails->remove($key);
$tempOriginalOrderDetails->remove($key);
$app['orm.em']->remove($OrderDetail);
}
}
Expand Down Expand Up @@ -244,6 +299,38 @@ public function index(Application $app, Request $request, $id = null)
$TargetOrder->setBirth($Customer->getBirth());
}

// 在庫情報更新
foreach ($TargetOrder->getOrderDetails() as $orderDetail) {

$stock = $stockQuantity($orderDetail);

if ($stock) {
// 在庫情報の在庫数を更新
$quantity = $stock['productStock']->getStock() - $stock['quantity'];
$stock['productStock']->setStock($quantity);

// 商品規格情報の在庫数を更新
$orderDetail->getProductClass()->setStock($quantity);
}

}

// 削除された受注明細の在庫情報更新
foreach ($removeOrderDetail as $orderDetail) {

$stock = $stockQuantity($orderDetail);

if ($stock) {
// 在庫情報の在庫数を更新
$quantity = $stock['productStock']->getStock() + $stock['quantity'];
$stock['productStock']->setStock($quantity);

// 商品規格情報の在庫数を更新
$orderDetail->getProductClass()->setStock($quantity);
}

}

$app['orm.em']->persist($TargetOrder);
$app['orm.em']->flush();

Expand Down
32 changes: 28 additions & 4 deletions src/Eccube/Controller/Admin/Order/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace Eccube\Controller\Admin\Order;

use Doctrine\DBAL\LockMode;
use Eccube\Application;
use Eccube\Common\Constant;
use Eccube\Controller\AbstractController;
Expand Down Expand Up @@ -173,13 +174,36 @@ public function delete(Application $app, Request $request, $id)

if (!$Order) {
$app->deleteMessage();

return $app->redirect($app->url('admin_order_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED);
}

log_info('受注削除開始', array($Order->getId()));

$Order->setDelFlg(Constant::ENABLED);

// 削除された受注明細の在庫情報更新
foreach ($Order->getOrderDetails() as $orderDetail) {

if ($orderDetail->getProductClass()->getStockUnlimited() == Constant::DISABLED) {

$quantity = $orderDetail->getQuantity();

// 在庫チェックあり
// 在庫に対してロック(select ... for update)を実行
$productStock = $app['eccube.repository.product_stock']->find(
$orderDetail->getProductClass()->getProductStock()->getId(), LockMode::PESSIMISTIC_WRITE
);

// 在庫情報の在庫数を更新
$quantity = $productStock->getStock() + $quantity;
$productStock->setStock($quantity);

// 商品規格情報の在庫数を更新
$orderDetail->getProductClass()->setStock($quantity);
}
}

$app['orm.em']->persist($Order);
$app['orm.em']->flush();

Expand Down Expand Up @@ -279,9 +303,9 @@ public function exportOrder(Application $app, Request $request)
});

$now = new \DateTime();
$filename = 'order_' . $now->format('YmdHis') . '.csv';
$filename = 'order_'.$now->format('YmdHis').'.csv';
$response->headers->set('Content-Type', 'application/octet-stream');
$response->headers->set('Content-Disposition', 'attachment; filename=' . $filename);
$response->headers->set('Content-Disposition', 'attachment; filename='.$filename);
$response->send();

log_info('受注CSV出力ファイル名', array($filename));
Expand Down Expand Up @@ -370,9 +394,9 @@ public function exportShipping(Application $app, Request $request)
});

$now = new \DateTime();
$filename = 'shipping_' . $now->format('YmdHis') . '.csv';
$filename = 'shipping_'.$now->format('YmdHis').'.csv';
$response->headers->set('Content-Type', 'application/octet-stream');
$response->headers->set('Content-Disposition', 'attachment; filename=' . $filename);
$response->headers->set('Content-Disposition', 'attachment; filename='.$filename);
$response->send();

log_info('配送CSV出力ファイル名', array($filename));
Expand Down
6 changes: 5 additions & 1 deletion src/Eccube/Entity/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ public function _calc()
if ($ProductClass->getClassCategory1()) {
$classCategoryId1 = $ProductClass->getClassCategory1()->getId();
if (!empty($classCategoryId1)) {
$this->classCategories1[$ProductClass->getClassCategory1()->getId()] = $ProductClass->getClassCategory1()->getName();
if ($ProductClass->getClassCategory2()) {
// 規格2が存在する時、規格1に品切れ中は表示しない
$this->classCategories1[$ProductClass->getClassCategory1()->getId()] = $ProductClass->getClassCategory1()->getName();
$this->classCategories2[$ProductClass->getClassCategory1()->getId()][$ProductClass->getClassCategory2()->getId()] = $ProductClass->getClassCategory2()->getName();
} else {
// 規格1のみが存在する時、品切れ中を表示
$this->classCategories1[$ProductClass->getClassCategory1()->getId()] = $ProductClass->getClassCategory1()->getName() . ($ProductClass->getStockFind() ? '' : ' (品切れ中)');
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Eccube/Form/Type/Admin/OrderType.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$form = $event->getForm();
$orderDetails = $form['OrderDetails']->getData();
if (empty($orderDetails) || count($orderDetails) < 1) {
// 画面下部にエラーメッセージを表示させる
$form['charge']->addError(new FormError('商品が追加されていません。'));
// 画面にエラーメッセージを表示させる
$form->addError(new FormError('商品が追加されていません。'));
}
});
}
Expand Down
10 changes: 7 additions & 3 deletions src/Eccube/Form/Type/Admin/ShippingType.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use Doctrine\ORM\EntityRepository;
use Eccube\Common\Constant;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
Expand Down Expand Up @@ -145,6 +144,11 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'format' => 'yyyy-MM-dd',
'required' => false,
))
// エラーメッセージ表示用(画面上ではform_errorsのみ定義)
->add('shipping_error', 'text', array(
'required' => false,
'mapped' => false,
))
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($BaseInfo) {
if ($BaseInfo->getOptionMultipleShipping() == Constant::ENABLED) {
$form = $event->getForm();
Expand Down Expand Up @@ -218,8 +222,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$shipmentItems = $form['ShipmentItems']->getData();

if (empty($shipmentItems) || count($shipmentItems) < 1) {
// 画面下部にエラーメッセージを表示させる
$form['shipping_delivery_date']->addError(new FormError('商品が追加されていません。'));
// 画面にエラーメッセージを表示させる
$form['shipping_error']->addError(new FormError('商品が追加されていません。'));
}
}
});
Expand Down
Loading