Completed
Push — master ( 5f30df...b891aa )
by Nicolaas
03:32
created

Order::IsProcessing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * @description:
5
 * The order class is a databound object for handling Orders within SilverStripe.
6
 * Note that it works closely with the ShoppingCart class, which accompanies the Order
7
 * until it has been paid for / confirmed by the user.
8
 *
9
 *
10
 * CONTENTS:
11
 * ----------------------------------------------
12
 * 1. CMS STUFF
13
 * 2. MAIN TRANSITION FUNCTIONS
14
 * 3. STATUS RELATED FUNCTIONS / SHORTCUTS
15
 * 4. LINKING ORDER WITH MEMBER AND ADDRESS
16
 * 5. CUSTOMER COMMUNICATION
17
 * 6. ITEM MANAGEMENT
18
 * 7. CRUD METHODS (e.g. canView, canEdit, canDelete, etc...)
19
 * 8. GET METHODS (e.g. Total, SubTotal, Title, etc...)
20
 * 9. TEMPLATE RELATED STUFF
21
 * 10. STANDARD SS METHODS (requireDefaultRecords, onBeforeDelete, etc...)
22
 * 11. DEBUG
23
 *
24
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
25
 * @package: ecommerce
26
 * @sub-package: model
27
 * @inspiration: Silverstripe Ltd, Jeremy
28
 *
29
 * NOTE: This is the SQL for selecting orders in sequence of
30
 **/
31
class Order extends DataObject implements EditableEcommerceObject
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...
32
{
33
    /**
34
     * API Control.
35
     *
36
     * @var array
37
     */
38
    private static $api_access = array(
0 ignored issues
show
Unused Code introduced by
The property $api_access 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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
39
        'view' => array(
40
            'OrderEmail',
41
            'EmailLink',
42
            'PrintLink',
43
            'RetrieveLink',
44
            'ShareLink',
45
            'Title',
46
            'Total',
47
            'SubTotal',
48
            'TotalPaid',
49
            'TotalOutstanding',
50
            'ExchangeRate',
51
            'CurrencyUsed',
52
            'TotalItems',
53
            'TotalItemsTimesQuantity',
54
            'IsCancelled',
55
            'Country',
56
            'FullNameCountry',
57
            'IsSubmitted',
58
            'CustomerStatus',
59
            'CanHaveShippingAddress',
60
            'CancelledBy',
61
            'CurrencyUsed',
62
            'BillingAddress',
63
            'UseShippingAddress',
64
            'ShippingAddress',
65
            'Status',
66
            'Attributes',
67
            'OrderStatusLogs',
68
            'MemberID',
69
        ),
70
    );
71
72
    /**
73
     * standard SS variable.
74
     *
75
     * @var array
76
     */
77
    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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
78
        'SessionID' => 'Varchar(32)', //so that in the future we can link sessions with Orders.... One session can have several orders, but an order can onnly have one session
79
        'UseShippingAddress' => 'Boolean',
80
        'CustomerOrderNote' => 'Text',
81
        'ExchangeRate' => 'Double',
82
        //'TotalItems_Saved' => 'Double',
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
83
        //'TotalItemsTimesQuantity_Saved' => 'Double'
84
    );
85
86
    private static $has_one = array(
0 ignored issues
show
Unused Code introduced by
The property $has_one 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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
87
        'Member' => 'Member',
88
        'BillingAddress' => 'BillingAddress',
89
        'ShippingAddress' => 'ShippingAddress',
90
        'Status' => 'OrderStep',
91
        'CancelledBy' => 'Member',
92
        'CurrencyUsed' => 'EcommerceCurrency',
93
    );
94
95
    /**
96
     * standard SS variable.
97
     *
98
     * @var array
99
     */
100
    private static $has_many = array(
0 ignored issues
show
Unused Code introduced by
The property $has_many 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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
101
        'Attributes' => 'OrderAttribute',
102
        'OrderStatusLogs' => 'OrderStatusLog',
103
        'Payments' => 'EcommercePayment',
104
        'Emails' => 'OrderEmailRecord',
105
    );
106
107
    /**
108
     * standard SS variable.
109
     *
110
     * @var array
111
     */
112
    private static $indexes = array(
0 ignored issues
show
Unused Code introduced by
The property $indexes 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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
113
        'SessionID' => true,
114
    );
115
116
    /**
117
     * standard SS variable.
118
     *
119
     * @var string
120
     */
121
    private static $default_sort = '"LastEdited" DESC';
0 ignored issues
show
Unused Code introduced by
The property $default_sort 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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
122
123
    /**
124
     * standard SS variable.
125
     *
126
     * @var array
127
     */
128
    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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
129
        'OrderEmail' => 'Text',
130
        'EmailLink' => 'Text',
131
        'PrintLink' => 'Text',
132
        'ShareLink' => 'Text',
133
        'RetrieveLink' => 'Text',
134
        'Title' => 'Text',
135
        'Total' => 'Currency',
136
        'TotalAsMoney' => 'Money',
137
        'SubTotal' => 'Currency',
138
        'SubTotalAsMoney' => 'Money',
139
        'TotalPaid' => 'Currency',
140
        'TotalPaidAsMoney' => 'Money',
141
        'TotalOutstanding' => 'Currency',
142
        'TotalOutstandingAsMoney' => 'Money',
143
        'HasAlternativeCurrency' => 'Boolean',
144
        'TotalItems' => 'Double',
145
        'TotalItemsTimesQuantity' => 'Double',
146
        'IsCancelled' => 'Boolean',
147
        'Country' => 'Varchar(3)', //This is the applicable country for the order - for tax purposes, etc....
148
        'FullNameCountry' => 'Varchar',
149
        'IsSubmitted' => 'Boolean',
150
        'CustomerStatus' => 'Varchar',
151
        'CanHaveShippingAddress' => 'Boolean',
152
    );
153
154
    /**
155
     * standard SS variable.
156
     *
157
     * @var string
158
     */
159
    private static $singular_name = '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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
160
    public function i18n_singular_name()
161
    {
162
        return _t('Order.ORDER', 'Order');
163
    }
164
165
    /**
166
     * standard SS variable.
167
     *
168
     * @var string
169
     */
170
    private static $plural_name = '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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
171
    public function i18n_plural_name()
172
    {
173
        return _t('Order.ORDERS', 'Orders');
174
    }
175
176
    /**
177
     * Standard SS variable.
178
     *
179
     * @var string
180
     */
181
    private static $description = "A collection of items that together make up the 'Order'.  An order can be placed.";
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...
182
183
    /**
184
     * Tells us if an order needs to be recalculated
185
     * can save one for each order...
186
     *
187
     * @var array
188
     */
189
    private static $_needs_recalculating = array();
190
191
    /**
192
     * @param bool (optional) $b
193
     * @param int (optional)  $orderID
194
     *
195
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
196
     */
197
    public static function set_needs_recalculating($b = true, $orderID = 0)
198
    {
199
        self::$_needs_recalculating[$orderID] = $b;
200
    }
201
202
    /**
203
     * @param int (optional) $orderID
204
     *
205
     * @return bool
206
     */
207
    public static function get_needs_recalculating($orderID = 0)
208
    {
209
        return isset(self::$_needs_recalculating[$orderID]) ? self::$_needs_recalculating[$orderID] : false;
210
    }
211
212
    /**
213
     * Total Items : total items in cart
214
     * We start with -1 to easily identify if it has been run before.
215
     *
216
     * @var int
217
     */
218
    protected $totalItems = null;
219
220
    /**
221
     * Total Items : total items in cart
222
     * We start with -1 to easily identify if it has been run before.
223
     *
224
     * @var float
225
     */
226
    protected $totalItemsTimesQuantity = null;
227
228
    /**
229
     * Returns a set of modifier forms for use in the checkout order form,
230
     * Controller is optional, because the orderForm has its own default controller.
231
     *
232
     * This method only returns the Forms that should be included outside
233
     * the editable table... Forms within it can be called
234
     * from through the modifier itself.
235
     *
236
     * @param Controller $optionalController
0 ignored issues
show
Documentation introduced by
Should the type for parameter $optionalController not be null|Controller?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
237
     * @param Validator  $optionalValidator
0 ignored issues
show
Documentation introduced by
Should the type for parameter $optionalValidator not be null|Validator?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
238
     *
239
     * @return ArrayList (ModifierForms) | Null
0 ignored issues
show
Documentation introduced by
Should the return type not be ArrayList|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
240
     **/
241
    public function getModifierForms(Controller $optionalController = null, Validator $optionalValidator = null)
242
    {
243
        $arrayList = new ArrayList();
244
        $modifiers = $this->Modifiers();
245
        if ($modifiers->count()) {
246
            foreach ($modifiers as $modifier) {
247
                if ($modifier->ShowForm()) {
248
                    if ($form = $modifier->getModifierForm($optionalController, $optionalValidator)) {
249
                        $form->ShowFormInEditableOrderTable = $modifier->ShowFormInEditableOrderTable();
250
                        $form->ShowFormOutsideEditableOrderTable = $modifier->ShowFormOutsideEditableOrderTable();
251
                        $form->ModifierName = $modifier->ClassName;
252
                        $arrayList->push($form);
253
                    }
254
                }
255
            }
256
        }
257
        if ($arrayList->count()) {
258
            return $arrayList;
259
        } else {
260
            return;
261
        }
262
    }
263
264
    /**
265
     * This function returns the OrderSteps.
266
     *
267
     * @return ArrayList (OrderSteps)
0 ignored issues
show
Documentation introduced by
Should the return type not be DataList?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
268
     **/
269
    public static function get_order_status_options()
270
    {
271
        return OrderStep::get();
272
    }
273
274
    /**
275
     * Like the standard byID, but it checks whether we are allowed to view the order.
276
     *
277
     * @return: Order | Null
278
     **/
279
    public static function get_by_id_if_can_view($id)
280
    {
281
        $order = Order::get()->byID($id);
282
        if ($order && $order->canView()) {
283
            if ($order->IsSubmitted()) {
284
                // LITTLE HACK TO MAKE SURE WE SHOW THE LATEST INFORMATION!
285
                $order->tryToFinaliseOrder();
286
            }
287
288
            return $order;
289
        }
290
291
        return;
292
    }
293
294
    /**
295
     * returns a Datalist with the submitted order log included
296
     * this allows you to sort the orders by their submit dates.
297
     * You can retrieve this list and then add more to it (e.g. additional filters, additional joins, etc...).
298
     *
299
     * @param bool $onlySubmittedOrders - only include Orders that have already been submitted.
300
     * @param bool $includeCancelledOrders - only include Orders that have already been submitted.
301
     *
302
     * @return DataList (Orders)
303
     */
304
    public static function get_datalist_of_orders_with_submit_record($onlySubmittedOrders = true, $includeCancelledOrders = false)
305
    {
306
        if ($onlySubmittedOrders) {
307
            $submittedOrderStatusLogClassName = EcommerceConfig::get('OrderStatusLog', 'order_status_log_class_used_for_submitting_order');
308
            $list = Order::get()
309
                ->LeftJoin('OrderStatusLog', '"Order"."ID" = "OrderStatusLog"."OrderID"')
310
                ->LeftJoin($submittedOrderStatusLogClassName, '"OrderStatusLog"."ID" = "'.$submittedOrderStatusLogClassName.'"."ID"')
311
                ->Sort('OrderStatusLog.Created', 'ASC');
312
            $where = ' ("OrderStatusLog"."ClassName" = \''.$submittedOrderStatusLogClassName.'\') ';
313
        } else {
314
            $list = Order::get();
315
            $where = ' ("StatusID" > 0) ';
316
        }
317
        if ($includeCancelledOrders) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
318
            //do nothing...
319
        } else {
320
            $where .= ' AND ("CancelledByID" = 0 OR "CancelledByID" IS NULL)';
321
        }
322
        $list = $list->where($where);
323
324
        return $list;
325
    }
326
327
/*******************************************************
328
   * 1. CMS STUFF
329
*******************************************************/
330
331
    /**
332
     * fields that we remove from the parent::getCMSFields object set.
333
     *
334
     * @var array
335
     */
336
    protected $fieldsAndTabsToBeRemoved = array(
337
        'MemberID',
338
        'Attributes',
339
        'SessionID',
340
        'Emails',
341
        'BillingAddressID',
342
        'ShippingAddressID',
343
        'UseShippingAddress',
344
        'OrderStatusLogs',
345
        'Payments',
346
        'OrderDate',
347
        'ExchangeRate',
348
        'CurrencyUsedID',
349
        'StatusID',
350
        'Currency',
351
    );
352
353
    /**
354
     * STANDARD SILVERSTRIPE STUFF.
355
     **/
356
    private static $summary_fields = array(
0 ignored issues
show
Unused Code introduced by
The property $summary_fields 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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
357
        'Title' => 'Title',
358
        'Status.Title' => 'Next Step',
359
        'Member.Surname' => 'Name',
360
        'Member.Email' => 'Email',
361
        'TotalAsMoney.Nice' => 'Total',
362
        'TotalItemsTimesQuantity' => 'Units'
363
    );
364
365
    /**
366
     * STANDARD SILVERSTRIPE STUFF.
367
     *
368
     * @todo: how to translate this?
369
     **/
370
    private static $searchable_fields = array(
0 ignored issues
show
Unused Code introduced by
The property $searchable_fields 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...
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
371
        'ID' => array(
372
            'field' => 'NumericField',
373
            'title' => 'Order Number',
374
        ),
375
        'MemberID' => array(
376
            'field' => 'TextField',
377
            'filter' => 'OrderFilters_MemberAndAddress',
378
            'title' => 'Customer Details',
379
        ),
380
        'Created' => array(
381
            'field' => 'TextField',
382
            'filter' => 'OrderFilters_AroundDateFilter',
383
            'title' => 'Date (e.g. Today, 1 jan 2007, or last week)',
384
        ),
385
        //make sure to keep the items below, otherwise they do not show in form
386
        'StatusID' => array(
387
            'filter' => 'OrderFilters_MultiOptionsetStatusIDFilter',
388
        ),
389
        'CancelledByID' => array(
390
            'filter' => 'OrderFilters_HasBeenCancelled',
391
            'title' => 'Cancelled by ...',
392
        ),
393
    );
394
395
    /**
396
     * Determine which properties on the DataObject are
397
     * searchable, and map them to their default {@link FormField}
398
     * representations. Used for scaffolding a searchform for {@link ModelAdmin}.
399
     *
400
     * Some additional logic is included for switching field labels, based on
401
     * how generic or specific the field type is.
402
     *
403
     * Used by {@link SearchContext}.
404
     *
405
     * @param array $_params
0 ignored issues
show
Documentation introduced by
Should the type for parameter $_params not be array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
406
     *                       'fieldClasses': Associative array of field names as keys and FormField classes as values
407
     *                       'restrictFields': Numeric array of a field name whitelist
408
     *
409
     * @return FieldList
410
     */
411
    public function scaffoldSearchFields($_params = null)
0 ignored issues
show
Coding Style introduced by
scaffoldSearchFields uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
412
    {
413
        $fieldList = parent::scaffoldSearchFields($_params);
414
        $statusOptions = OrderStep::get();
415
        if ($statusOptions && $statusOptions->count()) {
416
            $createdOrderStatusID = 0;
0 ignored issues
show
Unused Code introduced by
$createdOrderStatusID is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
417
            $preSelected = array();
418
            $createdOrderStatus = $statusOptions->First();
419
            if ($createdOrderStatus) {
420
                $createdOrderStatusID = $createdOrderStatus->ID;
0 ignored issues
show
Unused Code introduced by
$createdOrderStatusID is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
421
            }
422
            $arrayOfStatusOptions = clone $statusOptions->map('ID', 'Title');
423
            $arrayOfStatusOptionsFinal = array();
424
            if (count($arrayOfStatusOptions)) {
425
                foreach ($arrayOfStatusOptions as $key => $value) {
426
                    if (isset($_GET['q']['StatusID'][$key])) {
427
                        $preSelected[$key] = $key;
428
                    }
429
                    $count = Order::get()
430
                        ->Filter(array('StatusID' => intval($key)))
431
                        ->count();
432
                    if ($count < 1) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
433
                        //do nothing
434
                    } else {
435
                        $arrayOfStatusOptionsFinal[$key] = $value." ($count)";
436
                    }
437
                }
438
            }
439
            $statusField = new CheckboxSetField(
440
                'StatusID',
441
                Injector::inst()->get('OrderStep')->i18n_singular_name(),
442
                $arrayOfStatusOptionsFinal,
443
                $preSelected
0 ignored issues
show
Documentation introduced by
$preSelected is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
444
            );
445
            $fieldList->push($statusField);
446
        }
447
        $fieldList->push(new DropdownField('CancelledByID', 'Cancelled', array(-1 => '(Any)', 1 => 'yes', 0 => 'no')));
448
449
        return $fieldList;
450
    }
451
452
    /**
453
     * link to edit the record.
454
     *
455
     * @param string | Null $action - e.g. edit
456
     *
457
     * @return string
458
     */
459
    public function CMSEditLink($action = null)
460
    {
461
        return Controller::join_links(
462
            Director::baseURL(),
463
            '/admin/sales/'.$this->ClassName.'/EditForm/field/'.$this->ClassName.'/item/'.$this->ID.'/',
464
            $action
465
        );
466
    }
467
468
    /**
469
     * STANDARD SILVERSTRIPE STUFF
470
     * broken up into submitted and not (yet) submitted.
471
     **/
472
    public function getCMSFields()
