Skip to content

Commit

Permalink
赤電対応
Browse files Browse the repository at this point in the history
  • Loading branch information
chihiro-adachi committed Jul 20, 2018
1 parent c366299 commit e77a1e4
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 586 deletions.
179 changes: 12 additions & 167 deletions src/Eccube/Controller/Admin/Order/EditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
use Eccube\Controller\AbstractController;
use Eccube\Entity\Customer;
use Eccube\Entity\Master\CustomerStatus;
use Eccube\Entity\Master\DeviceType;
use Eccube\Entity\Master\OrderItemType;
use Eccube\Entity\Master\OrderStatus;
use Eccube\Entity\Order;
use Eccube\Entity\Shipping;
use Eccube\Event\EccubeEvents;
Expand Down Expand Up @@ -158,15 +156,14 @@ public function index(Request $request, $id = null)
{
$TargetOrder = null;
$OriginOrder = null;
$isNewOrder = false;

if (is_null($id)) {
if (null === $id) {
// 空のエンティティを作成.
$TargetOrder = $this->newOrder();
$isNewOrder = true;
$TargetOrder = new Order();
$TargetOrder->addShipping((new Shipping())->setOrder($TargetOrder));
} else {
$TargetOrder = $this->orderRepository->find($id);
if (is_null($TargetOrder)) {
if (null === $TargetOrder) {
throw new NotFoundHttpException();
}
}
Expand Down Expand Up @@ -203,14 +200,14 @@ public function index(Request $request, $id = null)
$form = $builder->getForm();

// 単数配送の場合は配送先の編集ができる
if ($TargetOrder->isMultiple() == false) {
if (!$TargetOrder->isMultiple()) {
$form['Shipping']->setData($TargetOrder->getShippings()[0]);
}

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

if ($form->isSubmitted()) {
if ($form->isSubmitted() && $form['OrderItems']->isValid()) {
$event = new EventArgs(
[
'builder' => $builder,
Expand All @@ -223,9 +220,9 @@ public function index(Request $request, $id = null)
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_INDEX_PROGRESS, $event);

$flowResult = $this->purchaseFlow->validate($TargetOrder, $purchaseContext);

if ($flowResult->hasWarning()) {
foreach ($flowResult->getWarning() as $warning) {
// TODO Warning の場合の処理
$this->addWarning($warning->getMessage(), 'admin');
}
}
Expand All @@ -241,7 +238,7 @@ public function index(Request $request, $id = null)
case 'register':
log_info('受注登録開始', [$TargetOrder->getId()]);

if ($flowResult->hasError() === false && $form->isValid()) {
if (!$flowResult->hasError() && $form->isValid()) {
try {
$this->purchaseFlow->prepare($TargetOrder, $purchaseContext);
$this->purchaseFlow->commit($TargetOrder, $purchaseContext);
Expand Down Expand Up @@ -289,21 +286,6 @@ public function index(Request $request, $id = null)
}

break;

case 'add_delivery':
// お届け先情報の新規追加

$form = $builder->getForm();

$Shipping = new Shipping();
$TargetOrder->addShipping($Shipping);

$Shipping->setOrder($TargetOrder);

$form->setData($TargetOrder);

break;

default:
break;
}
Expand Down Expand Up @@ -361,69 +343,6 @@ public function index(Request $request, $id = null)
];
}

/**
* 顧客情報を検索する.
*
* @Route("/%eccube_admin_route%/order/search/customer", name="admin_order_search_customer")
*
* @param Request $request
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function searchCustomer(Request $request)
{
if ($request->isXmlHttpRequest()) {
log_debug('search customer start.');

$searchData = [
'multi' => $request->get('search_word'),
];

$qb = $this->customerRepository->getQueryBuilderBySearchData($searchData);

$event = new EventArgs(
[
'qb' => $qb,
'data' => $searchData,
],
$request
);
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_SEARCH, $event);

/** @var Customer[] $Customers */
$Customers = $qb->getQuery()->getResult();

if (empty($Customers)) {
log_debug('search customer not found.');
}

$data = [];
$formatName = '%s%s(%s%s)';
foreach ($Customers as $Customer) {
$data[] = [
'id' => $Customer->getId(),
'name' => sprintf($formatName, $Customer->getName01(), $Customer->getName02(),
$Customer->getKana01(),
$Customer->getKana02()),
'phone_number' => $Customer->getPhoneNumber(),
'email' => $Customer->getEmail(),
];
}

$event = new EventArgs(
[
'data' => $data,
'Customers' => $Customers,
],
$request
);
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_ORDER_EDIT_SEARCH_CUSTOMER_COMPLETE, $event);
$data = $event->getArgument('data');

return $this->json($data);
}
}

/**
* 顧客情報を検索する.
*
Expand All @@ -438,7 +357,7 @@ public function searchCustomer(Request $request)
*/
public function searchCustomerHtml(Request $request, $page_no = null, Paginator $paginator)
{
if ($request->isXmlHttpRequest()) {
if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
log_debug('search customer start.');
$page_count = $this->eccubeConfig['eccube_default_page_count'];
$session = $this->session;
Expand Down Expand Up @@ -532,7 +451,7 @@ public function searchCustomerHtml(Request $request, $page_no = null, Paginator
*/
public function searchCustomerById(Request $request)
{
if ($request->isXmlHttpRequest()) {
if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
log_debug('search customer by id start.');

/** @var $Customer \Eccube\Entity\Customer */
Expand Down Expand Up @@ -591,7 +510,7 @@ public function searchCustomerById(Request $request)
*/
public function searchProduct(Request $request, $page_no = null, Paginator $paginator)
{
if ($request->isXmlHttpRequest()) {
if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
log_debug('search product start.');
$page_count = $this->eccubeConfig['eccube_default_page_count'];
$session = $this->session;
Expand Down Expand Up @@ -686,7 +605,7 @@ public function searchProduct(Request $request, $page_no = null, Paginator $pagi
*/
public function searchOrderItemType(Request $request)
{
if ($request->isXmlHttpRequest()) {
if ($request->isXmlHttpRequest() && $this->isTokenValid()) {
log_debug('search order item type start.');

$criteria = Criteria::create();
Expand All @@ -713,78 +632,4 @@ public function searchOrderItemType(Request $request)
];
}
}

protected function newOrder()
{
$Order = new Order();
// device type
$DeviceType = $this->deviceTypeRepository->find(DeviceType::DEVICE_TYPE_ADMIN);
$Order->setDeviceType($DeviceType);

$Shipping = new Shipping();
$Order->addShipping($Shipping);
$Shipping->setOrder($Order);

return $Order;
}

/**
* 受注ステータスに応じて, 受注日/入金日/発送日を更新する,
* 発送済ステータスが設定された場合は, お届け先情報の発送日も更新を行う.
*
* 編集の場合
* - 受注ステータスが他のステータスから発送済へ変更された場合に発送日を更新
* - 受注ステータスが他のステータスから入金済へ変更された場合に入金日を更新
*
* 新規登録の場合
* - 受注日を更新
* - 受注ステータスが発送済に設定された場合に発送日を更新
* - 受注ステータスが入金済に設定された場合に入金日を更新
*
* @param $app
* @param $TargetOrder
* @param $OriginOrder
*
* TODO Service へ移動する
*/
protected function updateDate($app, $TargetOrder, $OriginOrder)
{
$dateTime = new \DateTime();

// 編集
if ($TargetOrder->getId()) {
// 発送済
if ($TargetOrder->getOrderStatus()->getId() == OrderStatus::DELIVERED) {
// 編集前と異なる場合のみ更新
if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
// お届け先情報の発送日も更新する.
$Shippings = $TargetOrder->getShippings();
foreach ($Shippings as $Shipping) {
$Shipping->setShippingDate($dateTime);
}
}
// 入金済
} elseif ($TargetOrder->getOrderStatus()->getId() == OrderStatus::PAID) {
// 編集前と異なる場合のみ更新
if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
$TargetOrder->setPaymentDate($dateTime);
}
}
// 新規
} else {
// 発送済
if ($TargetOrder->getOrderStatus()->getId() == OrderStatus::DELIVERED) {
// お届け先情報の発送日も更新する.
$Shippings = $TargetOrder->getShippings();
foreach ($Shippings as $Shipping) {
$Shipping->setShippingDate($dateTime);
}
// 入金済
} elseif ($TargetOrder->getOrderStatus()->getId() == OrderStatus::PAID) {
$TargetOrder->setPaymentDate($dateTime);
}
// 受注日時
$TargetOrder->setOrderDate($dateTime);
}
}
}
2 changes: 1 addition & 1 deletion src/Eccube/Entity/Master/TaxType.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ class TaxType extends \Eccube\Entity\Master\AbstractMasterEntity
*
* @var integer
*/
const TAX_EXEMPT = 2;
const TAX_EXEMPT = 3;
}
2 changes: 1 addition & 1 deletion src/Eccube/Entity/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ public function removeShipping(\Eccube\Entity\Shipping $Shipping)
public function getShippings()
{
$criteria = Criteria::create()
->orderBy(['name01' => Criteria::ASC, 'name02' => Criteria::ASC]);
->orderBy(['name01' => Criteria::ASC, 'name02' => Criteria::ASC, 'id' => Criteria::ASC]);

return $this->Shippings->matching($criteria);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Eccube/Entity/OrderItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function isTax()
/**
* @var string
*
* @ORM\Column(name="quantity", type="decimal", precision=10, scale=0, options={"unsigned":true,"default":0})
* @ORM\Column(name="quantity", type="decimal", precision=10, scale=0, options={"default":0})
*/
private $quantity = 0;

Expand Down
Loading

0 comments on commit e77a1e4

Please sign in to comment.