Completed
Push — master ( 1552c3...bf9266 )
by Nicolaas
15:17
created

OrderStep_Sent::CalculatedCustomerMessage()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 4
nop 1
dl 0
loc 12
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @authors: Nicolaas [at] Sunny Side Up .co.nz
5
 * @package: ecommerce
6
 * @sub-package: model
7
 * @inspiration: Silverstripe Ltd, Jeremy
8
 **/
9
class OrderStep_Sent extends OrderStep implements OrderStepInterface
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...
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $emailClassName = 'Order_StatusEmail';
15
16
    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...
17
        'SendDetailsToCustomer' => 'Boolean',
18
        'EmailSubjectGift' => 'Varchar(200)',
19
        'CustomerMessageGift' => 'HTMLText'
20
    );
21
22
    private static $defaults = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $defaults is not used and could be removed.

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

Loading history...
23
        'CustomerCanEdit' => 0,
24
        'CustomerCanCancel' => 0,
25
        'CustomerCanPay' => 0,
26
        'Name' => 'Send Order',
27
        'Code' => 'SENT',
28
        'ShowAsInProcessOrder' => 1
29
    );
30
31
    private static $field_labels = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $field_labels is not used and could be removed.

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

Loading history...
32
        'EmailSubjectGift' => 'Email subject',
33
        'CustomerMessageGift' => 'Customer message'
34
    ];
35
36
    /**
37
     * The OrderStatusLog that is relevant to the particular step.
38
     *
39
     * @var string
40
     */
41
    protected $relevantLogEntryClassName = 'OrderStatusLog_DispatchPhysicalOrder';
42
43
    public function getCMSFields()
44
    {
45
        $fields = parent::getCMSFields();
46
        $fields->addFieldToTab('Root.Main', new HeaderField('ActuallySendDetails', _t('OrderStep.ACTUALLYSENDDETAILS', 'Send details to the customer?'), 3), 'SendDetailsToCustomer');
47
        $fields->addFieldsToTab(
48
            'Root.CustomerMessage',
49
            [
50
                HeaderField::create(
51
                    'GiftHeader',
52
                    _t('OrderStep.SEPARATE_DELIVERY', 'Message for separate shipping address ...')
53
                ),
54
                TextField::create(
55
                    'EmailSubjectGift',
56
                    _t('OrderStep.EmailSubjectGift', 'Subject')
57
                ),
58
                HTMLEditorField::create(
59
                    'CustomerMessageGift',
60
                    _t('OrderStep.CustomerMessageGift', 'Message')
61
                )->setRows(5)
62
            ]
63
        );
64
65
        return $fields;
66
    }
67
68
    /**
69
     *initStep:
70
     * makes sure the step is ready to run.... (e.g. check if the order is ready to be emailed as receipt).
71
     * should be able to run this function many times to check if the step is ready.
72
     *
73
     * @see Order::doNextStatus
74
     *
75
     * @param Order object
76
     *
77
     * @return bool - true if the current step is ready to be run...
78
     **/
79
    public function initStep(Order $order)
80
    {
81
        return true;
82
    }
83
84
    /**
85
     *doStep:
86
     * should only be able to run this function once
87
     * (init stops you from running it twice - in theory....)
88
     * runs the actual step.
89
     *
90
     * @see Order::doNextStatus
91
     *
92
     * @param Order object
93
     *
94
     * @return bool - true if run correctly.
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...
95
     **/
96
    public function doStep(Order $order)
97
    {
98
        if ($this->RelevantLogEntry($order)) {
99
            return $this->sendEmailForStep(
100
                $order,
101
                $subject = $this->CalculatedEmailSubject($order),
102
                $message = $this->CalculatedCustomerMessage($order),
103
                $resend = false,
104
                $this->SendDetailsToCustomer ? false : true,
0 ignored issues
show
Documentation introduced by
The property SendDetailsToCustomer does not exist on object<OrderStep_Sent>. 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...
105
                $this->getEmailClassName()
106
            );
107
        }
108
    }
109
110
    /**
111
     *nextStep:
112
     * returns the next step (after it checks if everything is in place for the next step to run...).
113
     *
114
     * @see Order::doNextStatus
115
     *
116
     * @param Order $order
117
     *
118
     * @return OrderStep | Null (next step OrderStep object)
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...
119
     **/
120
    public function nextStep(Order $order)
121
    {
122
        if (!$this->SendDetailsToCustomer || $this->hasBeenSent($order)) {
0 ignored issues
show
Documentation introduced by
The property SendDetailsToCustomer does not exist on object<OrderStep_Sent>. 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...
123
            return parent::nextStep($order);
124
        }
125
126
        return;
127
    }
128
129
    /**
130
     * Allows the opportunity for the Order Step to add any fields to Order::getCMSFields.
131
     *
132
     * @param FieldList $fields
133
     * @param Order     $order
134
     *
135
     * @return FieldList
136
     **/
137
    public function addOrderStepFields(FieldList $fields, Order $order)
138
    {
139
        $fields = parent::addOrderStepFields($fields, $order);
140
        $title = _t('OrderStep.MUSTENTERDISPATCHRECORD', ' ... To move this order to the next step please enter dispatch details.');
141
        $fields->addFieldToTab('Root.Next', $order->getOrderStatusLogsTableField('OrderStatusLog_DispatchPhysicalOrder', $title), 'ActionNextStepManually');
142
143
        return $fields;
144
    }
145
146
    /**
147
     * For some ordersteps this returns true...
148
     *
149
     * @return bool
150
     **/
151
    protected function hasCustomerMessage()
152
    {
153
        return $this->SendDetailsToCustomer;
0 ignored issues
show
Documentation introduced by
The property SendDetailsToCustomer does not exist on object<OrderStep_Sent>. 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...
154
    }
155
156
    /**
157
     * Explains the current order step.
158
     *
159
     * @return string
160
     */
161
    protected function myDescription()
162
    {
163
        return _t('OrderStep.SENT_DESCRIPTION', 'During this step we record the delivery details for the order such as the courrier ticket number and whatever else is relevant.');
164
    }
165
166
    public function CalculatedEmailSubject($order = 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...
167
    {
168
        $v = null;
169
        if($order && $order->IsSeparateShippingAddress()) {
170
            $v = $this->EmailSubjectGift;
0 ignored issues
show
Documentation introduced by
The property EmailSubjectGift does not exist on object<OrderStep_Sent>. 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...
171
        }
172
        if(! $v) {
173
            $v = $this->EmailSubject;
0 ignored issues
show
Documentation introduced by
The property EmailSubject does not exist on object<OrderStep_Sent>. 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...
174
        }
175
176
        return $v;
177
    }
178
179
    public function CalculatedCustomerMessage($order = 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...
180
    {
181
        $v = null;
182
        if($order && $order->IsSeparateShippingAddress()) {
183
            $v = $this->CustomerMessageGift;
0 ignored issues
show
Documentation introduced by
The property CustomerMessageGift does not exist on object<OrderStep_Sent>. 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...
184
        }
185
        if(! $v) {
186
            $v = $this->CustomerMessage;
0 ignored issues
show
Documentation introduced by
The property CustomerMessage does not exist on object<OrderStep_Sent>. 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...
187
        }
188
189
        return $v;
190
    }
191
}
192