0 ignored issues
show
Coding Style introduced by
getCMSFields uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
473
    {
474
        $fields = $this->scaffoldFormFields(array(
475
            // Don't allow has_many/many_many relationship editing before the record is first saved
476
            'includeRelations' => false,
477
            'tabbed' => true,
478
            'ajaxSafe' => true
479
        ));
480
        $fields->insertBefore(
481
            Tab::create(
482
                'Next',
483
                _t('Order.NEXT_TAB', 'Action')
484
            ),
485
            'Main'
0 ignored issues
show
Documentation introduced by
'Main' is of type string, but the function expects a object<FormField>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
486
        );
487
        $fields->addFieldsToTab(
488
            'Root',
489
            array(
490
                Tab::create(
491
                    "Items",
492
                    _t('Order.ITEMS_TAB', 'Items')
493
                ),
494
                Tab::create(
495
                    "Extras",
496
                    _t('Order.MODIFIERS_TAB', 'Adjustments')
497
                ),
498
                Tab::create(
499
                    'Emails',
500
                    _t('Order.EMAILS_TAB', 'Emails')
501
                ),
502
                Tab::create(
503
                    'Payments',
504
                    _t('Order.PAYMENTS_TAB', 'Payment')
505
                ),
506
                Tab::create(
507
                    'Account',
508
                    _t('Order.ACCOUNT_TAB', 'Account')
509
                ),
510
                Tab::create(
511
                    'Currency',
512
                    _t('Order.CURRENCY_TAB', 'Currency')
513
                ),
514
                Tab::create(
515
                    'Addresses',
516
                    _t('Order.ADDRESSES_TAB', 'Addresses')
517
                ),
518
                Tab::create(
519
                    'Log',
520
                    _t('Order.LOG_TAB', 'Notes')
521
                ),
522
                Tab::create(
523
                    'Cancellations',
524
                    _t('Order.CANCELLATION_TAB', 'Cancel')
525
                ),
526
            )
527
        );
528
        //as we are no longer using the parent:;getCMSFields
529
        // we had to add the updateCMSFields hook.
530
        $this->extend('updateCMSFields', $fields);
531
        $currentMember = Member::currentUser();
532
        if (!$this->exists() || !$this->StatusID) {
0 ignored issues
show
Documentation introduced by
The property StatusID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
533
            $firstStep = OrderStep::get()->First();
534
            $this->StatusID = $firstStep->ID;
0 ignored issues
show
Documentation introduced by
The property StatusID does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
535
            $this->write();
536
        }
537
        $submitted = $this->IsSubmitted() ? true : false;
538
        if ($submitted) {
539
            //TODO
540
            //Having trouble here, as when you submit the form (for example, a payment confirmation)
541
            //as the step moves forward, meaning the fields generated are incorrect, causing an error
542
            //"I can't handle sub-URLs of a Form object." generated by the RequestHandler.
543
            //Therefore we need to try reload the page so that it will be requesting the correct URL to generate the correct fields for the current step
544
            //Or something similar.
545
            //why not check if the URL == $this->CMSEditLink()
546
            //and only tryToFinaliseOrder if this is true....
547
            if ($_SERVER['REQUEST_URI'] == $this->CMSEditLink() || $_SERVER['REQUEST_URI'] == $this->CMSEditLink('edit')) {
548
                $this->tryToFinaliseOrder();
549
            }
550
        } else {
551
            $this->init(true);
552
            $this->calculateOrderAttributes(true);
553
            Session::set('EcommerceOrderGETCMSHack', $this->ID);
554
        }
555
        if ($submitted) {
556
            $this->fieldsAndTabsToBeRemoved[] = 'CustomerOrderNote';
557
        } else {
558
            $this->fieldsAndTabsToBeRemoved[] = 'Emails';
559
        }
560
        foreach ($this->fieldsAndTabsToBeRemoved as $field) {
561
            $fields->removeByName($field);
562
        }
563
        $orderSummaryConfig = GridFieldConfig_Base::create();
564
        $orderSummaryConfig->removeComponentsByType('GridFieldToolbarHeader');
565
        // $orderSummaryConfig->removeComponentsByType('GridFieldSortableHeader');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
566
        $orderSummaryConfig->removeComponentsByType('GridFieldFilterHeader');
567
        $orderSummaryConfig->removeComponentsByType('GridFieldPageCount');
568
        $orderSummaryConfig->removeComponentsByType('GridFieldPaginator');
569
        $nextFieldArray = array(
570
            LiteralField::create('CssFix', '<style>#Root_Next h2 {padding: 0!important; margin: 0!important; margin-top: 2em!important;}</style>'),
571
            HeaderField::create('OrderSummaryHeader', _t('Order.THIS_ORDER_HEADER', 'Order Summary')),
572
            GridField::create(
573
                'OrderSummary',
574
                _t('Order.CURRENT_STATUS', 'Summary'),
575
                ArrayList::create(array($this)),
576
                $orderSummaryConfig
577
            ),
578
        );
579
        $keyNotes = OrderStatusLog::get()->filter(
580
            array(
581
                'OrderID' => $this->ID,
582
                'ClassName' => 'OrderStatusLog'
583
            )
584
        );
585
        if ($keyNotes->count()) {
586
            $notesSummaryConfig = GridFieldConfig_RecordViewer::create();
587
            $notesSummaryConfig->removeComponentsByType('GridFieldToolbarHeader');
588
            $notesSummaryConfig->removeComponentsByType('GridFieldFilterHeader');
589
            // $orderSummaryConfig->removeComponentsByType('GridFieldSortableHeader');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
590
            $notesSummaryConfig->removeComponentsByType('GridFieldPageCount');
591
            $notesSummaryConfig->removeComponentsByType('GridFieldPaginator');
592
            $nextFieldArray = array_merge(
593
                $nextFieldArray,
594
                array(
595
                    HeaderField::create('KeyNotesHeader', _t('Order.KEY_NOTES_HEADER', 'Key Notes')),
596
                    GridField::create(
597
                        'OrderStatusLogSummary',
598
                        _t('Order.CURRENT_KEY_NOTES', 'Key Notes'),
599
                        $keyNotes,
600
                        $notesSummaryConfig
601
                    )
602
                )
603
            );
604
        }
605
        $nextFieldArray = array_merge(
606
            $nextFieldArray,
607
            array(
608
                HeaderField::create('MyOrderStepHeader', _t('Order.CURRENT_STATUS', '1. Current Status')),
609
                $this->OrderStepField()
610
            )
611
        );
612
613
         //is the member is a shop admin they can always view it
614
        if (EcommerceRole::current_member_can_process_orders(Member::currentUser())) {
615
            $nextFieldArray = array_merge(
616
                $nextFieldArray,
617
                array(
618
                    HeaderField::create('OrderStepNextStepHeader', _t('Order.ACTION_NEXT_STEP', '2. Action Next Step')),
619
                    HeaderField::create('ActionNextStepManually', _t('Order.MANUAL_STATUS_CHANGE', '3. Move Order Along')),
620
                    LiteralField::create('OrderStepNextStepHeaderExtra', '<p>'._t('Order.NEEDTOREFRESH', 'If you have made any changes to the order then you will have to refresh or save this record to move it along.').'</p>'),
621
                    EcommerceCMSButtonField::create(
622
                        'StatusIDExplanation',
623
                        $this->CMSEditLink(),
624
                        _t('Order.REFRESH', 'refresh now')
625
                    )
626
                )
627
            );
628
        }
629
        $nextFieldArray = array_merge(
630
            $nextFieldArray,
631
            array(
632
                EcommerceCMSButtonField::create(
633
                    'AddNoteButton',
634
                    $this->CMSEditLink('ItemEditForm/field/OrderStatusLog/item/new'),
635
                    _t('Order.ADD_NOTE', 'Add Note')
636
                )
637
            )
638
        );
639
        $fields->addFieldsToTab(
640
            'Root.Next',
641
            $nextFieldArray
642
        );
643
644
        $this->MyStep()->addOrderStepFields($fields, $this);
645
646
        if ($submitted) {
647
            $permaLinkLabel = _t('Order.PERMANENT_LINK', 'Customer Link');
648
            $html = '<p>'.$permaLinkLabel.': <a href="'.$this->getRetrieveLink().'">'.$this->getRetrieveLink().'</a></p>';
649
            $shareLinkLabel = _t('Order.SHARE_LINK', 'Share Link');
650
            $html .= '<p>'.$shareLinkLabel.': <a href="'.$this->getShareLink().'">'.$this->getShareLink().'</a></p>';
651
            $js = "window.open(this.href, 'payment', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=800,height=600'); return false;";
652
            $link = $this->getPrintLink();
653
            $label = _t('Order.PRINT_INVOICE', 'invoice');
654
            $linkHTML = '<a href="'.$link.'" onclick="'.$js.'">'.$label.'</a>';
655
            $linkHTML .= ' | ';
656
            $link = $this->getPackingSlipLink();
657
            $label = _t('Order.PRINT_PACKING_SLIP', 'packing slip');
658
            $labelPrint = _t('Order.PRINT', 'Print');
659
            $linkHTML .= '<a href="'.$link.'" onclick="'.$js.'">'.$label.'</a>';
660
            $html .= '<h3>';
661
            $html .= $labelPrint.': '.$linkHTML;
662
            $html .= '</h3>';
663
664
            $fields->addFieldToTab(
665
                'Root.Main',
666
                LiteralField::create('getPrintLinkANDgetPackingSlipLink', $html)
667
            );
668
669
            //add order here as well.
670
            $fields->addFieldToTab(
671
                'Root.Main',
672
                new LiteralField(
673
                    'MainDetails',
674
                    '<iframe src="'.$this->getPrintLink().'" width="100%" height="2500" style="border: 5px solid #2e7ead; border-radius: 2px;"></iframe>')
675
            );
676
            $fields->addFieldsToTab(
677
                'Root.Items',
678
                array(
679
                    GridField::create(
680
                        'Items_Sold',
681
                        'Items Sold',
682
                        $this->Items(),
683
                        new GridFieldConfig_RecordViewer
684
                    )
685
                )
686
            );
687
            $fields->addFieldsToTab(
688
                'Root.Extras',
689
                array(
690
                    GridField::create(
691
                        'Modifications',
692
                        'Price (and other) adjustments',
693
                        $this->Modifiers(),
694
                        new GridFieldConfig_RecordViewer
695
                    )
696
                )
697
            );
698
            $fields->addFieldsToTab(
699
                'Root.Emails',
700
                array(
701
                    $this->getEmailsTableField()
702
                )
703
            );
704
            $fields->addFieldsToTab(
705
                'Root.Payments',
706
                array(
707
                    $this->getPaymentsField(),
708
                    new ReadOnlyField('TotalPaidNice', _t('Order.TOTALPAID', 'Total Paid'), $this->TotalPaidAsCurrencyObject()->Nice()),
709
                    new ReadOnlyField('TotalOutstandingNice', _t('Order.TOTALOUTSTANDING', 'Total Outstanding'), $this->getTotalOutstandingAsMoney()->Nice())
710
                )
711
            );
712
            if ($this->canPay()) {
713
                $link = EcommercePaymentController::make_payment_link($this->ID);
714
                $js = "window.open(this.href, 'payment', 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=800,height=600'); return false;";
715
                $header = _t('Order.MAKEPAYMENT', 'make payment');
716
                $label = _t('Order.MAKEADDITIONALPAYMENTNOW', 'make additional payment now');
717
                $linkHTML = '<a href="'.$link.'" onclick="'.$js.'">'.$label.'</a>';
718
                $fields->addFieldToTab('Root.Payments', new HeaderField('MakeAdditionalPaymentHeader', $header, 3));
719
                $fields->addFieldToTab('Root.Payments', new LiteralField('MakeAdditionalPayment', $linkHTML));
720
            }
721
            //member
722
            $member = $this->Member();
0 ignored issues
show
Bug introduced by
The method Member() does not exist on Order. Did you maybe mean CreateOrReturnExistingMember()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
723
            if ($member && $member->exists()) {
724
                $fields->addFieldToTab('Root.Account', new LiteralField('MemberDetails', $member->getEcommerceFieldsForCMS()));
725
            } else {
726
                $fields->addFieldToTab('Root.Account', new LiteralField('MemberDetails',
727
                    '<p>'._t('Order.NO_ACCOUNT', 'There is no --- account --- associated with this order').'</p>'
728
                ));
729
            }
730
            $cancelledField = $fields->dataFieldByName('CancelledByID');
731
            $fields->removeByName('CancelledByID');
732
            $shopAdminAndCurrentCustomerArray = EcommerceRole::list_of_admins(true);
733
            if ($member && $member->exists()) {
734
                $shopAdminAndCurrentCustomerArray[$member->ID] = $member->getName();
735
            }
736
            if ($this->CancelledByID) {
0 ignored issues
show
Documentation introduced by
The property CancelledByID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
737
                if ($cancellingMember = $this->CancelledBy()) {
0 ignored issues
show
Documentation Bug introduced by
The method CancelledBy does not exist on object<Order>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
738
                    $shopAdminAndCurrentCustomerArray[$this->CancelledByID] = $cancellingMember->getName();
0 ignored issues
show
Documentation introduced by
The property CancelledByID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
739
                }
740
            }
741
            if ($this->canCancel()) {
742
                $fields->addFieldsToTab(
743
                    'Root.Cancellations',
744
                    array(
745
                        DropdownField::create(
746
                            'CancelledByID',
747
                            $cancelledField->Title(),
748
                            $shopAdminAndCurrentCustomerArray
749
                        )
750
                    )
751
                );
752
            } else {
753
                $cancelledBy = isset($shopAdminAndCurrentCustomerArray[$this->CancelledByID]) && $this->CancelledByID ? $shopAdminAndCurrentCustomerArray[$this->CancelledByID] : _t('Order.NOT_CANCELLED', 'not cancelled');
0 ignored issues
show
Documentation introduced by
The property CancelledByID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
754
                $fields->addFieldsToTab(
755
                    'Root.Cancellations',
756
                    ReadonlyField::create(
757
                        'CancelledByDisplay',
758
                        $cancelledField->Title(),
759
                        $cancelledBy
760
761
                    )
762
                );
763
            }
764
            $fields->addFieldToTab('Root.Log', $this->getOrderStatusLogsTableField_Archived());
765
            $submissionLog = $this->SubmissionLog();
766
            if ($submissionLog) {
767
                $fields->addFieldToTab('Root.Log',
768
                    ReadonlyField::create(
769
                        'SequentialOrderNumber',
770
                        _t('Order.SEQUENTIALORDERNUMBER', 'Consecutive order number'),
771
                        $submissionLog->SequentialOrderNumber
772
                    )->setRightTitle('e.g. 1,2,3,4,5...')
773
                );
774
            }
775
        } else {
776
            $linkText = _t(
777
                'Order.LOAD_THIS_ORDER',
778
                'load this order'
779
            );
780
            $message = _t(
781
                'Order.NOSUBMITTEDYET',
782
                'No details are shown here as this order has not been submitted yet. You can {link} to submit it... NOTE: For this, you will be logged in as the customer and logged out as (shop)admin .',
783
                array('link' => '<a href="'.$this->getRetrieveLink().'" data-popup="true">'.$linkText.'</a>')
0 ignored issues
show
Documentation introduced by
array('link' => '<a href...' . $linkText . '</a>') is of type array<string,string,{"link":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
784
            );
785
            $fields->addFieldToTab('Root.Next', new LiteralField('MainDetails', '<p>'.$message.'</p>'));
786
            $fields->addFieldToTab('Root.Items', $this->getOrderItemsField());
787
            $fields->addFieldToTab('Root.Extras', $this->getModifierTableField());
788
789
            //MEMBER STUFF
790
            $specialOptionsArray = array();
791
            if ($this->MemberID) {
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
792
                $specialOptionsArray[0] = _t('Order.SELECTCUSTOMER', '--- Remover Customer ---');
793
                $specialOptionsArray[$this->MemberID] = _t('Order.LEAVEWITHCURRENTCUSTOMER', '- Leave with current customer: ').$this->Member()->getTitle();
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method Member() does not exist on Order. Did you maybe mean CreateOrReturnExistingMember()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
794
            } elseif ($currentMember) {
795
                $specialOptionsArray[0] = _t('Order.SELECTCUSTOMER', '--- Select Customers ---');
796
                $currentMemberID = $currentMember->ID;
797
                $specialOptionsArray[$currentMemberID] = _t('Order.ASSIGNTHISORDERTOME', '- Assign this order to me: ').$currentMember->getTitle();
798
            }
799
            //MEMBER FIELD!!!!!!!
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
800
            $memberArray = $specialOptionsArray + EcommerceRole::list_of_customers(true);
801
            $fields->addFieldToTab('Root.Next', new DropdownField('MemberID', _t('Order.SELECTCUSTOMER', 'Select Customer'), $memberArray), 'CustomerOrderNote');
802
            $memberArray = null;
0 ignored issues
show
Unused Code introduced by
$memberArray is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
803
        }
804
        $fields->addFieldToTab('Root.Addresses', new HeaderField('BillingAddressHeader', _t('Order.BILLINGADDRESS', 'Billing Address')));
805
806
        $fields->addFieldToTab('Root.Addresses', $this->getBillingAddressField());
807
808
        if (EcommerceConfig::get('OrderAddress', 'use_separate_shipping_address')) {
809
            $fields->addFieldToTab('Root.Addresses', new HeaderField('ShippingAddressHeader', _t('Order.SHIPPINGADDRESS', 'Shipping Address')));
810
            $fields->addFieldToTab('Root.Addresses', new CheckboxField('UseShippingAddress', _t('Order.USESEPERATEADDRESS', 'Use separate shipping address?')));
811
            if ($this->UseShippingAddress) {
0 ignored issues
show
Documentation introduced by
The property UseShippingAddress does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
812
                $fields->addFieldToTab('Root.Addresses', $this->getShippingAddressField());
813
            }
814
        }
815
        $currencies = EcommerceCurrency::get_list();
816
        if ($currencies && $currencies->count()) {
817
            $currencies = $currencies->map()->toArray();
818
            $fields->addFieldToTab('Root.Currency', new ReadOnlyField('ExchangeRate ', _t('Order.EXCHANGERATE', 'Exchange Rate'), $this->ExchangeRate));
0 ignored issues
show
Documentation introduced by
The property ExchangeRate does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
819
            $fields->addFieldToTab('Root.Currency', $currencyField = new DropdownField('CurrencyUsedID', _t('Order.CurrencyUsed', 'Currency Used'), $currencies));
820
            if ($this->IsSubmitted()) {
821
                $fields->replaceField('CurrencyUsedID', $fields->dataFieldByName('CurrencyUsedID')->performReadonlyTransformation());
822
            }
823
        } else {
824
            $fields->addFieldToTab('Root.Currency', new LiteralField('CurrencyInfo', '<p>You can not change currencies, because no currencies have been created.</p>'));
825
            $fields->replaceField('CurrencyUsedID', $fields->dataFieldByName('CurrencyUsedID')->performReadonlyTransformation());
826
        }
827
        $fields->addFieldToTab('Root.Log', new ReadonlyField('Created', _t('Root.CREATED', 'Created')));
828
        $fields->addFieldToTab('Root.Log', new ReadonlyField('LastEdited', _t('Root.LASTEDITED', 'Last saved')));
829
        $this->extend('updateCMSFields', $fields);
830
831
        return $fields;
832
    }
833
834
    /**
835
     * Field to add and edit Order Items.
836
     *
837
     * @return GridField
838
     */
839
    protected function getOrderItemsField()
840
    {
841
        $gridFieldConfig = GridFieldConfigForOrderItems::create();
842
        $source = $this->OrderItems();
843
844
        return new GridField('OrderItems', _t('OrderItems.PLURALNAME', 'Order Items'), $source, $gridFieldConfig);
845
    }
846
847
    /**
848
     * Field to add and edit Modifiers.
849
     *
850
     * @return GridField
851
     */
852
    public function getModifierTableField()
853
    {
854
        $gridFieldConfig = GridFieldConfigForOrderItems::create();
855
        $source = $this->Modifiers();
856
857
        return new GridField('OrderModifiers', _t('OrderItems.PLURALNAME', 'Order Items'), $source, $gridFieldConfig);
858
    }
859
860
    /**
861
     *@return GridField
862
     **/
863
    protected function getBillingAddressField()
864
    {
865
        $this->CreateOrReturnExistingAddress('BillingAddress');
866
        $gridFieldConfig = GridFieldConfig::create()->addComponents(
867
            new GridFieldToolbarHeader(),
868
            new GridFieldSortableHeader(),
869
            new GridFieldDataColumns(),
870
            new GridFieldPaginator(10),
871
            new GridFieldEditButton(),
872
            new GridFieldDetailForm()
873
        );
874
        //$source = $this->BillingAddress();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
875
        $source = BillingAddress::get()->filter(array('OrderID' => $this->ID));
876
877
        return new GridField('BillingAddress', _t('BillingAddress.SINGULARNAME', 'Billing Address'), $source, $gridFieldConfig);
878
    }
879
880
    /**
881
     *@return GridField
882
     **/
883
    protected function getShippingAddressField()
884
    {
885
        $this->CreateOrReturnExistingAddress('ShippingAddress');
886
        $gridFieldConfig = GridFieldConfig::create()->addComponents(
887
            new GridFieldToolbarHeader(),
888
            new GridFieldSortableHeader(),
889
            new GridFieldDataColumns(),
890
            new GridFieldPaginator(10),
891
            new GridFieldEditButton(),
892
            new GridFieldDetailForm()
893
        );
894
        //$source = $this->ShippingAddress();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
895
        $source = ShippingAddress::get()->filter(array('OrderID' => $this->ID));
896
897
        return new GridField('ShippingAddress', _t('BillingAddress.SINGULARNAME', 'Shipping Address'), $source, $gridFieldConfig);
898
    }
899
900
    /**
901
     * Needs to be public because the OrderStep::getCMSFIelds accesses it.
902
     *
903
     * @param string    $sourceClass
904
     * @param string    $title
905
     *
906
     * @return GridField
907
     **/
908
    public function getOrderStatusLogsTableField(
909
        $sourceClass = 'OrderStatusLog',
910
        $title = ''
911
    ) {
912
        $gridFieldConfig = GridFieldConfig_RecordViewer::create()->addComponents(
913
            new GridFieldAddNewButton('toolbar-header-right'),
914
            new GridFieldDetailForm()
915
        );
916
        $title ? $title : $title = _t('OrderStatusLog.PLURALNAME', 'Order Status Logs');
917
        $source = $this->OrderStatusLogs()->Filter(array('ClassName' => $sourceClass));
0 ignored issues
show
Bug introduced by
The method OrderStatusLogs() does not exist on Order. Did you maybe mean getOrderStatusLogsTableField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
918
        $gf = new GridField($sourceClass, $title, $source, $gridFieldConfig);
919
        $gf->setModelClass($sourceClass);
920
921
        return $gf;
922
    }
923
924
    /**
925
     * Needs to be public because the OrderStep::getCMSFIelds accesses it.
926
     *
927
     * @param string    $sourceClass
928
     * @param string    $title
929
     *
930
     * @return GridField
931
     **/
932
    public function getOrderStatusLogsTableFieldEditable(
933
        $sourceClass = 'OrderStatusLog',
934
        $title = ''
935
    ) {
936
        $gf = $this->getOrderStatusLogsTableField($sourceClass, $title);
937
        $gf->getConfig()->addComponents(
938
            new GridFieldEditButton()
939
        );
940
        return $gf;
941
    }
942
943
    /**
944
     * @param string    $sourceClass
945
     * @param string    $title
946
     * @param FieldList $fieldList          (Optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $fieldList not be null|FieldList?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
947
     * @param FieldList $detailedFormFields (Optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $detailedFormFields not be null|FieldList?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
948
     *
949
     * @return GridField
950
     **/
951
    protected function getOrderStatusLogsTableField_Archived(
952
        $sourceClass = 'OrderStatusLog',
953
        $title = '',
954
        FieldList $fieldList = null,
0 ignored issues
show
Unused Code introduced by
The parameter $fieldList is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
955
        FieldList $detailedFormFields = null
0 ignored issues
show
Unused Code introduced by
The parameter $detailedFormFields is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
956
    ) {
957
        $title ? $title : $title = _t('OrderLog.PLURALNAME', 'Order Log');
958
        $source = $this->OrderStatusLogs();
0 ignored issues
show
Bug introduced by
The method OrderStatusLogs() does not exist on Order. Did you maybe mean getOrderStatusLogsTableField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
959
        if ($sourceClass != 'OrderStatusLog' && class_exists($sourceClass)) {
960
            $source = $source->filter(array('ClassName' => ClassInfo::subclassesFor($sourceClass)));
961
        }
962
        $gridField = GridField::create($sourceClass, $title, $source, $config = GridFieldConfig_RelationEditor::create());
963
        $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
964
        $config->removeComponentsByType('GridFieldDeleteAction');
965
966
        return $gridField;
967
    }
968
969
    /**
970
     * @return GridField
971
     **/
972
    public function getEmailsTableField()
973
    {
974
        $gridFieldConfig = GridFieldConfig_RecordViewer::create()->addComponents(
975
            new GridFieldDetailForm()
976
        );
977
978
        return new GridField('Emails', _t('Order.CUSTOMER_EMAILS', 'Customer Emails'), $this->Emails(), $gridFieldConfig);
0 ignored issues
show
Bug introduced by
The method Emails() does not exist on Order. Did you maybe mean getEmailsTableField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
979
    }
980
981
    /**
982
     * @return GridField
983
     */
984
    protected function getPaymentsField()
985
    {
986
        $gridFieldConfig = GridFieldConfig_RecordViewer::create()->addComponents(
987
            new GridFieldDetailForm(),
988
            new GridFieldEditButton()
989
        );
990
991
        return new GridField('Payments', _t('Order.PAYMENTS', 'Payments'), $this->Payments(), $gridFieldConfig);
0 ignored issues
show
Bug introduced by
The method Payments() does not exist on Order. Did you maybe mean getPaymentsField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
992
    }
993
994
    /**
995
     * @return OrderStepField
996
     */
997
    public function OrderStepField()
998
    {
999
        return OrderStepField::create($name = 'MyOrderStep', $this, Member::currentUser());
1000
    }
1001
1002
/*******************************************************
1003
   * 2. MAIN TRANSITION FUNCTIONS
1004
*******************************************************/
1005
1006
    /**
1007
     * init runs on start of a new Order (@see onAfterWrite)
1008
     * it adds all the modifiers to the orders and the starting OrderStep.
1009
     *
1010
     * @param bool $recalculate
1011
     *
1012
     * @return DataObject (Order)
1013
     **/
1014
    public function init($recalculate = false)
1015
    {
1016
        if ($this->IsSubmitted()) {
1017
            user_error('Can not init an order that has been submitted', E_USER_NOTICE);
1018
        } else {
1019
            //to do: check if shop is open....
1020
            if ($this->StatusID || $recalculate) {
0 ignored issues
show
Documentation introduced by
The property StatusID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1021
                if (!$this->StatusID) {
0 ignored issues
show
Documentation introduced by
The property StatusID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1022
                    $createdOrderStatus = OrderStep::get()->First();
1023
                    if (!$createdOrderStatus) {
1024
                        user_error('No ordersteps have been created', E_USER_WARNING);
1025
                    }
1026
                    $this->StatusID = $createdOrderStatus->ID;
0 ignored issues
show
Documentation introduced by
The property StatusID does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1027
                }
1028
                $createdModifiersClassNames = array();
1029
                $modifiersAsArrayList = new ArrayList();
1030
                $modifiers = $this->modifiersFromDatabase($includingRemoved = true);
0 ignored issues
show
Documentation introduced by
$includingRemoved = true is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
1031
                if ($modifiers->count()) {
1032
                    foreach ($modifiers as $modifier) {
1033
                        $modifiersAsArrayList->push($modifier);
1034
                    }
1035
                }
1036
                if ($modifiersAsArrayList->count()) {
1037
                    foreach ($modifiersAsArrayList as $modifier) {
1038
                        $createdModifiersClassNames[$modifier->ID] = $modifier->ClassName;
1039
                    }
1040
                } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
1041
                }
1042
                $modifiersToAdd = EcommerceConfig::get('Order', 'modifiers');
1043
                if (is_array($modifiersToAdd) && count($modifiersToAdd) > 0) {
1044
                    foreach ($modifiersToAdd as $numericKey => $className) {
1045
                        if (!in_array($className, $createdModifiersClassNames)) {
1046
                            if (class_exists($className)) {
1047
                                $modifier = new $className();
1048
                                //only add the ones that should be added automatically
1049
                                if (!$modifier->DoNotAddAutomatically()) {
1050
                                    if (is_a($modifier, 'OrderModifier')) {
1051
                                        $modifier->OrderID = $this->ID;
1052
                                        $modifier->Sort = $numericKey;
1053
                                        //init method includes a WRITE
1054
                                        $modifier->init();
1055
                                        //IMPORTANT - add as has_many relationship  (Attributes can be a modifier OR an OrderItem)
1056
                                        $this->Attributes()->add($modifier);
0 ignored issues
show
Bug introduced by
The method Attributes() does not exist on Order. Did you maybe mean getOrderAttributesByType()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1057
                                        $modifiersAsArrayList->push($modifier);
1058
                                    }
1059
                                }
1060
                            } else {
1061
                                user_error('reference to a non-existing class: '.$className.' in modifiers', E_USER_NOTICE);
1062
                            }
1063
                        }
1064
                    }
1065
                }
1066
                $this->extend('onInit', $this);
1067
                //careful - this will call "onAfterWrite" again
1068
                $this->write();
1069
            }
1070
        }
1071
1072
        return $this;
1073
    }
