Failed Conditions
Pull Request — experimental/sf (#29)
by Kentaro
50:12 queued 39:05
created

UpdateDateProcessor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Service\PurchaseFlow\Processor;
15
16
use Eccube\Common\EccubeConfig;
17
use Eccube\Entity\ItemHolderInterface;
18
use Eccube\Entity\Master\OrderStatus;
19
use Eccube\Entity\Order;
20
use Eccube\Service\PurchaseFlow\ProcessResult;
21
use Eccube\Service\PurchaseFlow\PurchaseContext;
22
23
/**
24
 * 受注情報の日付更新.
25
 */
26
class UpdateDateProcessor extends AbstractPurchaseProcessor
27
{
28
    /**
29
     * @var EccubeConfig
30
     */
31
    protected $eccubeConfig;
32
33
    /**
34
     * UpdateDatePurchaseProcessor constructor.
35
     *
36
     * @param EccubeConfig $eccubeConfig
37
     */
38
    public function __construct(EccubeConfig $eccubeConfig)
39
    {
40
        $this->eccubeConfig = $eccubeConfig;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function commit(ItemHolderInterface $TargetOrder, PurchaseContext $context)
47
    {
48
        $dateTime = new \DateTime();
49
        $OriginOrder = $context->getOriginHolder();
50
51
        /* @var Order $TargetOrder */
52
        if (!$TargetOrder->getOrderStatus()) {
53
            return ProcessResult::success();
54
        }
55
56
        // 編集
57
        if ($TargetOrder->getId()) {
58
            // 発送済
59
            if ($TargetOrder->getOrderStatus()->getId() == OrderStatus::DELIVERED) {
60
                // 編集前と異なる場合のみ更新
61
                if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
62
                    // お届け先情報の発送日も更新する.
63
                    $Shippings = $TargetOrder->getShippings();
64
                    foreach ($Shippings as $Shipping) {
65
                        $Shipping->setShippingDate($dateTime);
66
                    }
67
                }
68
                // 入金済
69
            } elseif ($TargetOrder->getOrderStatus()->getId() == OrderStatus::PAID) {
70
                // 編集前と異なる場合のみ更新
71
                if ($TargetOrder->getOrderStatus()->getId() != $OriginOrder->getOrderStatus()->getId()) {
72
                    $TargetOrder->setPaymentDate($dateTime);
73
                }
74
            }
75
            // 新規
76
        } else {
77
            // 発送済
78
            if ($TargetOrder->getOrderStatus()->getId() == OrderStatus::DELIVERED) {
79
                // お届け先情報の発送日も更新する.
80
                $Shippings = $TargetOrder->getShippings();
81
                foreach ($Shippings as $Shipping) {
82
                    $Shipping->setShippingDate($dateTime);
83
                }
84
                // 入金済
85
            } elseif ($TargetOrder->getOrderStatus()->getId() == OrderStatus::PAID) {
86
                $TargetOrder->setPaymentDate($dateTime);
87
            }
88
            // 受注日時
89
            $TargetOrder->setOrderDate($dateTime);
90
        }
91
92
        return ProcessResult::success();
93
    }
94
}
95