Order   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 220
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 81
dl 0
loc 220
rs 10
c 2
b 0
f 0
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A fieldLabels() 0 17 1
A canDelete() 0 3 1
A providePermissions() 0 17 1
A canEdit() 0 3 1
A getReceiptLink() 0 8 1
A ReceiptLink() 0 3 1
A canView() 0 3 1
A canCreate() 0 3 1
A getCMSFields() 0 7 1
1
<?php
2
3
namespace Dynamic\Foxy\Orders\Model;
4
5
use Dynamic\Foxy\Extension\Purchasable;
6
use SilverStripe\Forms\DateField;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forms\GridField\GridField;
9
use SilverStripe\Forms\GridField\GridFieldConfig_RecordViewer;
10
use SilverStripe\ORM\DataObject;
11
use SilverStripe\ORM\FieldType\DBHTMLVarchar;
12
use SilverStripe\ORM\HasManyList;
13
use SilverStripe\Security\Member;
14
use SilverStripe\Security\Permission;
15
use SilverStripe\Security\PermissionProvider;
16
17
/**
18
 * Class Order
19
 * @package Dynamic\Foxy\Model
20
 *
21
 * @property \SilverStripe\ORM\FieldType\DBInt StoreID
22
 * @property \SilverStripe\ORM\FieldType\DBInt OrderID
23
 * @property \SilverStripe\ORM\FieldType\DBVarchar Email
24
 * @property \SilverStripe\ORM\FieldType\DBDatetime TransactionDate
25
 * @property \SilverStripe\ORM\FieldType\DBCurrency ProductTotal
26
 * @property \SilverStripe\ORM\FieldType\DBCurrency TaxTotal
27
 * @property \SilverStripe\ORM\FieldType\DBCurrency ShippingTotal
28
 * @property \SilverStripe\ORM\FieldType\DBCurrency OrderTotal
29
 * @property \SilverStripe\ORM\FieldType\DBVarchar ReceiptURL
30
 * @property \SilverStripe\ORM\FieldType\DBVarchar OrderStatus
31
 * @property \SilverStripe\ORM\FieldType\DBText Response
32
 *
33
 * @property int MemberID
34
 * @method Member Member
35
 *
36
 * @method HasManyList Details
37
 */
38
class Order extends DataObject implements PermissionProvider
39
{
40
    /**
41
     * @var array
42
     */
43
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
44
        'StoreID' => 'Int',
45
        'OrderID' => 'Int',
46
        'Email' => 'Varchar(255)',
47
        'TransactionDate' => 'DBDatetime',
48
        'ProductTotal' => 'Currency',
49
        'TaxTotal' => 'Currency',
50
        'ShippingTotal' => 'Currency',
51
        'OrderTotal' => 'Currency',
52
        'ReceiptURL' => 'Varchar(255)',
53
        'OrderStatus' => 'Varchar(255)',
54
        'Response' => 'Text',
55
        'CustomerID' => 'Int',
56
    ];
57
58
    /**
59
     * @var array
60
     */
61
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
62
        'Member' => Member::class,
63
    ];
64
65
    /**
66
     * @var array
67
     */
68
    private static $has_many = [
0 ignored issues
show
introduced by
The private property $has_many is not used, and could be removed.
Loading history...
69
        'Details' => OrderDetail::class,
70
    ];
71
72
    /**
73
     * @var string
74
     */
75
    private static $singular_name = 'Order';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
76
77
    /**
78
     * @var string
79
     */
80
    private static $plural_name = 'Orders';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
81
82
    /**
83
     * @var string
84
     */
85
    private static $description = 'Orders from FoxyCart Datafeed';
0 ignored issues
show
introduced by
The private property $description is not used, and could be removed.
Loading history...
86
87
    /**
88
     * @var string
89
     */
90
    private static $default_sort = 'TransactionDate DESC, ID DESC';
0 ignored issues
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
91
92
    /**
93
     * @var array
94
     */
95
    private static $summary_fields = [
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
96
        'OrderID',
97
        'TransactionDate.Nice',
98
        'Email',
99
        'ProductTotal.Nice',
100
        'ShippingTotal.Nice',
101
        'TaxTotal.Nice',
102
        'OrderTotal.Nice',
103
        'ReceiptLink',
104
    ];
105
106
    /**
107
     * @var array
108
     */
109
    private static $searchable_fields = [
0 ignored issues
show
introduced by
The private property $searchable_fields is not used, and could be removed.
Loading history...
110
        'OrderID',
111
        'TransactionDate' => [
112
            'field' => DateField::class,
113
            'filter' => 'PartialMatchFilter',
114
        ],
115
        'Email',
116
        'OrderTotal',
117
    ];