1074
1075
    /**
1076
     * @var array
1077
     */
1078
    private static $_try_to_finalise_order_is_running = array();
1079
1080
    /**
1081
     * Goes through the order steps and tries to "apply" the next status to the order.
1082
     *
1083
     * @param bool $runAgain
1084
     * @param bool $fromOrderQueue - is it being called from the OrderProcessQueue (or similar)
1085
     **/
1086
    public function tryToFinaliseOrder($runAgain = false, $fromOrderQueue = false)
1087
    {
1088
        if (empty(self::$_try_to_finalise_order_is_running[$this->ID]) || $runAgain) {
1089
            self::$_try_to_finalise_order_is_running[$this->ID] = true;
1090
            if ($this->CancelledByID) {
0 ignored issues
show
Documentation introduced by
The property CancelledByID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1091
                $this->Archive(true);
1092
1093
                return;
1094
            }
1095
            //does a queue object already exist
1096
            $queueObjectSingleton = Injector::inst()->get('OrderProcessQueue');
1097
            if ($myQueueObject = $queueObjectSingleton->getQueueObject($this)) {
1098
                if ($myQueueObject->InProcess) {
1099
                    if (! $fromOrderQueue) {
1100
                        return;
1101
                    }
1102
                }
1103
            }
1104
            //a little hack to make sure we do not rely on a stored value
1105
            //of "isSubmitted"
1106
            $this->_isSubmittedTempVar = -1;
0 ignored issues
show
Documentation Bug introduced by
The property $_isSubmittedTempVar was declared of type boolean, but -1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
1107
            //status of order is being progressed
1108
            $nextStatusID = $this->doNextStatus();
1109
            if ($nextStatusID) {
1110
                $nextStatusObject = OrderStep::get()->byID($nextStatusID);
1111
                if ($nextStatusObject) {
1112
                    $delay = $nextStatusObject->CalculatedDeferTimeInSeconds($this);
1113
                    if ($delay > 0) {
1114
                        if ($nextStatusObject->DeferFromSubmitTime) {
1115
                            $delay = $delay - $this->SecondsSinceBeingSubmitted();
1116
                            if ($delay < 0) {
1117
                                $delay = 0;
1118
                            }
1119
                        }
1120
                        $queueObjectSingleton->AddOrderToQueue(
1121
                            $this,
1122
                            $delay
1123
                        );
1124
                    } else {
1125
                        //status has been completed, so it can be released
1126
                        self::$_try_to_finalise_order_is_running[$this->ID] = false;
1127
                        $this->tryToFinaliseOrder($runAgain, $fromOrderQueue);
1128
                    }
1129
                }
1130
            }
1131
        }
1132
    }
1133
1134
    /**
1135
     * Goes through the order steps and tries to "apply" the next step
1136
     * Step is updated after the other one is completed...
1137
     *
1138
     * @return int (StatusID or false if the next status can not be "applied")
1139
     **/
1140
    public function doNextStatus()
1141
    {
1142
        if ($this->MyStep()->initStep($this)) {
1143
            if ($this->MyStep()->doStep($this)) {
1144
                if ($nextOrderStepObject = $this->MyStep()->nextStep($this)) {
1145
                    $this->StatusID = $nextOrderStepObject->ID;
0 ignored issues
show
Documentation introduced by
The property StatusID does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1146
                    $this->write();
1147
1148
                    return $this->StatusID;
0 ignored issues
show
Documentation introduced by
The property StatusID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1149
                }
1150
            }
1151
        }
1152
1153
        return 0;
1154
    }
1155
1156
    /**
1157
     * cancel an order.
1158
     *
1159
     * @param Member $member - the user cancelling the order
1160
     * @param string $reason - the reason the order is cancelled
1161
     *
1162
     * @return OrderStatusLog_Cancel
0 ignored issues
show
Documentation introduced by
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1163
     */
1164
    public function Cancel(Member $member, $reason = '')
1165
    {
1166
        $this->CancelledByID = $member->ID;
0 ignored issues
show
Documentation introduced by
The property CancelledByID does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1167
        //archive and write
1168
        $this->Archive($avoidWrites = true);
1169
        //create log ...
1170
        $log = OrderStatusLog_Cancel::create();
1171
        $log->AuthorID = $member->ID;
0 ignored issues
show
Documentation introduced by
The property AuthorID does not exist on object<OrderStatusLog_Cancel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1172
        $log->OrderID = $this->ID;
0 ignored issues
show
Documentation introduced by
The property OrderID does not exist on object<OrderStatusLog_Cancel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1173
        $log->Note = $reason;
0 ignored issues
show
Documentation introduced by
The property Note does not exist on object<OrderStatusLog_Cancel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1174
        if ($member->IsShopAdmin()) {
1175
            $log->InternalUseOnly = true;
0 ignored issues
show
Documentation introduced by
The property InternalUseOnly does not exist on object<OrderStatusLog_Cancel>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1176
        }
1177
1178
        return $log->write();
1179
    }
1180
1181
    /**
1182
     * returns true if successful.
1183
     *
1184
     * @param bool $avoidWrites
1185
     *
1186
     * @return bool
1187
     */
1188
    public function Archive($avoidWrites = true)
