Completed
Push — master ( 396bd1...fbf0e7 )
by
unknown
03:26
created

OrderStatusLog_Submitted   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 134
rs 10
c 0
b 0
f 0
wmc 19
lcom 1
cbo 4
1
<?php
2
3
4
/**
5
 * OrderStatusLog_Submitted is an important class that is created when an order is submitted.
6
 * It is created by the order and it signifies to the OrderStep to continue to the next step.
7
 *
8
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
9
 * @package: ecommerce
10
 * @sub-package: model
11
 * @inspiration: Silverstripe Ltd, Jeremy
12
 **/
13
class OrderStatusLog_Submitted extends OrderStatusLog
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
14
{
15
    private static $db = array(
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
        'OrderAsHTML' => 'HTMLText',
17
        'OrderAsString' => 'Text',
18
        'SequentialOrderNumber' => 'Int',
19
        'Total' => 'Currency',
20
        'SubTotal' => 'Currency',
21
    );
22
23
    private static $defaults = array(
0 ignored issues
show
Unused Code introduced by
The property $defaults is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
24
        'InternalUseOnly' => true,
25
    );
26
27
    private static $casting = array(
0 ignored issues
show
Unused Code introduced by
The property $casting is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
28
        'HTMLRepresentation' => 'HTMLText',
29
    );
30
31
    private static $singular_name = 'Submitted Order';
0 ignored issues
show
Unused Code introduced by
The property $singular_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
32
    public function i18n_singular_name()
33
    {
34
        return _t('OrderStatusLog.SUBMITTEDORDER', 'Submitted Order - Fulltext Backup');
35
    }
36
37
    private static $plural_name = 'Submitted Orders';
0 ignored issues
show
Unused Code introduced by
The property $plural_name is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
38
    public function i18n_plural_name()
39
    {
40
        return _t('OrderStatusLog.SUBMITTEDORDERS', 'Submitted Orders - Fulltext Backup');
41
    }
42
43
    /**
44
     * Standard SS variable.
45
     *
46
     * @var string
47
     */
48
    private static $description = 'The record that the order has been submitted by the customer.  This is important in e-commerce, because from here, nothing can change to the order.';
0 ignored issues
show
Unused Code introduced by
The property $description is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
49
50
    /**
51
     * Standard SS method.
52
     *
53
     * @param Member $member
54
     *
55
     * @return bool
56
     */
57
    public function canDelete($member = null)
58
    {
59
        return false;
60
    }
61
62
    /**
63
     * Standard SS method.
64
     *
65
     * @param Member $member
66
     *
67
     * @return bool
68
     */
69
    public function canEdit($member = null)
70
    {
71
        return false;
72
    }
73
74
    /**
75
     * Standard SS method.
76
     *
77
     * @param Member $member
78
     *
79
     * @return bool
80
     */
81
    public function canCreate($member = null)
82
    {
83
        if (! $member) {
84
            $member = Member::currentUser();
85
        }
86
        $extended = $this->extendedCan(__FUNCTION__, $member);
87
        if ($extended !== null) {
88
            return $extended;
89
        }
90
91
        return true;
92
    }
93
94
    /**
95
     * can only be created when the order is submitted.
96
     *
97
     *@return string
98
     **/
99
    public function HTMLRepresentation()
100
    {
101
        return $this->getHTMLRepresentation();
102
    }
103
    public function getHTMLRepresentation()
104
    {
105
        if ($this->OrderAsHTML) {
106
            return $this->OrderAsHTML;
107
        } elseif ($this->OrderAsString) {
108
            return unserialize($this->OrderAsString);
109
        }
110
111
        return _t('OrderStatusLog.NO_FURTHER_INFO_AVAILABLE', 'no further information available');
112
    }
113
114
    /**
115
     * adding a sequential order number.
116
     */
117
    public function onBeforeWrite()
118
    {
119
        parent::onBeforeWrite();
120
        if ($order = $this->Order()) {
121
            if (!$this->Total) {
122
                $this->Total = $order->Total();
123
                $this->SubTotal = $order->SubTotal();
124
            }
125
        }
126
        if (!intval($this->SequentialOrderNumber)) {
127
            $this->SequentialOrderNumber = 1;
128
            $min = intval(EcommerceConfig::get('Order', 'order_id_start_number')) - 0;
129
            if (isset($this->ID)) {
130
                $id = intval($this->ID);
131
            } else {
132
                $id = 0;
133
            }
134
            $lastOne = DataObject::get_one(
135
                'OrderStatusLog_Submitted',
136
                '\'ID\' != \''.$id.'\''
137
                $cache = true,
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_VARIABLE, expecting ',' or ')'
Loading history...
138
                array('SequentialOrderNumber' => 'DESC')
139
            );
140
            if ($lastOne) {
141
                $this->SequentialOrderNumber = intval($lastOne->SequentialOrderNumber) + 1;
142
            }
143
            if (intval($min) && $this->SequentialOrderNumber < $min) {
144
                $this->SequentialOrderNumber = $min;
145
            }
146
        }
147
    }
148
}
149