118
119
    /**
120
     * @var array
121
     */
122
    private static $casting = [
0 ignored issues
show
introduced by
The private property $casting is not used, and could be removed.
Loading history...
123
        'ReceiptLink' => 'HTMLVarchar',
124
    ];
125
126
    /**
127
     * @var array
128
     */
129
    private static $indexes = [
0 ignored issues
show
introduced by
The private property $indexes is not used, and could be removed.
Loading history...
130
        'OrderID' => true, // make unique
131
    ];
132
133
    /**
134
     * @var string
135
     */
136
    private static $table_name = 'FoxyOrder';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
137
138
    /**
139
     * @param bool $includerelations
140
     *
141
     * @return array|string
142
     */
143
    public function fieldLabels($includerelations = true)
144
    {
145
        $labels = parent::fieldLabels();
146
        $labels['StoreID'] = _t(__CLASS__ . '.StoreID', 'Store ID#');
147
        $labels['OrderID'] = _t(__CLASS__ . '.OrderID', 'Order ID#');
148
        $labels['TransactionDate'] = _t(__CLASS__ . '.TransactionDate', 'Date');
149
        $labels['TransactionDate.NiceUS'] = _t(__CLASS__ . '.TransactionDate', 'Date');
150
        $labels['Email'] = _t(__CLASS__ . '.Email', 'Email');
151
        $labels['ProductTotal.Nice'] = _t(__CLASS__ . '.ProductTotal', 'Sub Total');
152
        $labels['TaxTotal.Nice'] = _t(__CLASS__ . '.TaxTotal', 'Tax');
153
        $labels['ShippingTotal.Nice'] = _t(__CLASS__ . '.ShippingTotal', 'Shipping');
154
        $labels['OrderTotal'] = _t(__CLASS__ . '.OrderTotal', 'Total');
155
        $labels['OrderTotal.Nice'] = _t(__CLASS__ . '.OrderTotal', 'Total');
156
        $labels['ReceiptLink'] = _t(__CLASS__ . '.ReceiptLink', 'Invoice');
157
        $labels['Details.ProductID'] = _t(__CLASS__ . '.Details.ProductID', 'Product');
158
159
        return $labels;
160
    }
161
162
    /**
163
     * @return FieldList
164
     */
165
    public function getCMSFields()
166
    {
167
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
168
            $fields->removeByName(['Response']);
169
        });
170
171
        return parent::getCMSFields();
172
    }
173
174
    /**
175
     * @return mixed
176
     */
177
    public function ReceiptLink()
178
    {
179
        return $this->getReceiptLink();
180
    }
181
182
    /**
183
     * @return mixed
184
     */
185
    public function getReceiptLink()
186
    {
187
        $obj = DBHTMLVarchar::create();
188
        $obj->setValue(
189
            '<a href="' . $this->ReceiptURL . '" target="_blank" class="cms-panel-link action external-link">view</a>'
190
        );
191
192
        return $obj;
193
    }
194
195
    /**
196
     * @return array
197
     */
198
    public function providePermissions()
199
    {
200
        return [
201
            'MANAGE_FOXY_ORDERS' => [
202
                'name' => _t(
203
                    __CLASS__ . '.PERMISSION_MANAGE_ORDERS_DESCRIPTION',
204
                    'Manage orders'
205
                ),
206
                'category' => _t(
207
                    Purchasable::class . '.PERMISSIONS_CATEGORY',
208
                    'Foxy'
209
                ),
210
                'help' => _t(
211
                    __CLASS__ . '.PERMISSION_MANAGE_ORDERS_HELP',
212
                    'Manage orders and view recipts'
213
                ),
214
                'sort' => 400,
215
            ],
216
        ];
217
    }
218
219
    /**
220
     * @param bool $member
221
     *
222
     * @return bool|int
223
     */
224
    public function canView($member = null)
225
    {
226
        return Permission::checkMember($member, 'MANAGE_FOXY_ORDERS');
227
    }
228
229
    /**
230
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
231
     *
232
     * @return bool
233
     */
234
    public function canEdit($member = null)
235
    {
236
        return false;
237
    }
238
239
    /**
240
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
241
     *
242
     * @return bool
243
     */
244
    public function canDelete($member = null)
245
    {
246
        return false;
247
    }
248
249
    /**
250
     * @param null $member
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $member is correct as it would always require null to be passed?
Loading history...
251
     * @param array $context
252
     *
253
     * @return bool
254
     */
255
    public function canCreate($member = null, $context = [])
256
    {
257
        return false;
258
    }
259
}
260