|
1
|
|
|
<?php |
|
2
|
|
|
class RepeatOrder_OrderItem extends DataObject |
|
3
|
|
|
{ |
|
4
|
|
|
public static $db = array( |
|
5
|
|
|
'Quantity' => 'Int' |
|
6
|
|
|
); |
|
7
|
|
|
public static $has_one = array( |
|
8
|
|
|
'Product' => 'Product', |
|
9
|
|
|
'Order' => 'RepeatOrder', |
|
10
|
|
|
'Alternative1' => 'Product', |
|
11
|
|
|
'Alternative2' => 'Product', |
|
12
|
|
|
'Alternative3' => 'Product', |
|
13
|
|
|
'Alternative4' => 'Product', |
|
14
|
|
|
'Alternative5' => 'Product', |
|
15
|
|
|
'Alternative6' => 'Product', |
|
16
|
|
|
'Alternative7' => 'Product', |
|
17
|
|
|
'Alternative8' => 'Product', |
|
18
|
|
|
'Alternative9' => 'Product' |
|
19
|
|
|
); |
|
20
|
|
|
|
|
21
|
|
|
public function getCMSFields() |
|
22
|
|
|
{ |
|
23
|
|
|
$fields = parent::getCMSFields(); |
|
24
|
|
|
return $fields; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function Title() |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
if ($product = $this->Product()) { |
|
|
|
|
|
|
30
|
|
|
return $product->Title; |
|
31
|
|
|
} |
|
32
|
|
|
return "NOT FOUND"; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function BuyableTitle() |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
if ($product = $this->Product()) { |
|
|
|
|
|
|
38
|
|
|
return $product->Title; |
|
39
|
|
|
} |
|
40
|
|
|
return "NOT FOUND"; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* returns a link to the product |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
public function Link() |
|
48
|
|
|
{ |
|
49
|
|
|
if ($product = $this->Product()) { |
|
|
|
|
|
|
50
|
|
|
return $product->Link; |
|
51
|
|
|
} |
|
52
|
|
|
return ''; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* returns the product ID |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getProductID() |
|
60
|
|
|
{ |
|
61
|
|
|
if ($product = $this->Product()) { |
|
|
|
|
|
|
62
|
|
|
return $product->ID; |
|
63
|
|
|
} |
|
64
|
|
|
return 0; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return Field (EcomQuantityField) |
|
|
|
|
|
|
69
|
|
|
**/ |
|
70
|
|
|
public function IDField() |
|
71
|
|
|
{ |
|
72
|
|
|
$field = HiddenField::create( |
|
73
|
|
|
'Product[ID]['.$this->Product()->ID.']', |
|
|
|
|
|
|
74
|
|
|
"", |
|
75
|
|
|
$this->Product()->ID |
|
|
|
|
|
|
76
|
|
|
); |
|
77
|
|
|
return $field; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @return Field (EcomQuantityField) |
|
|
|
|
|
|
82
|
|
|
**/ |
|
83
|
|
|
public function QuantityField() |
|
84
|
|
|
{ |
|
85
|
|
|
$field = NumericField::create( |
|
86
|
|
|
'Product[Quantity]['.$this->Product()->ID.']', |
|
|
|
|
|
|
87
|
|
|
"", |
|
88
|
|
|
$this->Quantity |
|
|
|
|
|
|
89
|
|
|
)->addExtraClass('ajaxQuantityField'); |
|
90
|
|
|
return $field; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Alias for AlternativesPerProduct |
|
95
|
|
|
*/ |
|
96
|
|
|
public function TableAlternatives() |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->AlternativesPerProduct(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* returns a list of alternatives per product (if any) |
|
103
|
|
|
* @return ArrayList|null |
|
104
|
|
|
*/ |
|
105
|
|
|
public function AlternativesPerProduct() |
|
106
|
|
|
{ |
|
107
|
|
|
$dos = ArrayList::create(); |
|
108
|
|
|
$altCount = Config::inst()->get('RepeatOrderForm', 'number_of_product_alternatives'); |
|
109
|
|
|
for ($i = 1; $i <= $altCount; $i++) { |
|
110
|
|
|
$alternativeField = "Alternative".$i."ID"; |
|
111
|
|
|
if ($this->$alternativeField) { |
|
112
|
|
|
$product = Product::get()->filter(['ID' => $this->$alternativeField])->first(); |
|
113
|
|
|
if ($product) { |
|
114
|
|
|
$dos->push($product); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
if ($dos && $dos->count()) { |
|
119
|
|
|
return $dos; |
|
120
|
|
|
} |
|
121
|
|
|
return null; |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
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
@returnannotation as described here.