1189
    {
1190
        $lastOrderStep = OrderStep::get()->Last();
1191
        if ($lastOrderStep) {
1192
            if ($avoidWrites) {
1193
                DB::query('
1194
                    UPDATE "Order"
1195
                    SET "Order"."StatusID" = '.$lastOrderStep->ID.'
1196
                    WHERE "Order"."ID" = '.$this->ID.'
1197
                    LIMIT 1
1198
                ');
1199
1200
                return true;
1201
            } else {
1202
                $this->StatusID = $lastOrderStep->ID;
0 ignored issues
show
Documentation introduced by
The property StatusID does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1203
                $this->write();
1204
1205
                return true;
1206
            }
1207
        }
1208
1209
        return false;
1210
    }
1211
1212
/*******************************************************
1213
   * 3. STATUS RELATED FUNCTIONS / SHORTCUTS
1214
*******************************************************/
1215
1216
    /**
1217
     * Avoids caching of $this->Status().
1218
     *
1219
     * @return DataObject (current OrderStep)
1220
     */
1221
    public function MyStep()
1222
    {
1223
        $step = null;
1224
        if ($this->StatusID) {
0 ignored issues
show
Documentation introduced by
The property StatusID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1225
            $step = OrderStep::get()->byID($this->StatusID);
0 ignored issues
show
Documentation introduced by
The property StatusID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1226
        }
1227
        if (!$step) {
1228
            $step = OrderStep::get()->First(); //TODO: this could produce strange results
1229
        }
1230
        if (!$step) {
1231
            $step = OrderStep_Created::create();
1232
        }
1233
        if (!$step) {
1234
            user_error('You need an order step in your Database.');
1235
        }
1236
1237
        return $step;
1238
    }
1239
1240
    /**
1241
     * Return the OrderStatusLog that is relevant to the Order status.
1242
     *
1243
     * @return OrderStatusLog
1244
     */
1245
    public function RelevantLogEntry()
1246
    {
1247
        return $this->MyStep()->RelevantLogEntry($this);
1248
    }
1249
1250
    /**
1251
     * @return OrderStep (current OrderStep that can be seen by customer)
0 ignored issues
show
Documentation introduced by
Should the return type not be OrderStep|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1252
     */
1253
    public function CurrentStepVisibleToCustomer()
1254
    {
1255
        $obj = $this->MyStep();
1256
        if ($obj->HideStepFromCustomer) {
1257
            $obj = OrderStep::get()->where('"OrderStep"."Sort" < '.$obj->Sort.' AND "HideStepFromCustomer" = 0')->Last();
1258
            if (!$obj) {
1259
                $obj = OrderStep::get()->First();
1260
            }
1261
        }
1262
1263
        return $obj;
1264
    }
1265
1266
    /**
1267
     * works out if the order is still at the first OrderStep.
1268
     *
1269
     * @return bool
1270
     */
1271
    public function IsFirstStep()
1272
    {
1273
        $firstStep = OrderStep::get()->First();
1274
        $currentStep = $this->MyStep();
1275
        if ($firstStep && $currentStep) {
1276
            if ($firstStep->ID == $currentStep->ID) {
1277
                return true;
1278
            }
1279
        }
1280
1281
        return false;
1282
    }
1283
1284
    /**
1285
     * Is the order still being "edited" by the customer?
1286
     *
1287
     * @return bool
1288
     */
1289
    public function IsInCart()
1290
    {
1291
        return (bool) $this->IsSubmitted() ? false : true;
1292
    }
1293
1294
    /**
1295
     * The order has "passed" the IsInCart phase.
1296
     *
1297
     * @return bool
1298
     */
1299
    public function IsPastCart()
1300
    {
1301
        return (bool) $this->IsInCart() ? false : true;
1302
    }
1303
1304
    /**
1305
     * Are there still steps the order needs to go through?
1306
     *
1307
     * @return bool
1308
     */
1309
    public function IsUncomplete()
1310
    {
1311
        return (bool) $this->MyStep()->ShowAsUncompletedOrder;
1312
    }
1313
1314
    /**
1315
     * Is the order in the :"processing" phaase.?
1316
     *
1317
     * @return bool
1318
     */
1319
    public function IsProcessing()
1320
    {
1321
        return (bool) $this->MyStep()->ShowAsInProcessOrder;
1322
    }
1323
1324
    /**
1325
     * Is the order completed?
1326
     *
1327
     * @return bool
1328
     */
1329
    public function IsCompleted()
1330
    {
1331
        return (bool) $this->MyStep()->ShowAsCompletedOrder;
1332
    }
1333
1334
    /**
1335
     * Has the order been paid?
1336
     * TODO: why do we check if there is a total at all?
1337
     *
1338
     * @return bool
1339
     */
1340
    public function IsPaid()
1341
    {
1342
        if ($this->IsSubmitted()) {
1343
            return (bool) (($this->Total() >= 0) && ($this->TotalOutstanding() <= 0));
1344
        }
1345
1346
        return false;
1347
    }
1348
1349
    /**
1350
     * Has the order been paid?
1351
     * TODO: why do we check if there is a total at all?
1352
     *
1353
     * @return bool
1354
     */
1355
    public function PaymentIsPending()
1356
    {
1357
        if ($this->IsSubmitted()) {
1358
            if ($this->IsPaid()) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
1359
                //do nothing;
1360
            } elseif (($payments = $this->Payments()) && $payments->count()) {
0 ignored issues
show
Bug introduced by
The method Payments() does not exist on Order. Did you maybe mean getPaymentsField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1361
                foreach ($payments as $payment) {
1362
                    if ('Pending' == $payment->Status) {
1363
                        return true;
1364
                    }
1365
                }
1366
            }
1367
        }
1368
1369
        return false;
1370
    }
1371
1372
    /**
1373
     * shows payments that are meaningfull
1374
     * if the order has been paid then only show successful payments.
1375
     *
1376
     * @return DataList
1377
     */
1378
    public function RelevantPayments()
1379
    {
1380
        if ($this->IsPaid()) {
1381
            return $this->Payments("\"Status\" = 'Success'");
0 ignored issues
show
Bug introduced by
The method Payments() does not exist on Order. Did you maybe mean getPaymentsField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1382
            //EcommercePayment::get()->
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1383
            //	filter(array("OrderID" => $this->ID, "Status" => "Success"));
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1384
        } else {
1385
            return $this->Payments();
0 ignored issues
show
Bug introduced by
The method Payments() does not exist on Order. Did you maybe mean getPaymentsField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1386
        }
1387
    }
1388
1389
    /**
1390
     * Has the order been cancelled?
1391
     *
1392
     * @return bool
1393
     */
1394
    public function IsCancelled()
1395
    {
1396
        return $this->getIsCancelled();
1397
    }
1398
    public function getIsCancelled()
1399
    {
1400
        return $this->CancelledByID ? true : false;
0 ignored issues
show
Documentation introduced by
The property CancelledByID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1401
    }
1402
1403
    /**
1404
     * Has the order been cancelled by the customer?
1405
     *
1406
     * @return bool
1407
     */
1408
    public function IsCustomerCancelled()
1409
    {
1410
        if ($this->MemberID > 0 && $this->MemberID == $this->IsCancelledID) {
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property IsCancelledID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Unused Code introduced by
This if statement, and the following return statement can be replaced with return $this->MemberID >...= $this->IsCancelledID;.
Loading history...
1411
            return true;
1412
        }
1413
1414
        return false;
1415
    }
1416
1417
    /**
1418
     * Has the order been cancelled by the  administrator?
1419
     *
1420
     * @return bool
1421
     */
1422
    public function IsAdminCancelled()
1423
    {
1424
        if ($this->IsCancelled()) {
1425
            if (!$this->IsCustomerCancelled()) {
1426
                $admin = Member::get()->byID($this->CancelledByID);
0 ignored issues
show
Documentation introduced by
The property CancelledByID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1427
                if ($admin) {
1428
                    if ($admin->IsShopAdmin()) {
1429
                        return true;
1430
                    }
1431
                }
1432
            }
1433
        }
1434
1435
        return false;
1436
    }
1437
1438
    /**
1439
     * Is the Shop Closed for business?
1440
     *
1441
     * @return bool
1442
     */
1443
    public function ShopClosed()
1444
    {
1445
        return EcomConfig()->ShopClosed;
1446
    }
1447
1448
/*******************************************************
1449
   * 4. LINKING ORDER WITH MEMBER AND ADDRESS
1450
*******************************************************/
1451
1452
    /**
1453
     * Returns a member linked to the order.
1454
     * If a member is already linked, it will return the existing member.
1455
     * Otherwise it will return a new Member.
1456
     *
1457
     * Any new member is NOT written, because we dont want to create a new member unless we have to!
1458
     * We will not add a member to the order unless a new one is created in the checkout
1459
     * OR the member is logged in / logs in.
1460
     *
1461
     * Also note that if a new member is created, it is not automatically written
1462
     *
1463
     * @param bool $forceCreation - if set to true then the member will always be saved in the database.
1464
     *
1465
     * @return Member
1466
     **/
1467
    public function CreateOrReturnExistingMember($forceCreation = false)
1468
    {
1469
        if ($this->IsSubmitted()) {
1470
            return $this->Member();
0 ignored issues
show
Bug introduced by
The method Member() does not exist on Order. Did you maybe mean CreateOrReturnExistingMember()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1471
        }
1472
        if ($this->MemberID) {
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1473
            $member = $this->Member();
0 ignored issues
show
Bug introduced by
The method Member() does not exist on Order. Did you maybe mean CreateOrReturnExistingMember()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
Unused Code introduced by
$member is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1474
        } elseif ($member = Member::currentUser()) {
1475
            if (!$member->IsShopAdmin()) {
1476
                $this->MemberID = $member->ID;
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1477
                $this->write();
1478
            }
1479
        }
1480
        $member = $this->Member();
0 ignored issues
show
Bug introduced by
The method Member() does not exist on Order. Did you maybe mean CreateOrReturnExistingMember()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
1481
        if (!$member) {
1482
            $member = new Member();
1483
        }
1484
        if ($member && $forceCreation) {
1485
            $member->write();
1486
        }
1487
1488
        return $member;
1489
    }
1490
1491
    /**
1492
     * Returns either the existing one or a new Order Address...
1493
     * All Orders will have a Shipping and Billing address attached to it.
1494
     * Method used to retrieve object e.g. for $order->BillingAddress(); "BillingAddress" is the method name you can use.
1495
     * If the method name is the same as the class name then dont worry about providing one.
1496
     *
1497
     * @param string $className             - ClassName of the Address (e.g. BillingAddress or ShippingAddress)
1498
     * @param string $alternativeMethodName - method to retrieve Address
1499
     **/
1500
    public function CreateOrReturnExistingAddress($className = 'BillingAddress', $alternativeMethodName = '')
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
1501
    {
1502
        if ($this->exists()) {
1503
            $methodName = $className;
1504
            if ($alternativeMethodName) {
1505
                $methodName = $alternativeMethodName;
1506
            }
1507
            if ($this->IsSubmitted()) {
1508
                return $this->$methodName();
1509
            }
1510
            $variableName = $className.'ID';
1511
            $address = null;
1512
            if ($this->$variableName) {
1513
                $address = $this->$methodName();
1514
            }
1515
            if (!$address) {
1516
                $address = new $className();
1517
                if ($member = $this->CreateOrReturnExistingMember()) {
1518
                    if ($member->exists()) {
1519
                        $address->FillWithLastAddressFromMember($member, $write = false);
1520
                    }
1521
                }
1522
            }
1523
            if ($address) {
1524
                if (!$address->exists()) {
1525
                    $address->write();
1526
                }
1527
                if ($address->OrderID != $this->ID) {
1528
                    $address->OrderID = $this->ID;
1529
                    $address->write();
1530
                }
1531
                if ($this->$variableName != $address->ID) {
1532
                    if (!$this->IsSubmitted()) {
1533
                        $this->$variableName = $address->ID;
1534
                        $this->write();
1535
                    }
1536
                }
1537
1538
                return $address;
1539
            }
1540
        }
1541
1542
        return;
1543
    }
1544
1545
    /**
1546
     * Sets the country in the billing and shipping address.
1547
     *
1548
     * @param string $countryCode            - code for the country e.g. NZ
1549
     * @param bool   $includeBillingAddress
1550
     * @param bool   $includeShippingAddress
1551
     **/
1552
    public function SetCountryFields($countryCode, $includeBillingAddress = true, $includeShippingAddress = true)
1553
    {
1554
        if ($this->IsSubmitted()) {
1555
            user_error('Can not change country in submitted order', E_USER_NOTICE);
1556
        } else {
1557
            if ($includeBillingAddress) {
1558
                if ($billingAddress = $this->CreateOrReturnExistingAddress('BillingAddress')) {
1559
                    $billingAddress->SetCountryFields($countryCode);
1560
                }
1561
            }
1562
            if (EcommerceConfig::get('OrderAddress', 'use_separate_shipping_address')) {
1563
                if ($includeShippingAddress) {
1564
                    if ($shippingAddress = $this->CreateOrReturnExistingAddress('ShippingAddress')) {
1565
                        $shippingAddress->SetCountryFields($countryCode);
1566
                    }
1567
                }
1568
            }
1569
        }
1570
    }
1571
1572
    /**
1573
     * Sets the region in the billing and shipping address.
1574
     *
1575
     * @param int $regionID - ID for the region to be set
1576
     **/
1577
    public function SetRegionFields($regionID)
1578
    {
1579
        if ($this->IsSubmitted()) {
1580
            user_error('Can not change country in submitted order', E_USER_NOTICE);
1581
        } else {
1582
            if ($billingAddress = $this->CreateOrReturnExistingAddress('BillingAddress')) {
1583
                $billingAddress->SetRegionFields($regionID);
1584
            }
1585
            if ($this->CanHaveShippingAddress()) {
1586
                if ($shippingAddress = $this->CreateOrReturnExistingAddress('ShippingAddress')) {
1587
                    $shippingAddress->SetRegionFields($regionID);
1588
                }
1589
            }
1590
        }
1591
    }
1592
1593
    /**
1594
     * Stores the preferred currency of the order.
1595
     * IMPORTANTLY we store the exchange rate for future reference...
1596
     *
1597
     * @param EcommerceCurrency $currency
0 ignored issues
show
Documentation introduced by
There is no parameter named $currency. Did you maybe mean $newCurrency?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
1598
     */
1599
    public function UpdateCurrency($newCurrency)
1600
    {
1601
        if ($this->IsSubmitted()) {
1602
            user_error('Can not set the currency after the order has been submitted', E_USER_NOTICE);
1603
        } else {
1604
            if (! is_a($newCurrency, Object::getCustomClass('EcommerceCurrency'))) {
1605
                $newCurrency = EcommerceCurrency::default_currency();
1606
            }
1607
            $this->CurrencyUsedID = $newCurrency->ID;
0 ignored issues
show
Documentation introduced by
The property CurrencyUsedID does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1608
            $this->ExchangeRate = $newCurrency->getExchangeRate();
0 ignored issues
show
Documentation introduced by
The property ExchangeRate does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1609
            $this->write();
1610
        }
1611
    }
1612
1613
    /**
1614
     * alias for UpdateCurrency.
1615
     *
1616
     * @param EcommerceCurrency $currency
1617
     */
1618
    public function SetCurrency($currency)
1619
    {
1620
        $this->UpdateCurrency($currency);
1621
    }
1622
1623
/*******************************************************
1624
   * 5. CUSTOMER COMMUNICATION
1625
*******************************************************/
1626
1627
    /**
1628
     * Send the invoice of the order by email.
1629
     *
1630
     * @param string $emailClassName     (optional) class used to send email
1631
     * @param string $subject            (optional) subject for the email
1632
     * @param string $message            (optional) the main message in the email
1633
     * @param bool   $resend             (optional) send the email even if it has been sent before
1634
     * @param bool   $adminOnlyOrToEmail (optional) sends the email to the ADMIN ONLY, if you provide an email, it will go to the email...
1635
     *
1636
     * @return bool TRUE on success, FALSE on failure
1637
     */
1638
    public function sendEmail(
1639
        $emailClassName = 'Order_InvoiceEmail',
1640
        $subject = '',
1641
        $message = '',
1642
        $resend = false,
1643
        $adminOnlyOrToEmail = false
1644
    ) {
1645
        return $this->prepareAndSendEmail(
1646
            $emailClassName,
1647
            $subject,
1648
            $message,
1649
            $resend,
1650
            $adminOnlyOrToEmail
1651
        );
1652
    }
1653
1654
    /**
1655
     * Sends a message to the shop admin ONLY and not to the customer
1656
     * This can be used by ordersteps and orderlogs to notify the admin of any potential problems.
1657
     *
1658
     * @param string         $emailClassName       - (optional) template to be used ...
1659
     * @param string         $subject              - (optional) subject for the email
1660
     * @param string         $message              - (optional) message to be added with the email
1661
     * @param bool           $resend               - (optional) can it be sent twice?
1662
     * @param bool | string  $adminOnlyOrToEmail   - (optional) sends the email to the ADMIN ONLY, if you provide an email, it will go to the email...
1663
     *
1664
     * @return bool TRUE for success, FALSE for failure (not tested)
1665
     */
1666
    public function sendAdminNotification(
1667
        $emailClassName = 'Order_ErrorEmail',
1668
        $subject = '',
1669
        $message = '',
1670
        $resend = false,
1671
        $adminOnlyOrToEmail = true
1672
    ) {
1673
        return $this->prepareAndSendEmail(
1674
            $emailClassName,
1675
            $subject,
1676
            $message,
1677
            $resend,
1678
            $adminOnlyOrToEmail
1679
        );
1680
    }
1681
1682
    /**
1683
     * returns the order formatted as an email.
1684
     *
1685
     * @param string $emailClassName - template to use.
1686
     * @param string $subject        - (optional) the subject (which can be used as title in email)
1687
     * @param string $message        - (optional) the additional message
1688
     *
1689
     * @return string (html)
1690
     */
1691
    public function renderOrderInEmailFormat(
1692
        $emailClassName,
1693
        $subject = '',
1694
        $message = ''
1695
    )
1696
    {
1697
        $arrayData = $this->createReplacementArrayForEmail($subject, $message);
1698
        Config::nest();
1699
        Config::inst()->update('SSViewer', 'theme_enabled', true);
1700
        $html = $arrayData->renderWith($emailClassName);
1701
        Config::unnest();
1702
1703
        return Order_Email::emogrify_html($html);
1704
    }
1705
1706
    /**
1707
     * Send a mail of the order to the client (and another to the admin).
1708
     *
1709
     * @param string         $emailClassName       - (optional) template to be used ...
1710
     * @param string         $subject              - (optional) subject for the email
1711
     * @param string         $message              - (optional) message to be added with the email
1712
     * @param bool           $resend               - (optional) can it be sent twice?
1713
     * @param bool | string  $adminOnlyOrToEmail   - (optional) sends the email to the ADMIN ONLY, if you provide an email, it will go to the email...
1714
     *
1715
     * @return bool TRUE for success, FALSE for failure (not tested)
1716
     */
1717
    protected function prepareAndSendEmail(
1718
        $emailClassName,
1719
        $subject,
1720
        $message,
1721
        $resend = false,
1722
        $adminOnlyOrToEmail = false
1723
    ) {
1724
        $arrayData = $this->createReplacementArrayForEmail($subject, $message);
1725
        $from = Order_Email::get_from_email();
1726
        //why are we using this email and NOT the member.EMAIL?
1727
        //for historical reasons????
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1728
        if ($adminOnlyOrToEmail) {
1729
            if (filter_var($adminOnlyOrToEmail, FILTER_VALIDATE_EMAIL)) {
1730
                $to = $adminOnlyOrToEmail;
1731
                // invalid e-mail address
1732
            } else {
1733
                $to = Order_Email::get_from_email();
1734
            }
1735
        } else {
1736
            $to = $this->getOrderEmail();
1737
        }
1738
        if ($from && $to) {
1739
            $email = new $emailClassName();
1740
            if (!(is_a($email, Object::getCustomClass('Email')))) {
1741
                user_error('No correct email class provided.', E_USER_ERROR);
1742
            }
1743
            $email->setFrom($from);
1744
            $email->setTo($to);
1745
            //we take the subject from the Array Data, just in case it has been adjusted.
1746
            $email->setSubject($arrayData->getField('Subject'));
1747
            //we also see if a CC and a BCC have been added
1748
            ;
1749
            if ($cc = $arrayData->getField('CC')) {
1750
                $email->setCc($cc);
1751
            }
1752
            if ($bcc = $arrayData->getField('BCC')) {
1753
                $email->setBcc($bcc);
1754
            }
1755
            $email->populateTemplate($arrayData);
1756
            // This might be called from within the CMS,
1757
            // so we need to restore the theme, just in case
1758
            // templates within the theme exist
1759
            Config::nest();
1760
            Config::inst()->update('SSViewer', 'theme_enabled', true);
1761
            $email->setOrder($this);
1762
            $email->setResend($resend);
1763
            $result = $email->send(null);
1764
            Config::unnest();
1765
            if (Director::isDev()) {
1766
                return true;
1767
            } else {
1768
                return $result;
1769
            }
1770
        }
1771
1772
        return false;
1773
    }
1774
1775
    /**
1776
     * returns the Data that can be used in the body of an order Email
1777
     * we add the subject here so that the subject, for example, can be added to the <title>
1778
     * of the email template.
1779
     * we add the subject here so that the subject, for example, can be added to the <title>
1780
     * of the email template.
1781
     *
1782
     * @param string $subject  - (optional) subject for email
1783
     * @param string $message  - (optional) the additional message
1784
     *
1785
     * @return ArrayData
1786
     *                   - Subject - EmailSubject
1787
     *                   - Message - specific message for this order
1788
     *                   - Message - custom message
1789
     *                   - OrderStepMessage - generic message for step
1790
     *                   - Order
1791
     *                   - EmailLogo
1792
     *                   - ShopPhysicalAddress
1793
     *                   - CurrentDateAndTime
1794
     *                   - BaseURL
1795
     *                   - CC
1796
     *                   - BCC
1797
     */
1798
    protected function createReplacementArrayForEmail($subject = '', $message = '')
1799
    {
1800
        $step = $this->MyStep();
1801
        $config = $this->EcomConfig();
1802
        $replacementArray = array();
1803
        //set subject
1804
        if ( ! $subject) {
1805
            $subject = $step->EmailSubject;
1806
        }
1807
        if( ! $message) {
1808
            $message = $step->CustomerMessage;
1809
        }
1810
        $subject = str_replace('[OrderNumber]', $this->ID, $subject);
1811
        //set other variables
1812
        $replacementArray['Subject'] = $subject;
1813
        $replacementArray['To'] = '';
1814
        $replacementArray['CC'] = '';
1815
        $replacementArray['BCC'] = '';
1816
        $replacementArray['OrderStepMessage'] = $message;
1817
        $replacementArray['Order'] = $this;
1818
        $replacementArray['EmailLogo'] = $config->EmailLogo();
0 ignored issues
show
Documentation Bug introduced by
The method EmailLogo does not exist on object<EcommerceDBConfig>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1819
        $replacementArray['ShopPhysicalAddress'] = $config->ShopPhysicalAddress;
0 ignored issues
show
Documentation introduced by
The property ShopPhysicalAddress does not exist on object<EcommerceDBConfig>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1820
        $replacementArray['CurrentDateAndTime'] = DBField::create_field('SS_Datetime', 'Now');
1821
        $replacementArray['BaseURL'] = Director::baseURL();
1822
        $arrayData = ArrayData::create($replacementArray);
1823
        $this->extend('updateReplacementArrayForEmail', $arrayData);
1824
1825
        return $arrayData;
1826
    }
1827
1828
/*******************************************************
1829
   * 6. ITEM MANAGEMENT
1830
*******************************************************/
1831
1832
    /**
1833
     * returns a list of Order Attributes by type.
1834
     *
1835
     * @param array | String $types
1836
     *
1837
     * @return ArrayList
1838
     */
1839
    public function getOrderAttributesByType($types)
1840
    {
1841
        if (!is_array($types) && is_string($types)) {
1842
            $types = array($types);
1843
        }
1844
        if (!is_array($al)) {
0 ignored issues
show
Bug introduced by
The variable $al seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1845
            user_error('wrong parameter (types) provided in Order::getOrderAttributesByTypes');
1846
        }
1847
        $al = new ArrayList();
1848
        $items = $this->Items();
1849
        foreach ($items as $item) {
1850
            if (in_array($item->OrderAttributeType(), $types)) {
1851
                $al->push($item);
1852
            }
1853
        }
1854
        $modifiers = $this->Modifiers();
1855
        foreach ($modifiers as $modifier) {
1856
            if (in_array($modifier->OrderAttributeType(), $types)) {
1857
                $al->push($modifier);
1858
            }
1859
        }
1860
1861
        return $al;
1862
    }
1863
1864
    /**
1865
     * Returns the items of the order.
1866
     * Items are the order items (products) and NOT the modifiers (discount, tax, etc...).
1867
     *
1868
     * N. B. this method returns Order Items
1869
     * also see Buaybles
1870
1871
     *
1872
     * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier')
1873
     *
1874
     * @return DataList (OrderItems)
1875
     */
1876
    public function Items($filterOrClassName = '')
1877
    {
1878
        if (!$this->exists()) {
1879
            $this->write();
1880
        }
1881
1882
        return $this->itemsFromDatabase($filterOrClassName);
1883
    }
1884
1885
    /**
1886
     * @alias function of Items
1887
     *
1888
     * N. B. this method returns Order Items
1889
     * also see Buaybles
1890
     *
1891
     * @param string filter - where statement to exclude certain items.
1892
     * @alias for Items
1893
     * @return DataList (OrderItems)
1894
     */
1895
    public function OrderItems($filterOrClassName = '')
1896
    {
1897
        return $this->Items($filterOrClassName);
1898
    }
1899
1900
    /**
1901
     * returns the buyables asscoiated with the order items.
1902
     *
1903
     * NB. this method retursn buyables
1904
     *
1905
     * @param string filter - where statement to exclude certain items.
1906
     *
1907
     * @return ArrayList (Buyables)
1908
     */
1909
    public function Buyables($filterOrClassName = '')
1910
    {
1911
        $items = $this->Items($filterOrClassName);
1912
        $arrayList = new ArrayList();
1913
        foreach ($items as $item) {
1914
            $arrayList->push($item->Buyable());
1915
        }
1916
1917
        return $arrayList;
1918
    }
1919
1920
    /**
1921
     * Return all the {@link OrderItem} instances that are
1922
     * available as records in the database.
1923
     *
1924
     * @param string filter - where statement to exclude certain items,
1925
     *   you can also pass a classname (e.g. MyOrderItem), in which case only this class will be returned (and any class extending your given class)
1926
     *
1927
     * @return DataList (OrderItems)
1928
     */
1929
    protected function itemsFromDatabase($filterOrClassName = '')
1930
    {
1931
        $className = 'OrderItem';
1932
        $extrafilter = '';
1933
        if ($filterOrClassName) {
1934
            if (class_exists($filterOrClassName)) {
1935
                $className = $filterOrClassName;
1936
            } else {
1937
                $extrafilter = " AND $filterOrClassName";
1938
            }
1939
        }
1940
1941
        return $className::get()->filter(array('OrderID' => $this->ID))->where($extrafilter);
1942
    }
1943
1944
    /**
1945
     * @alias for Modifiers
1946
     *
1947
     * @return DataList (OrderModifiers)
1948
     */
1949
    public function OrderModifiers()
1950
    {
1951
        return $this->Modifiers();
1952
    }
1953
1954
    /**
1955
     * Returns the modifiers of the order, if it hasn't been saved yet
1956
     * it returns the modifiers from session, if it has, it returns them
1957
     * from the DB entry. ONLY USE OUTSIDE ORDER.
1958
     *
1959
     * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier')
1960
     *
1961
     * @return DataList (OrderModifiers)
1962
     */
1963
    public function Modifiers($filterOrClassName = '')
1964
    {
1965
        return $this->modifiersFromDatabase($filterOrClassName);
1966
    }
1967
1968
    /**
1969
     * Get all {@link OrderModifier} instances that are
1970
     * available as records in the database.
1971
     * NOTE: includes REMOVED Modifiers, so that they do not get added again...
1972
     *
1973
     * @param string filter - where statement to exclude certain items OR ClassName (e.g. 'TaxModifier')
1974
     *
1975
     * @return DataList (OrderModifiers)
1976
     */
1977
    protected function modifiersFromDatabase($filterOrClassName = '')
1978
    {
1979
        $className = 'OrderModifier';
1980
        $extrafilter = '';
1981
        if ($filterOrClassName) {
1982
            if (class_exists($filterOrClassName)) {
1983
                $className = $filterOrClassName;
1984
            } else {
1985
                $extrafilter = " AND $filterOrClassName";
1986
            }
1987
        }
1988
1989
        return $className::get()->where('"OrderAttribute"."OrderID" = '.$this->ID." $extrafilter");
1990
    }
1991
1992
    /**
1993
     * Calculates and updates all the order attributes.
1994
     *
1995
     * @param bool $recalculate - run it, even if it has run already
1996
     */
1997
    public function calculateOrderAttributes($recalculate = false)
1998
    {
1999
        if ($this->IsSubmitted()) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
2000
            //submitted orders are NEVER recalculated.
2001
            //they are set in stone.
2002
        } elseif (self::get_needs_recalculating($this->ID) || $recalculate) {
2003
            if ($this->StatusID || $this->TotalItems()) {
0 ignored issues
show
Documentation introduced by
The property StatusID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2004
                $this->ensureCorrectExchangeRate();
2005
                $this->calculateOrderItems($recalculate);
2006
                $this->calculateModifiers($recalculate);
2007
                $this->extend('onCalculateOrder');
2008
            }
2009
        }
2010
    }
2011
2012
    /**
2013
     * Calculates and updates all the product items.
2014
     *
2015
     * @param bool $recalculate - run it, even if it has run already
2016
     */
2017
    protected function calculateOrderItems($recalculate = false)
2018
    {
2019
        //check if order has modifiers already
2020
        //check /re-add all non-removable ones
2021
        //$start = microtime();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2022
        $orderItems = $this->itemsFromDatabase();
2023
        if ($orderItems->count()) {
2024
            foreach ($orderItems as $orderItem) {
2025
                if ($orderItem) {
2026
                    $orderItem->runUpdate($recalculate);
2027
                }
2028
            }
2029
        }
2030
        $this->extend('onCalculateOrderItems', $orderItems);
2031
    }
2032
2033
    /**
2034
     * Calculates and updates all the modifiers.
2035
     *
2036
     * @param bool $recalculate - run it, even if it has run already
2037
     */
2038
    protected function calculateModifiers($recalculate = false)
2039
    {
2040
        $createdModifiers = $this->modifiersFromDatabase();
2041
        if ($createdModifiers->count()) {
2042
            foreach ($createdModifiers as $modifier) {
2043
                if ($modifier) {
2044
                    $modifier->runUpdate($recalculate);
2045
                }
2046
            }
2047
        }
2048
        $this->extend('onCalculateModifiers', $createdModifiers);
2049
    }
2050
2051
    /**
2052
     * Returns the subtotal of the modifiers for this order.
2053
     * If a modifier appears in the excludedModifiers array, it is not counted.
2054
     *
2055
     * @param string|array $excluded               - Class(es) of modifier(s) to ignore in the calculation.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $excluded not be string|array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2056
     * @param bool         $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier.
2057
     *
2058
     * @return float
0 ignored issues
show
Documentation introduced by
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2059
     */
2060
    public function ModifiersSubTotal($excluded = null, $stopAtExcludedModifier = false)
2061
    {
2062
        $total = 0;
2063
        $modifiers = $this->Modifiers();
2064
        if ($modifiers->count()) {
2065
            foreach ($modifiers as $modifier) {
2066
                if (!$modifier->IsRemoved()) { //we just double-check this...
2067
                    if (is_array($excluded) && in_array($modifier->ClassName, $excluded)) {
2068
                        if ($stopAtExcludedModifier) {
2069
                            break;
2070
                        }
2071
                        //do the next modifier
2072
                        continue;
2073
                    } elseif (is_string($excluded) && ($modifier->ClassName == $excluded)) {
2074
                        if ($stopAtExcludedModifier) {
2075
                            break;
2076
                        }
2077
                        //do the next modifier
2078
                        continue;
2079
                    }
2080
                    $total += $modifier->CalculationTotal();
2081
                }
2082
            }
2083
        }
2084
2085
        return $total;
2086
    }
2087
2088
    /**
2089
     * returns a modifier that is an instanceof the classname
2090
     * it extends.
2091
     *
2092
     * @param string $className: class name for the modifier
0 ignored issues
show
Documentation introduced by
There is no parameter named $className:. Did you maybe mean $className?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
2093
     *
2094
     * @return DataObject (OrderModifier)
2095
     **/
2096
    public function RetrieveModifier($className)
2097
    {
2098
        $modifiers = $this->Modifiers();
2099
        if ($modifiers->count()) {
2100
            foreach ($modifiers as $modifier) {
2101
                if (is_a($modifier, Object::getCustomClass($className))) {
2102
                    return $modifier;
2103
                }
2104
            }
2105
        }
2106
    }
2107
2108
/*******************************************************
2109
   * 7. CRUD METHODS (e.g. canView, canEdit, canDelete, etc...)
2110
*******************************************************/
2111
2112
    /**
2113
     * @param Member $member
2114
     *
2115
     * @return DataObject (Member)
2116
     **/
2117
     //TODO: please comment why we make use of this function
2118
    protected function getMemberForCanFunctions(Member $member = null)
2119
    {
2120
        if (!$member) {
2121
            $member = Member::currentUser();
2122
        }
2123
        if (!$member) {
2124
            $member = new Member();
2125
            $member->ID = 0;
2126
        }
2127
2128
        return $member;
2129
    }
2130
2131
    /**
2132
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2133
     *
2134
     * @return bool
2135
     **/
2136
    public function canCreate($member = null)
2137
    {
2138
        $member = $this->getMemberForCanFunctions($member);
2139
        $extended = $this->extendedCan(__FUNCTION__, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>, but the function expects a object<Member>|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2140
        if ($extended !== null) {
2141
            return $extended;
2142
        }
2143
        if ($member->exists()) {
2144
            return $member->IsShopAdmin();
2145
        }
2146
    }
2147
2148
    /**
2149
     * Standard SS method - can the current member view this order?
2150
     *
2151
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2152
     *
2153
     * @return bool
2154
     **/
2155
    public function canView($member = null)
2156
    {
2157
        if (!$this->exists()) {
2158
            return true;
2159
        }
2160
        $member = $this->getMemberForCanFunctions($member);
2161
        //check if this has been "altered" in any DataExtension
2162
        $extended = $this->extendedCan(__FUNCTION__, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>, but the function expects a object<Member>|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2163
        if ($extended !== null) {
2164
            return $extended;
2165
        }
2166
        //is the member is a shop admin they can always view it
2167
        if (EcommerceRole::current_member_is_shop_admin($member)) {
2168
            return true;
2169
        }
2170
2171
        //is the member is a shop assistant they can always view it
2172
        if (EcommerceRole::current_member_is_shop_assistant($member)) {
2173
            return true;
2174
        }
2175
        //if the current member OWNS the order, (s)he can always view it.
2176
        if ($member->exists() && $this->MemberID == $member->ID) {
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2177
            return true;
2178
        }
2179
        //it is the current order
2180
        if ($this->IsInSession()) {
2181
            //we do some additional CHECKS for session hackings!
2182
            if ($member->exists() && $this->MemberID) {
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2183
                //can't view the order of another member!
2184
                //shop admin exemption is already captured.
2185
                //this is always true
2186
                if ($this->MemberID != $member->ID) {
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2187
                    return false;
2188
                }
2189
            } else {
2190
                //order belongs to someone, but current user is NOT logged in...
2191
                //this is allowed!
2192
                //the reason it is allowed is because we want to be able to
2193
                //add order to non-existing member
2194
                return true;
2195
            }
2196
        }
2197
2198
        return false;
2199
    }
2200
2201
    /**
2202
     * @param Member $member optional
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2203
     * @return bool
2204
     */
2205
    public function canOverrideCanView($member = null)
2206
    {
2207
        if ($this->canView($member)) {
2208
            //can view overrides any concerns
2209
            return true;
2210
        } else {
2211
            $tsOrder = strtotime($this->LastEdited);
2212
            $tsNow = time();
2213
            $minutes = EcommerceConfig::get('Order', 'minutes_an_order_can_be_viewed_without_logging_in');
2214
            if ($minutes && ((($tsNow - $tsOrder) / 60) < $minutes)) {
2215
2216
                //has the order been edited recently?
2217
                return true;
2218
            } elseif ($orderStep = $this->MyStep()) {
2219
2220
                // order is being processed ...
2221
                return $orderStep->canOverrideCanViewForOrder($this, $member);
0 ignored issues
show
Bug introduced by
The method canOverrideCanViewForOrder() does not exist on DataObject. Did you maybe mean canView()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
2222
            }
2223
        }
2224
        return false;
2225
    }
2226
2227
    /**
2228
     * @return bool
2229
     */
2230
    public function IsInSession()
2231
    {
2232
        $orderInSession = ShoppingCart::session_order();
2233
2234
        return $orderInSession && $this->ID && $this->ID == $orderInSession->ID;
2235
    }
2236
2237
    /**
2238
     * returns a pseudo random part of the session id.
2239
     *
2240
     * @param int $size
2241
     *
2242
     * @return string
2243
     */
2244
    public function LessSecureSessionID($size = 7, $start = null)
2245
    {
2246
        if (!$start || $start < 0 || $start > (32 - $size)) {
2247
            $start = 0;
2248
        }
2249
2250
        return substr($this->SessionID, $start, $size);
0 ignored issues
show
Documentation introduced by
The property SessionID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2251
    }
2252
    /**
2253
     *
2254
     * @param Member (optional) $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be optional|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2255
     *
2256
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2257
     **/
2258
    public function canViewAdminStuff($member = null)
2259
    {
2260
        $member = $this->getMemberForCanFunctions($member);
2261
        $extended = $this->extendedCan(__FUNCTION__, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>, but the function expects a object<Member>|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2262
        if ($extended !== null) {
2263
            return $extended;
2264
        }
2265
        if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) {
2266
            return true;
2267
        }
2268
    }
2269
2270
    /**
2271
     * if we set canEdit to false then we
2272
     * can not see the child records
2273
     * Basically, you can edit when you can view and canEdit (even as a customer)
2274
     * Or if you are a Shop Admin you can always edit.
2275
     * Otherwise it is false...
2276
     *
2277
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2278
     *
2279
     * @return bool
2280
     **/
2281
    public function canEdit($member = null)
2282
    {
2283
        $member = $this->getMemberForCanFunctions($member);
2284
        $extended = $this->extendedCan(__FUNCTION__, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>, but the function expects a object<Member>|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2285
        if ($extended !== null) {
2286
            return $extended;
2287
        }
2288
        if ($this->canView($member) && $this->MyStep()->CustomerCanEdit) {
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>, but the function expects a object<Member>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2289
            return true;
2290
        }
2291
        if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) {
2292
            return true;
2293
        }
2294
        //is the member is a shop assistant they can always view it
2295
        if (EcommerceRole::current_member_is_shop_assistant($member)) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return \EcommerceRole::c...hop_assistant($member);.
Loading history...
2296
            return true;
2297
        }
2298
        return false;
2299
    }
2300
2301
    /**
2302
     * is the order ready to go through to the
2303
     * checkout process.
2304
     *
2305
     * This method checks all the order items and order modifiers
2306
     * If any of them need immediate attention then this is done
2307
     * first after which it will go through to the checkout page.
2308
     *
2309
     * @param Member (optional) $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be null|Member?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2310
     *
2311
     * @return bool
2312
     **/
2313
    public function canCheckout(Member $member = null)
2314
    {
2315
        $member = $this->getMemberForCanFunctions($member);
2316
        $extended = $this->extendedCan(__FUNCTION__, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>, but the function expects a object<Member>|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2317
        if ($extended !== null) {
2318
            return $extended;
2319
        }
2320
        $submitErrors = $this->SubmitErrors();
2321
        if ($submitErrors && $submitErrors->count()) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return !($submitErrors &...submitErrors->count());.
Loading history...
2322
            return false;
2323
        }
2324
2325
        return true;
2326
    }
2327
2328
    /**
2329
     * Can the order be submitted?
2330
     * this method can be used to stop an order from being submitted
2331
     * due to something not being completed or done.
2332
     *
2333
     * @see Order::SubmitErrors
2334
     *
2335
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be null|Member?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2336
     *
2337
     * @return bool
2338
     **/
2339
    public function canSubmit(Member $member = null)
2340
    {
2341
        $member = $this->getMemberForCanFunctions($member);
2342
        $extended = $this->extendedCan(__FUNCTION__, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>, but the function expects a object<Member>|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2343
        if ($extended !== null) {
2344
            return $extended;
2345
        }
2346
        if ($this->IsSubmitted()) {
2347
            return false;
2348
        }
2349
        $submitErrors = $this->SubmitErrors();
2350
        if ($submitErrors && $submitErrors->count()) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return !($submitErrors &...submitErrors->count());.
Loading history...
2351
            return false;
2352
        }
2353
2354
        return true;
2355
    }
2356
2357
    /**
2358
     * Can a payment be made for this Order?
2359
     *
2360
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be null|Member?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2361
     *
2362
     * @return bool
2363
     **/
2364
    public function canPay(Member $member = null)
2365
    {
2366
        $member = $this->getMemberForCanFunctions($member);
2367
        $extended = $this->extendedCan(__FUNCTION__, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>, but the function expects a object<Member>|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2368
        if ($extended !== null) {
2369
            return $extended;
2370
        }
2371
        if ($this->IsPaid() || $this->IsCancelled() || $this->PaymentIsPending()) {
2372
            return false;
2373
        }
2374
2375
        return $this->MyStep()->CustomerCanPay;
2376
    }
2377
2378
    /**
2379
     * Can the given member cancel this order?
2380
     *
2381
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be null|Member?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2382
     *
2383
     * @return bool
2384
     **/
2385
    public function canCancel(Member $member = null)
2386
    {
2387
        //if it is already cancelled it can not be cancelled again
2388
        if ($this->CancelledByID) {
0 ignored issues
show
Documentation introduced by
The property CancelledByID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2389
            return false;
2390
        }
2391
        $member = $this->getMemberForCanFunctions($member);
2392
        $extended = $this->extendedCan(__FUNCTION__, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>, but the function expects a object<Member>|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2393
        if ($extended !== null) {
2394
            return $extended;
2395
        }
2396
        if (EcommerceRole::current_member_can_process_orders($member)) {
2397
            return true;
2398
        }
2399
2400
        return $this->MyStep()->CustomerCanCancel && $this->canView($member);
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>, but the function expects a object<Member>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2401
    }
2402
2403
    /**
2404
     * @param Member $member
0 ignored issues
show
Documentation introduced by
Should the type for parameter $member not be Member|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2405
     *
2406
     * @return bool
2407
     **/
2408
    public function canDelete($member = null)
2409
    {
2410
        $member = $this->getMemberForCanFunctions($member);
2411
        $extended = $this->extendedCan(__FUNCTION__, $member);
0 ignored issues
show
Documentation introduced by
$member is of type object<DataObject>, but the function expects a object<Member>|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
2412
        if ($extended !== null) {
2413
            return $extended;
2414
        }
2415
        if ($this->IsSubmitted()) {
2416
            return false;
2417
        }
2418
        if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return (bool) \Permissio...min_permission_code'));.
Loading history...
2419
            return true;
2420
        }
2421
2422
        return false;
2423
    }
2424
2425
    /**
2426
     * Returns all the order logs that the current member can view
2427
     * i.e. some order logs can only be viewed by the admin (e.g. suspected fraud orderlog).
2428
     *
2429
     * @return ArrayList (OrderStatusLogs)
2430
     **/
2431
    public function CanViewOrderStatusLogs()
2432
    {
2433
        $canViewOrderStatusLogs = new ArrayList();
2434
        $logs = $this->OrderStatusLogs();
0 ignored issues
show
Bug introduced by
The method OrderStatusLogs() does not exist on Order. Did you maybe mean getOrderStatusLogsTableField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
2435
        foreach ($logs as $log) {
2436
            if ($log->canView()) {
2437
                $canViewOrderStatusLogs->push($log);
2438
            }
2439
        }
2440
2441
        return $canViewOrderStatusLogs;
2442
    }
2443
2444
    /**
2445
     * returns all the logs that can be viewed by the customer.
2446
     *
2447
     * @return ArrayList (OrderStausLogs)
2448
     */
2449
    public function CustomerViewableOrderStatusLogs()
2450
    {
2451
        $customerViewableOrderStatusLogs = new ArrayList();
2452
        $logs = $this->OrderStatusLogs();
0 ignored issues
show
Bug introduced by
The method OrderStatusLogs() does not exist on Order. Did you maybe mean getOrderStatusLogsTableField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
2453
        if ($logs) {
2454
            foreach ($logs as $log) {
2455
                if (!$log->InternalUseOnly) {
2456
                    $customerViewableOrderStatusLogs->push($log);
2457
                }
2458
            }
2459
        }
2460
2461
        return $customerViewableOrderStatusLogs;
2462
    }
2463
2464
/*******************************************************
2465
   * 8. GET METHODS (e.g. Total, SubTotal, Title, etc...)
2466
*******************************************************/
2467
2468
    /**
2469
     * returns the email to be used for customer communication.
2470
     *
2471
     * @return string
2472
     */
2473
    public function OrderEmail()
2474
    {
2475
        return $this->getOrderEmail();
2476
    }
2477
    public function getOrderEmail()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
2478
    {
2479
        $email = '';
2480
        if ($this->BillingAddressID && $this->BillingAddress()) {
0 ignored issues
show
Documentation introduced by
The property BillingAddressID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method BillingAddress() does not exist on Order. Did you maybe mean getBillingAddressField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
2481
            $email = $this->BillingAddress()->Email;
0 ignored issues
show
Bug introduced by
The method BillingAddress() does not exist on Order. Did you maybe mean getBillingAddressField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
2482
        }
2483
        if (! $email) {
2484
            if ($this->MemberID && $this->Member()) {
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method Member() does not exist on Order. Did you maybe mean CreateOrReturnExistingMember()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
2485
                $email = $this->Member()->Email;
0 ignored issues
show
Bug introduced by
The method Member() does not exist on Order. Did you maybe mean CreateOrReturnExistingMember()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
2486
            }
2487
        }
2488
        $extendedEmail = $this->extend('updateOrderEmail', $email);
2489
        if ($extendedEmail !== null && is_array($extendedEmail) && count($extendedEmail)) {
2490
            $email = implode(';', $extendedEmail);
2491
        }
2492
2493
        return $email;
2494
    }
2495
2496
    /**
2497
     * Returns true if there is a prink or email link.
2498
     *
2499
     * @return bool
2500
     */
2501
    public function HasPrintOrEmailLink()
2502
    {
2503
        return $this->EmailLink() || $this->PrintLink();
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->PrintLink() of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
2504
    }
2505
2506
    /**
2507
     * returns the absolute link to the order that can be used in the customer communication (email).
2508
     *
2509
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be false|string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2510
     */
2511
    public function EmailLink($type = 'Order_StatusEmail')
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2512
    {
2513
        return $this->getEmailLink();
2514
    }
2515
    public function getEmailLink($type = 'Order_StatusEmail')
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
getEmailLink uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
2516
    {
2517
        if (!isset($_REQUEST['print'])) {
2518
            if ($this->IsSubmitted()) {
2519
                return Director::AbsoluteURL(OrderConfirmationPage::get_email_link($this->ID, $this->MyStep()->getEmailClassName(), $actuallySendEmail = true));
2520
            }
2521
        }
2522
    }
2523
2524
    /**
2525
     * returns the absolute link to the order for printing.
2526
     *
2527
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2528
     */
2529
    public function PrintLink()
2530
    {
2531
        return $this->getPrintLink();
2532
    }
2533
    public function getPrintLink()
0 ignored issues
show
Coding Style introduced by
getPrintLink uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
2534
    {
2535
        if (!isset($_REQUEST['print'])) {
2536
            if ($this->IsSubmitted()) {
2537
                return Director::AbsoluteURL(OrderConfirmationPage::get_order_link($this->ID)).'?print=1';
2538
            }
2539
        }
2540
    }
2541
2542
    /**
2543
     * returns the absolute link to the order for printing.
2544
     *
2545
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2546
     */
2547
    public function PackingSlipLink()
2548
    {
2549
        return $this->getPackingSlipLink();
2550
    }
2551
    public function getPackingSlipLink()
2552
    {
2553
        if ($this->IsSubmitted()) {
2554
            return Director::AbsoluteURL(OrderConfirmationPage::get_order_link($this->ID)).'?packingslip=1';
2555
        }
2556
    }
2557
2558
    /**
2559
     * returns the absolute link that the customer can use to retrieve the email WITHOUT logging in.
2560
     *
2561
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|false?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2562
     */
2563
    public function RetrieveLink()
2564
    {
2565
        return $this->getRetrieveLink();
2566
    }
2567
2568
    public function getRetrieveLink()
2569
    {
2570
        //important to recalculate!
2571
        if ($this->IsSubmitted($recalculate = true)) {
2572
            //add session ID if not added yet...
2573
            if (!$this->SessionID) {
0 ignored issues
show
Documentation introduced by
The property SessionID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2574
                $this->write();
2575
            }
2576
2577
            return Director::AbsoluteURL(OrderConfirmationPage::find_link()).'retrieveorder/'.$this->SessionID.'/'.$this->ID.'/';
0 ignored issues
show
Documentation introduced by
The property SessionID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2578
        } else {
2579
            return Director::AbsoluteURL('/shoppingcart/loadorder/'.$this->ID.'/');
2580
        }
2581
    }
2582
2583
    public function ShareLink()
2584
    {
2585
        return $this->getShareLink();
2586
    }
2587
2588
    public function getShareLink()
2589
    {
2590
        $orderItems = $this->itemsFromDatabase();
2591
        $action = 'share';
2592
        $array = array();
2593
        foreach ($orderItems as $orderItem) {
2594
            $array[] = implode(
2595
                ',',
2596
                array(
2597
                    $orderItem->BuyableClassName,
2598
                    $orderItem->BuyableID,
2599
                    $orderItem->Quantity
2600
                )
2601
            );
2602
        }
2603
2604
        return Director::AbsoluteURL(CartPage::find_link($action.'/'.implode('-', $array)));
2605
    }
2606
2607
    /**
2608
     * link to delete order.
2609
     *
2610
     * @return string
2611
     */
2612
    public function DeleteLink()
2613
    {
2614
        return $this->getDeleteLink();
2615
    }
2616
    public function getDeleteLink()
2617
    {
2618
        if ($this->canDelete()) {
2619
            return ShoppingCart_Controller::delete_order_link($this->ID);
2620
        } else {
2621
            return '';
2622
        }
2623
    }
2624
2625
    /**
2626
     * link to copy order.
2627
     *
2628
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2629
     */
2630
    public function CopyOrderLink()
2631
    {
2632
        return $this->getCopyOrderLink();
2633
    }
2634
    public function getCopyOrderLink()
2635
    {
2636
        if ($this->canView() && $this->IsSubmitted()) {
2637
            return ShoppingCart_Controller::copy_order_link($this->ID);
2638
        } else {
2639
            return '';
2640
        }
2641
    }
2642
2643
    /**
2644
     * A "Title" for the order, which summarises the main details (date, and customer) in a string.
2645
     *
2646
     * @param string $dateFormat  - e.g. "D j M Y, G:i T"
0 ignored issues
show
Documentation introduced by
Should the type for parameter $dateFormat not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2647
     * @param bool   $includeName - e.g. by Mr Johnson
2648
     *
2649
     * @return string
2650
     **/
2651
    public function Title($dateFormat = null, $includeName = false)
2652
    {
2653
        return $this->getTitle($dateFormat, $includeName);
2654
    }
2655
    public function getTitle($dateFormat = null, $includeName = false)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
2656
    {
2657
        if ($this->exists()) {
2658
            if ($dateFormat === null) {
2659
                $dateFormat = EcommerceConfig::get('Order', 'date_format_for_title');
2660
            }
2661
            if ($includeName === null) {
2662
                $includeName = EcommerceConfig::get('Order', 'include_customer_name_in_title');
2663
            }
2664
            $title = $this->i18n_singular_name()." #".number_format($this->ID);
2665
            if ($dateFormat) {
2666
                if ($submissionLog = $this->SubmissionLog()) {
2667
                    $dateObject = $submissionLog->dbObject('Created');
2668
                    $placed = _t('Order.PLACED', 'placed');
2669
                } else {
2670
                    $dateObject = $this->dbObject('Created');
2671
                    $placed = _t('Order.STARTED', 'started');
2672
                }
2673
                $title .= ' - '.$placed.' '.$dateObject->Format($dateFormat);
2674
            }
2675
            $name = '';
2676
            if ($this->CancelledByID) {
0 ignored issues
show
Documentation introduced by
The property CancelledByID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2677
                $name = ' - '._t('Order.CANCELLED', 'CANCELLED');
2678
            }
2679
            if ($includeName) {
2680
                $by = _t('Order.BY', 'by');
2681
                if (!$name) {
2682
                    if ($this->BillingAddressID) {
0 ignored issues
show
Documentation introduced by
The property BillingAddressID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2683
                        if ($billingAddress = $this->BillingAddress()) {
0 ignored issues
show
Bug introduced by
The method BillingAddress() does not exist on Order. Did you maybe mean getBillingAddressField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
2684
                            $name = ' - '.$by.' '.$billingAddress->Prefix.' '.$billingAddress->FirstName.' '.$billingAddress->Surname;
2685
                        }
2686
                    }
2687
                }
2688
                if (!$name) {
2689
                    if ($this->MemberID) {
0 ignored issues
show
Documentation introduced by
The property MemberID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2690
                        if ($member = $this->Member()) {
0 ignored issues
show
Bug introduced by
The method Member() does not exist on Order. Did you maybe mean CreateOrReturnExistingMember()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
2691
                            if ($member->exists()) {
2692
                                if ($memberName = $member->getName()) {
2693
                                    if (!trim($memberName)) {
2694
                                        $memberName = _t('Order.ANONYMOUS', 'anonymous');
2695
                                    }
2696
                                    $name = ' - '.$by.' '.$memberName;
2697
                                }
2698
                            }
2699
                        }
2700
                    }
2701
                }
2702
            }
2703
            $title .= $name;
2704
        } else {
2705
            $title = _t('Order.NEW', 'New').' '.$this->i18n_singular_name();
2706
        }
2707
        $extendedTitle = $this->extend('updateTitle', $title);
2708
        if ($extendedTitle !== null && is_array($extendedTitle) && count($extendedTitle)) {
2709
            $title = implode('; ', $extendedTitle);
2710
        }
2711
2712
        return $title;
2713
    }
2714
2715
    /**
2716
     * Returns the subtotal of the items for this order.
2717
     *
2718
     * @return float
0 ignored issues
show
Documentation introduced by
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2719
     */
2720
    public function SubTotal()
2721
    {
2722
        return $this->getSubTotal();
2723
    }
2724
    public function getSubTotal()
2725
    {
2726
        $result = 0;
2727
        $items = $this->Items();
2728
        if ($items->count()) {
2729
            foreach ($items as $item) {
2730
                if (is_a($item, Object::getCustomClass('OrderAttribute'))) {
2731
                    $result += $item->Total();
2732
                }
2733
            }
2734
        }
2735
2736
        return $result;
2737
    }
2738
2739
    /**
2740
     * @return Currency (DB Object)
2741
     **/
2742
    public function SubTotalAsCurrencyObject()
2743
    {
2744
        return DBField::create_field('Currency', $this->SubTotal());
2745
    }
2746
2747
    /**
2748
     * @return Money
2749
     **/
2750
    public function SubTotalAsMoney()
2751
    {
2752
        return $this->getSubTotalAsMoney();
2753
    }
2754
    public function getSubTotalAsMoney()
2755
    {
2756
        return EcommerceCurrency::get_money_object_from_order_currency($this->SubTotal(), $this);
2757
    }
2758
2759
    /**
2760
     * @param string|array $excluded               - Class(es) of modifier(s) to ignore in the calculation.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $excluded not be string|array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2761
     * @param bool         $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier.
2762
     *
2763
     * @return Currency (DB Object)
2764
     **/
2765
    public function ModifiersSubTotalAsCurrencyObject($excluded = null, $stopAtExcludedModifier = false)
2766
    {
2767
        return DBField::create_field('Currency', $this->ModifiersSubTotal($excluded, $stopAtExcludedModifier));
2768
    }
2769
2770
    /**
2771
     * @param string|array $excluded               - Class(es) of modifier(s) to ignore in the calculation.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $excluded not be string|array|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
2772
     * @param bool         $stopAtExcludedModifier - when this flag is TRUE, we stop adding the modifiers when we reach an excluded modifier.
2773
     *
2774
     * @return Money (DB Object)
2775
     **/
2776
    public function ModifiersSubTotalAsMoneyObject($excluded = null, $stopAtExcludedModifier = false)
2777
    {
2778
        return EcommerceCurrency::get_money_object_from_order_currency($this->ModifiersSubTotal($excluded, $stopAtExcludedModifier), $this);
2779
    }
2780
2781
    /**
2782
     * Returns the total cost of an order including the additional charges or deductions of its modifiers.
2783
     *
2784
     * @return float
0 ignored issues
show
Documentation introduced by
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2785
     */
2786
    public function Total()
2787
    {
2788
        return $this->getTotal();
2789
    }
2790
    public function getTotal()
2791
    {
2792
        return $this->SubTotal() + $this->ModifiersSubTotal();
2793
    }
2794
2795
    /**
2796
     * @return Currency (DB Object)
2797
     **/
2798
    public function TotalAsCurrencyObject()
2799
    {
2800
        return DBField::create_field('Currency', $this->Total());
2801
    }
2802
2803
    /**
2804
     * @return Money
2805
     **/
2806
    public function TotalAsMoney()
2807
    {
2808
        return $this->getTotalAsMoney();
2809
    }
2810
    public function getTotalAsMoney()
2811
    {
2812
        return EcommerceCurrency::get_money_object_from_order_currency($this->Total(), $this);
2813
    }
2814
2815
    /**
2816
     * Checks to see if any payments have been made on this order
2817
     * and if so, subracts the payment amount from the order.
2818
     *
2819
     * @return float
0 ignored issues
show
Documentation introduced by
Should the return type not be double|integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2820
     **/
2821
    public function TotalOutstanding()
2822
    {
2823
        return $this->getTotalOutstanding();
2824
    }
2825
    public function getTotalOutstanding()
2826
    {
2827
        if ($this->IsSubmitted()) {
2828
            $total = $this->Total();
2829
            $paid = $this->TotalPaid();
2830
            $outstanding = $total - $paid;
2831
            $maxDifference = EcommerceConfig::get('Order', 'maximum_ignorable_sales_payments_difference');
2832
            if (abs($outstanding) < $maxDifference) {
2833
                $outstanding = 0;
2834
            }
2835
2836
            return floatval($outstanding);
2837
        } else {
2838
            return 0;
2839
        }
2840
    }
2841
2842
    /**
2843
     * @return Currency (DB Object)
2844
     **/
2845
    public function TotalOutstandingAsCurrencyObject()
2846
    {
2847
        return DBField::create_field('Currency', $this->TotalOutstanding());
2848
    }
2849
2850
    /**
2851
     * @return Money
2852
     **/
2853
    public function TotalOutstandingAsMoney()
2854
    {
2855
        return $this->getTotalOutstandingAsMoney();
2856
    }
2857
    public function getTotalOutstandingAsMoney()
2858
    {
2859
        return EcommerceCurrency::get_money_object_from_order_currency($this->TotalOutstanding(), $this);
2860
    }
2861
2862
    /**
2863
     * @return float
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|double?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2864
     */
2865
    public function TotalPaid()
2866
    {
2867
        return $this->getTotalPaid();
2868
    }
2869
    public function getTotalPaid()
2870
    {
2871
        $paid = 0;
2872
        if ($payments = $this->Payments()) {
0 ignored issues
show
Bug introduced by
The method Payments() does not exist on Order. Did you maybe mean getPaymentsField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
2873
            foreach ($payments as $payment) {
2874
                if ($payment->Status == 'Success') {
2875
                    $paid += $payment->Amount->getAmount();
2876
                }
2877
            }
2878
        }
2879
        $reverseExchange = 1;
2880
        if ($this->ExchangeRate && $this->ExchangeRate != 1) {
0 ignored issues
show
Documentation introduced by
The property ExchangeRate does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2881
            $reverseExchange = 1 / $this->ExchangeRate;
0 ignored issues
show
Documentation introduced by
The property ExchangeRate does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2882
        }
2883
2884
        return $paid * $reverseExchange;
2885
    }
2886
2887
    /**
2888
     * @return Currency (DB Object)
2889
     **/
2890
    public function TotalPaidAsCurrencyObject()
2891
    {
2892
        return DBField::create_field('Currency', $this->TotalPaid());
2893
    }
2894
2895
    /**
2896
     * @return Money
2897
     **/
2898
    public function TotalPaidAsMoney()
2899
    {
2900
        return $this->getTotalPaidAsMoney();
2901
    }
2902
    public function getTotalPaidAsMoney()
2903
    {
2904
        return EcommerceCurrency::get_money_object_from_order_currency($this->TotalPaid(), $this);
2905
    }
2906
2907
    /**
2908
     * returns the total number of OrderItems (not modifiers).
2909
     * This is meant to run as fast as possible to quickly check
2910
     * if there is anything in the cart.
2911
     *
2912
     * @param bool $recalculate - do we need to recalculate (value is retained during lifetime of Object)
2913
     *
2914
     * @return int
2915
     **/
2916
    public function TotalItems($recalculate = false)
2917
    {
2918
        return $this->getTotalItems($recalculate);
2919
    }
2920
    public function getTotalItems($recalculate = false)
2921
    {
2922
        if ($this->totalItems === null || $recalculate) {
2923
            $this->totalItems = OrderItem::get()
2924
                ->where('"OrderAttribute"."OrderID" = '.$this->ID.' AND "OrderItem"."Quantity" > 0')
2925
                ->count();
2926
        }
2927
2928
        return $this->totalItems;
2929
    }
2930
2931
    /**
2932
     * Little shorthand.
2933
     *
2934
     * @param bool $recalculate
2935
     *
2936
     * @return bool
2937
     **/
2938
    public function MoreThanOneItemInCart($recalculate = false)
2939
    {
2940
        return $this->TotalItems($recalculate) > 1 ? true : false;
2941
    }
2942
2943
    /**
2944
     * returns the total number of OrderItems (not modifiers) times their respectective quantities.
2945
     *
2946
     * @param bool $recalculate - force recalculation
2947
     *
2948
     * @return float
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|double?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2949
     **/
2950
    public function TotalItemsTimesQuantity($recalculate = false)
2951
    {
2952
        return $this->getTotalItemsTimesQuantity($recalculate);
2953
    }
2954
    public function getTotalItemsTimesQuantity($recalculate = false)
2955
    {
2956
        if ($this->totalItemsTimesQuantity === null || $recalculate) {
2957
            //to do, why do we check if you can edit ????
2958
            $this->totalItemsTimesQuantity = DB::query('
0 ignored issues
show
Documentation Bug introduced by
The property $totalItemsTimesQuantity was declared of type double, but \DB::query(' ...uantity" > 0')->value() is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
2959
                SELECT SUM("OrderItem"."Quantity")
2960
                FROM "OrderItem"
2961
                    INNER JOIN "OrderAttribute" ON "OrderAttribute"."ID" = "OrderItem"."ID"
2962
                WHERE
2963
                    "OrderAttribute"."OrderID" = '.$this->ID.'
2964
                    AND "OrderItem"."Quantity" > 0'
2965
            )->value();
2966
        }
2967
2968
        return $this->totalItemsTimesQuantity - 0;
2969
    }
2970
2971
    /**
2972
     *
2973
     * @return string (country code)
2974
     **/
2975
    public function Country()
2976
    {
2977
        return $this->getCountry();
2978
    }
2979
2980
    /**
2981
    * Returns the country code for the country that applies to the order.
2982
    * @alias  for getCountry
2983
    *
2984
    * @return string - country code e.g. NZ
2985
     */
2986
    public function getCountry()
2987
    {
2988
        $countryCodes = array(
2989
            'Billing' => '',
2990
            'Shipping' => '',
2991
        );
2992
        $code = null;
0 ignored issues
show
Unused Code introduced by
$code is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2993
        if ($this->BillingAddressID) {
0 ignored issues
show
Documentation introduced by
The property BillingAddressID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2994
            $billingAddress = BillingAddress::get()->byID($this->BillingAddressID);
0 ignored issues
show
Documentation introduced by
The property BillingAddressID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
2995
            if ($billingAddress) {
2996
                if ($billingAddress->Country) {
2997
                    $countryCodes['Billing'] = $billingAddress->Country;
2998
                }
2999
            }
3000
        }
3001
        if ($this->ShippingAddressID && $this->UseShippingAddress) {
0 ignored issues
show
Documentation introduced by
The property ShippingAddressID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property UseShippingAddress does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3002
            $shippingAddress = ShippingAddress::get()->byID($this->ShippingAddressID);
0 ignored issues
show
Documentation introduced by
The property ShippingAddressID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3003
            if ($shippingAddress) {
3004
                if ($shippingAddress->ShippingCountry) {
3005
                    $countryCodes['Shipping'] = $shippingAddress->ShippingCountry;
3006
                }
3007
            }
3008
        }
3009
        if (
3010
            (EcommerceConfig::get('OrderAddress', 'use_shipping_address_for_main_region_and_country') && $countryCodes['Shipping'])
3011
            ||
3012
            (!$countryCodes['Billing'] && $countryCodes['Shipping'])
3013
        ) {
3014
            $code = $countryCodes['Shipping'];
3015
        } elseif ($countryCodes['Billing']) {
3016
            $code = $countryCodes['Billing'];
3017
        } else {
3018
            $code = EcommerceCountry::get_country_from_ip();
3019
        }
3020
3021
        return $code;
3022
    }
3023
3024
    /**
3025
     * @alias for getFullNameCountry
3026
     *
3027
     * @return string - country name
3028
     **/
3029
    public function FullNameCountry()
3030
    {
3031
        return $this->getFullNameCountry();
3032
    }
3033
3034
    /**
3035
     * returns name of coutry.
3036
     *
3037
     * @return string - country name
3038
     **/
3039
    public function getFullNameCountry()
3040
    {
3041
        return EcommerceCountry::find_title($this->Country());
3042
    }
3043
3044
    /**
3045
     * @alis for getExpectedCountryName
3046
     * @return string - country name
3047
     **/
3048
    public function ExpectedCountryName()
3049
    {
3050
        return $this->getExpectedCountryName();
3051
    }
3052
3053
    /**
3054
     * returns name of coutry that we expect the customer to have
3055
     * This takes into consideration more than just what has been entered
3056
     * for example, it looks at GEO IP.
3057
     *
3058
     * @todo: why do we dont return a string IF there is only one item.
3059
     *
3060
     * @return string - country name
3061
     **/
3062
    public function getExpectedCountryName()
3063
    {
3064
        return EcommerceCountry::find_title(EcommerceCountry::get_country(false, $this->ID));
3065
    }
3066
3067
    /**
3068
     * return the title of the fixed country (if any).
3069
     *
3070
     * @return string | empty string
3071
     **/
3072
    public function FixedCountry()
3073
    {
3074
        return $this->getFixedCountry();
3075
    }
3076
    public function getFixedCountry()
3077
    {
3078
        $code = EcommerceCountry::get_fixed_country_code();
3079
        if ($code) {
3080
            return EcommerceCountry::find_title($code);
3081
        }
3082
3083
        return '';
3084
    }
3085
3086
    /**
3087
     * Returns the region that applies to the order.
3088
     * we check both billing and shipping, in case one of them is empty.
3089
     *
3090
     * @return DataObject | Null (EcommerceRegion)
0 ignored issues
show
Documentation introduced by
Should the return type not be DataObject|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
3091
     **/
3092
    public function Region()
3093
    {
3094
        return $this->getRegion();
3095
    }
3096
    public function getRegion()
3097
    {
3098
        $regionIDs = array(
3099
            'Billing' => 0,
3100
            'Shipping' => 0,
3101
        );
3102
        if ($this->BillingAddressID) {
0 ignored issues
show
Documentation introduced by
The property BillingAddressID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3103
            if ($billingAddress = $this->BillingAddress()) {
0 ignored issues
show
Bug introduced by
The method BillingAddress() does not exist on Order. Did you maybe mean getBillingAddressField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
3104
                if ($billingAddress->RegionID) {
3105
                    $regionIDs['Billing'] = $billingAddress->RegionID;
3106
                }
3107
            }
3108
        }
3109
        if ($this->CanHaveShippingAddress()) {
3110
            if ($this->ShippingAddressID) {
0 ignored issues
show
Documentation introduced by
The property ShippingAddressID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3111
                if ($shippingAddress = $this->ShippingAddress()) {
0 ignored issues
show
Bug introduced by
The method ShippingAddress() does not exist on Order. Did you maybe mean getShippingAddressField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
3112
                    if ($shippingAddress->ShippingRegionID) {
3113
                        $regionIDs['Shipping'] = $shippingAddress->ShippingRegionID;
3114
                    }
3115
                }
3116
            }
3117
        }
3118
        if (count($regionIDs)) {
3119
            //note the double-check with $this->CanHaveShippingAddress() and get_use_....
3120
            if ($this->CanHaveShippingAddress() && EcommerceConfig::get('OrderAddress', 'use_shipping_address_for_main_region_and_country') && $regionIDs['Shipping']) {
3121
                return EcommerceRegion::get()->byID($regionIDs['Shipping']);
3122
            } else {
3123
                return EcommerceRegion::get()->byID($regionIDs['Billing']);
3124
            }
3125
        } else {
3126
            return EcommerceRegion::get()->byID(EcommerceRegion::get_region_from_ip());
3127
        }
3128
    }
3129
3130
    /**
3131
     * Casted variable
3132
     * Currency is not the same as the standard one?
3133
     *
3134
     * @return bool
3135
     **/
3136
    public function HasAlternativeCurrency()
3137
    {
3138
        return $this->getHasAlternativeCurrency();
3139
    }
3140
    public function getHasAlternativeCurrency()
3141
    {
3142
        if ($currency = $this->CurrencyUsed()) {
0 ignored issues
show
Documentation Bug introduced by
The method CurrencyUsed does not exist on object<Order>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
3143
            if ($currency->IsDefault()) {
0 ignored issues
show
Coding Style introduced by
The if-else statement can be simplified to return !$currency->IsDefault();.
Loading history...
3144
                return false;
3145
            } else {
3146
                return true;
3147
            }
3148
        } else {
3149
            return false;
3150
        }
3151
    }
3152
3153
    /**
3154
     * Makes sure exchange rate is updated and maintained before order is submitted
3155
     * This method is public because it could be called from a shopping Cart Object.
3156
     **/
3157
    public function EnsureCorrectExchangeRate()
3158
    {
3159
        if (!$this->IsSubmitted()) {
3160
            $oldExchangeRate = $this->ExchangeRate;
0 ignored issues
show
Documentation introduced by
The property ExchangeRate does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3161
            if ($currency = $this->CurrencyUsed()) {
0 ignored issues
show
Documentation Bug introduced by
The method CurrencyUsed does not exist on object<Order>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
3162
                if ($currency->IsDefault()) {
3163
                    $this->ExchangeRate = 0;
0 ignored issues
show
Documentation introduced by
The property ExchangeRate does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3164
                } else {
3165
                    $this->ExchangeRate = $currency->getExchangeRate();
0 ignored issues
show
Documentation introduced by
The property ExchangeRate does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3166
                }
3167
            } else {
3168
                $this->ExchangeRate = 0;
0 ignored issues
show
Documentation introduced by
The property ExchangeRate does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3169
            }
3170
            if ($this->ExchangeRate != $oldExchangeRate) {
0 ignored issues
show
Documentation introduced by
The property ExchangeRate does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3171
                $this->write();
3172
            }
3173
        }
3174
    }
3175
3176
    /**
3177
     * speeds up processing by storing the IsSubmitted value
3178
     * we start with -1 to know if it has been requested before.
3179
     *
3180
     * @var bool
3181
     */
3182
    protected $_isSubmittedTempVar = -1;
3183
3184
    /**
3185
     * Casted variable - has the order been submitted?
3186
     * alias
3187
     * @param bool $recalculate
3188
     *
3189
     * @return bool
3190
     **/
3191
    public function IsSubmitted($recalculate = true)
3192
    {
3193
        return $this->getIsSubmitted($recalculate);
3194
    }
3195
3196
    /**
3197
     * Casted variable - has the order been submitted?
3198
     *
3199
     * @param bool $recalculate
3200
     *
3201
     * @return bool
3202
     **/
3203
    public function getIsSubmitted($recalculate = false)
3204
    {
3205
        if ($this->_isSubmittedTempVar === -1 || $recalculate) {
3206
            if ($this->SubmissionLog()) {
3207
                $this->_isSubmittedTempVar = true;
3208
            } else {
3209
                $this->_isSubmittedTempVar = false;
3210
            }
3211
        }
3212
3213
        return $this->_isSubmittedTempVar;
3214
    }
3215
3216
    /**
3217
     *
3218
     *
3219
     * @return bool
3220
     */
3221
    public function IsArchived()
3222
    {
3223
        $lastStep = OrderStep::get()->Last();
3224
        if ($lastStep) {
3225
            if ($lastStep->ID == $this->StatusID) {
0 ignored issues
show
Documentation introduced by
The property StatusID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3226
                return true;
3227
            }
3228
        }
3229
        return false;
3230
    }
3231
3232
    /**
3233
     * Submission Log for this Order (if any).
3234
     *
3235
     * @return Submission Log (OrderStatusLog_Submitted) | Null
3236
     **/
3237
    public function SubmissionLog()
3238
    {
3239
        $className = EcommerceConfig::get('OrderStatusLog', 'order_status_log_class_used_for_submitting_order');
3240
3241
        return $className::get()
3242
            ->Filter(array('OrderID' => $this->ID))
3243
            ->Last();
3244
    }
3245
3246
    /**
3247
     * @return int
3248
     */
3249
    public function SecondsSinceBeingSubmitted()
3250
    {
3251
        if ($submissionLog = $this->SubmissionLog()) {
3252
            return time() - strtotime($submissionLog->Created);
3253
        } else {
3254
            return 0;
3255
        }
3256
    }
3257
3258
    /**
3259
     * if the order can not be submitted,
3260
     * then the reasons why it can not be submitted
3261
     * will be returned by this method.
3262
     *
3263
     * @see Order::canSubmit
3264
     *
3265
     * @return ArrayList | null
0 ignored issues
show
Documentation introduced by
Should the return type not be ArrayList|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
3266
     */
3267
    public function SubmitErrors()
3268
    {
3269
        $al = null;
3270
        $extendedSubmitErrors = $this->extend('updateSubmitErrors');
3271
        if ($extendedSubmitErrors !== null && is_array($extendedSubmitErrors) && count($extendedSubmitErrors)) {
3272
            $al = ArrayList::create();
3273
            foreach ($extendedSubmitErrors as $returnResultArray) {
3274
                foreach ($returnResultArray as $issue) {
3275
                    if ($issue) {
3276
                        $al->push(ArrayData::create(array("Title" => $issue)));
3277
                    }
3278
                }
3279
            }
3280
        }
3281
        return $al;
3282
    }
3283
3284
    /**
3285
     * Casted variable - has the order been submitted?
3286
     *
3287
     * @param bool $withDetail
3288
     *
3289
     * @return string
3290
     **/
3291
    public function CustomerStatus($withDetail = true)
3292
    {
3293
        return $this->getCustomerStatus($withDetail);
3294
    }
3295
    public function getCustomerStatus($withDetail = true)
3296
    {
3297
        $str = '';
3298
        if ($this->MyStep()->ShowAsUncompletedOrder) {
3299
            $str = _t('Order.UNCOMPLETED', 'Uncompleted');
3300
        } elseif ($this->MyStep()->ShowAsInProcessOrder) {
3301
            $str = _t('Order.IN_PROCESS', 'In Process');
3302
        } elseif ($this->MyStep()->ShowAsCompletedOrder) {
3303
            $str = _t('Order.COMPLETED', 'Completed');
3304
        }
3305
        if ($withDetail) {
3306
            if (!$this->HideStepFromCustomer) {
0 ignored issues
show
Documentation introduced by
The property HideStepFromCustomer does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3307
                $str .= ' ('.$this->MyStep()->Name.')';
3308
            }
3309
        }
3310
3311
        return $str;
3312
    }
3313
3314
    /**
3315
     * Casted variable - does the order have a potential shipping address?
3316
     *
3317
     * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
3318
     **/
3319
    public function CanHaveShippingAddress()
3320
    {
3321
        return $this->getCanHaveShippingAddress();
3322
    }
3323
    public function getCanHaveShippingAddress()
3324
    {
3325
        return EcommerceConfig::get('OrderAddress', 'use_separate_shipping_address');
3326
    }
3327
3328
    /**
3329
     * returns the link to view the Order
3330
     * WHY NOT CHECKOUT PAGE: first we check for cart page.
3331
     *
3332
     * @return CartPage | Null
3333
     */
3334
    public function DisplayPage()
3335
    {
3336
        if ($this->MyStep() && $this->MyStep()->AlternativeDisplayPage()) {
3337
            $page = $this->MyStep()->AlternativeDisplayPage();
3338
        } elseif ($this->IsSubmitted()) {
3339
            $page = OrderConfirmationPage::get()->First();
3340
        } else {
3341
            $page = CartPage::get()
3342
                ->Filter(array('ClassName' => 'CartPage'))
3343
                ->First();
3344
            if (!$page) {
3345
                $page = CheckoutPage::get()->First();
3346
            }
3347
        }
3348
3349
        return $page;
3350
    }
3351
3352
    /**
3353
     * returns the link to view the Order
3354
     * WHY NOT CHECKOUT PAGE: first we check for cart page.
3355
     * If a cart page has been created then we refer through to Cart Page.
3356
     * Otherwise it will default to the checkout page.
3357
     *
3358
     * @param string $action - any action that should be added to the link.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $action not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
3359
     *
3360
     * @return String(URLSegment)
0 ignored issues
show
Documentation introduced by
The doc-type String(URLSegment) could not be parsed: Expected "|" or "end of type", but got "(" at position 6. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
3361
     */
3362
    public function Link($action = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
3363
    {
3364
        $page = $this->DisplayPage();
3365
        if ($page) {
3366
            return $page->getOrderLink($this->ID, $action);
3367
        } else {
3368
            user_error('A Cart / Checkout Page + an Order Confirmation Page needs to be setup for the e-commerce module to work.', E_USER_NOTICE);
3369
            $page = ErrorPage::get()
3370
                ->Filter(array('ErrorCode' => '404'))
3371
                ->First();
3372
            if ($page) {
3373
                return $page->Link();
3374
            }
3375
        }
3376
    }
3377
3378
    /**
3379
     * Returns to link to access the Order's API.
3380
     *
3381
     * @param string $version
3382
     * @param string $extension
3383
     *
3384
     * @return String(URL)
0 ignored issues
show
Documentation introduced by
The doc-type String(URL) could not be parsed: Expected "|" or "end of type", but got "(" at position 6. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
3385
     */
3386
    public function APILink($version = 'v1', $extension = 'xml')
3387
    {
3388
        return Director::AbsoluteURL("/api/ecommerce/$version/Order/".$this->ID."/.$extension");
3389
    }
3390
3391
    /**
3392
     * returns the link to finalise the Order.
3393
     *
3394
     * @return String(URLSegment)
0 ignored issues
show
Documentation introduced by
The doc-type String(URLSegment) could not be parsed: Expected "|" or "end of type", but got "(" at position 6. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
3395
     */
3396
    public function CheckoutLink()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
3397
    {
3398
        $page = CheckoutPage::get()->First();
3399
        if ($page) {
3400
            return $page->Link();
3401
        } else {
3402
            $page = ErrorPage::get()
3403
                ->Filter(array('ErrorCode' => '404'))
3404
                ->First();
3405
            if ($page) {
3406
                return $page->Link();
3407
            }
3408
        }
3409
    }
3410
3411
    /**
3412
     * Converts the Order into HTML, based on the Order Template.
3413
     *
3414
     * @return HTML Object
0 ignored issues
show
Documentation introduced by
Should the return type not be DBField?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
3415
     **/
3416
    public function ConvertToHTML()
3417
    {
3418
        Config::nest();
3419
        Config::inst()->update('SSViewer', 'theme_enabled', true);
3420
        $html = $this->renderWith('Order');
3421
        Config::unnest();
3422
        $html = preg_replace('/(\s)+/', ' ', $html);
3423
3424
        return DBField::create_field('HTMLText', $html);
3425
    }
3426
3427
    /**
3428
     * Converts the Order into a serialized string
3429
     * TO DO: check if this works and check if we need to use special sapphire serialization code.
3430
     *
3431
     * @return string - serialized object
3432
     **/
3433
    public function ConvertToString()
3434
    {
3435
        return serialize($this->addHasOneAndHasManyAsVariables());
3436
    }
3437
3438
    /**
3439
     * Converts the Order into a JSON object
3440
     * TO DO: check if this works and check if we need to use special sapphire JSON code.
3441
     *
3442
     * @return string -  JSON
3443
     **/
3444
    public function ConvertToJSON()
3445
    {
3446
        return json_encode($this->addHasOneAndHasManyAsVariables());
3447
    }
3448
3449
    /**
3450
     * returns itself wtih more data added as variables.
3451
     * We add has_one and has_many as variables like this: $this->MyHasOne_serialized = serialize($this->MyHasOne()).
3452
     *
3453
     * @return Order - with most important has one and has many items included as variables.
3454
     **/
3455
    protected function addHasOneAndHasManyAsVariables()
3456
    {
3457
        $object = clone $this;
3458
        $object->Member_serialized = serialize($this->Member());
0 ignored issues
show
Documentation introduced by
The property Member_serialized does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method Member() does not exist on Order. Did you maybe mean CreateOrReturnExistingMember()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
3459
        $object->BillingAddress_serialized = serialize($this->BillingAddress());
0 ignored issues
show
Documentation introduced by
The property BillingAddress_serialized does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method BillingAddress() does not exist on Order. Did you maybe mean getBillingAddressField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
3460
        $object->ShippingAddress_serialized = serialize($this->ShippingAddress());
0 ignored issues
show
Documentation introduced by
The property ShippingAddress_serialized does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method ShippingAddress() does not exist on Order. Did you maybe mean getShippingAddressField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
3461
        $object->Attributes_serialized = serialize($this->Attributes());
0 ignored issues
show
Documentation introduced by
The property Attributes_serialized does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method Attributes() does not exist on Order. Did you maybe mean getOrderAttributesByType()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
3462
        $object->OrderStatusLogs_serialized = serialize($this->OrderStatusLogs());
0 ignored issues
show
Documentation introduced by
The property OrderStatusLogs_serialized does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method OrderStatusLogs() does not exist on Order. Did you maybe mean getOrderStatusLogsTableField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
3463
        $object->Payments_serialized = serialize($this->Payments());
0 ignored issues
show
Documentation introduced by
The property Payments_serialized does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method Payments() does not exist on Order. Did you maybe mean getPaymentsField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
3464
        $object->Emails_serialized = serialize($this->Emails());
0 ignored issues
show
Documentation introduced by
The property Emails_serialized does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method Emails() does not exist on Order. Did you maybe mean getEmailsTableField()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
3465
3466
        return $object;
3467
    }
3468
3469
/*******************************************************
3470
   * 9. TEMPLATE RELATED STUFF
3471
*******************************************************/
3472
3473
    /**
3474
     * returns the instance of EcommerceConfigAjax for use in templates.
3475
     * In templates, it is used like this:
3476
     * $EcommerceConfigAjax.TableID.
3477
     *
3478
     * @return EcommerceConfigAjax
0 ignored issues
show
Documentation introduced by
Should the return type not be EcommerceConfigAjaxDefinitions?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
3479
     **/
3480
    public function AJAXDefinitions()
3481
    {
3482
        return EcommerceConfigAjax::get_one($this);
3483
    }
3484
3485
    /**
3486
     * returns the instance of EcommerceDBConfig.
3487
     *
3488
     * @return EcommerceDBConfig
3489
     **/
3490
    public function EcomConfig()
3491
    {
3492
        return EcommerceDBConfig::current_ecommerce_db_config();
3493
    }
3494
3495
    /**
3496
     * Collects the JSON data for an ajax return of the cart.
3497
     *
3498
     * @param array $js
3499
     *
3500
     * @return array (for use in AJAX for JSON)
3501
     **/
3502
    public function updateForAjax(array $js)
3503
    {
3504
        $function = EcommerceConfig::get('Order', 'ajax_subtotal_format');
3505
        if (is_array($function)) {
3506
            list($function, $format) = $function;
3507
        }
3508
        $subTotal = $this->$function();
3509
        if (isset($format)) {
3510
            $subTotal = $subTotal->$format();
3511
            unset($format);
3512
        }
3513
        $function = EcommerceConfig::get('Order', 'ajax_total_format');
3514
        if (is_array($function)) {
3515
            list($function, $format) = $function;
3516
        }
3517
        $total = $this->$function();
3518
        if (isset($format)) {
3519
            $total = $total->$format();
3520
        }
3521
        $ajaxObject = $this->AJAXDefinitions();
3522
        $js[] = array(
3523
            't' => 'id',
3524
            's' => $ajaxObject->TableSubTotalID(),
3525
            'p' => 'innerHTML',
3526
            'v' => $subTotal,
3527
        );
3528
        $js[] = array(
3529
            't' => 'id',
3530
            's' => $ajaxObject->TableTotalID(),
3531
            'p' => 'innerHTML',
3532
            'v' => $total,
3533
        );
3534
        $js[] = array(
3535
            't' => 'class',
3536
            's' => $ajaxObject->TotalItemsClassName(),
3537
            'p' => 'innerHTML',
3538
            'v' => $this->TotalItems($recalculate = true),
3539
        );
3540
        $js[] = array(
3541
            't' => 'class',
3542
            's' => $ajaxObject->TotalItemsTimesQuantityClassName(),
3543
            'p' => 'innerHTML',
3544
            'v' => $this->TotalItemsTimesQuantity(),
3545
        );
3546
        $js[] = array(
3547
            't' => 'class',
3548
            's' => $ajaxObject->ExpectedCountryClassName(),
3549
            'p' => 'innerHTML',
3550
            'v' => $this->ExpectedCountryName(),
3551
        );
3552
3553
        return $js;
3554
    }
3555
3556
    /**
3557
     * @ToDO: move to more appropriate class
3558
     *
3559
     * @return float
3560
     **/
3561
    public function SubTotalCartValue()
3562
    {
3563
        return $this->SubTotal;
0 ignored issues
show
Documentation introduced by
The property SubTotal does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3564
    }
3565
3566
/*******************************************************
3567
   * 10. STANDARD SS METHODS (requireDefaultRecords, onBeforeDelete, etc...)
3568
*******************************************************/
3569
3570
    /**
3571
     *standard SS method.
3572
     **/
3573
    public function populateDefaults()
3574
    {
3575
        parent::populateDefaults();
3576
    }
3577
3578
    public function onBeforeWrite()
3579
    {
3580
        parent::onBeforeWrite();
3581
        if (! $this->getCanHaveShippingAddress()) {
3582
            $this->UseShippingAddress = false;
0 ignored issues
show
Documentation introduced by
The property UseShippingAddress does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3583
        }
3584
        if (!$this->CurrencyUsedID) {
0 ignored issues
show
Documentation introduced by
The property CurrencyUsedID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3585
            $this->CurrencyUsedID = EcommerceCurrency::default_currency_id();
0 ignored issues
show
Documentation introduced by
The property CurrencyUsedID does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3586
        }
3587
        if (!$this->SessionID) {
0 ignored issues
show
Documentation introduced by
The property SessionID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3588
            $generator = Injector::inst()->create('RandomGenerator');
3589
            $token = $generator->randomToken('sha1');
3590
            $this->SessionID = substr($token, 0, 32);
0 ignored issues
show
Documentation introduced by
The property SessionID does not exist on object<Order>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3591
        }
3592
    }
3593
3594
    /**
3595
     * standard SS method
3596
     * adds the ability to update order after writing it.
3597
     **/
3598
    public function onAfterWrite()
0 ignored issues
show
Coding Style introduced by
onAfterWrite uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
3599
    {
3600
        parent::onAfterWrite();
3601
        //crucial!
3602
        self::set_needs_recalculating(true, $this->ID);
3603
        // quick double-check
3604
        if ($this->IsCancelled() && ! $this->IsArchived()) {
3605
            $this->Archive($avoidWrites = true);
3606
        }
3607
        if ($this->IsSubmitted($recalculate = true)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
3608
            //do nothing
3609
        } else {
3610
            if ($this->StatusID) {
0 ignored issues
show
Documentation introduced by
The property StatusID does not exist on object<Order>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
3611
                $this->calculateOrderAttributes($recalculate = false);
3612
                if (EcommerceRole::current_member_is_shop_admin()) {
3613
                    if (isset($_REQUEST['SubmitOrderViaCMS'])) {
3614
                        $this->tryToFinaliseOrder();
3615
                        //just in case it writes again...
3616
                        unset($_REQUEST['SubmitOrderViaCMS']);
3617
                    }
3618
                }
3619
            }
3620
        }
3621
    }
3622
3623
    /**
3624
     *standard SS method.
3625
     *
3626
     * delete attributes, statuslogs, and payments
3627
     * THIS SHOULD NOT BE USED AS ORDERS SHOULD BE CANCELLED NOT DELETED
3628
     */
3629
    public function onBeforeDelete()
3630
    {
3631
        parent::onBeforeDelete();
3632
        if ($attributes = $this->Attributes()) {
0 ignored issues
show
Bug introduced by
The method Attributes() does not exist on Order. Did you maybe mean getOrderAttributesByType()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
3633
            foreach ($attributes as $attribute) {
3634
                $attribute->delete();
3635
                $attribute->destroy();
3636
            }
3637
        }
3638
3639
        //THE REST WAS GIVING ERRORS - POSSIBLY DUE TO THE FUNNY RELATIONSHIP (one-one, two times...)
3640
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
3641
        if($billingAddress = $this->BillingAddress()) {
3642
            if($billingAddress->exists()) {
3643
                $billingAddress->delete();
3644
                $billingAddress->destroy();
3645
            }
3646
        }
3647
        if($shippingAddress = $this->ShippingAddress()) {
3648
            if($shippingAddress->exists()) {
3649
                $shippingAddress->delete();
3650
                $shippingAddress->destroy();
3651
            }
3652
        }
3653
3654
        if($statuslogs = $this->OrderStatusLogs()){
3655
            foreach($statuslogs as $log){
3656
                $log->delete();
3657
                $log->destroy();
3658
            }
3659
        }
3660
        if($payments = $this->Payments()){
3661
            foreach($payments as $payment){
3662
                $payment->delete();
3663
                $payment->destroy();
3664
            }
3665
        }
3666
        if($emails = $this->Emails()) {
3667
            foreach($emails as $email){
3668
                $email->delete();
3669
                $email->destroy();
3670
            }
3671
        }
3672
        */
3673
    }
3674
3675
/*******************************************************
3676
   * 11. DEBUG
3677
*******************************************************/
3678
3679
    /**
3680
     * Debug helper method.
3681
     * Can be called from /shoppingcart/debug/.
3682
     *
3683
     * @return string
3684
     */
3685
    public function debug()
3686
    {
3687
        $this->calculateOrderAttributes(true);
3688
3689
        return EcommerceTaskDebugCart::debug_object($this);
3690
    }
3691
}
3692