1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\FoxyStripe\Model; |
4
|
|
|
|
5
|
|
|
use Dynamic\FoxyStripe\Page\ProductPage; |
6
|
|
|
use SilverStripe\Forms\FieldList; |
7
|
|
|
use SilverStripe\Forms\GridField\GridField; |
8
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RecordViewer; |
9
|
|
|
use SilverStripe\ORM\DataObject; |
10
|
|
|
use SilverStripe\Security\Permission; |
11
|
|
|
|
12
|
|
|
class OrderDetail extends DataObject |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private static $singular_name = 'Order Detail'; |
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private static $plural_name = 'Order Details'; |
|
|
|
|
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private static $description = ''; |
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
private static $db = array( |
|
|
|
|
33
|
|
|
'Quantity' => 'Int', |
34
|
|
|
'Price' => 'Currency', |
35
|
|
|
'ProductName' => 'Varchar(255)', |
36
|
|
|
'ProductCode' => 'Varchar(100)', |
37
|
|
|
'ProductImage' => 'Text', |
38
|
|
|
'ProductCategory' => 'Varchar(100)', |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
private static $has_one = array( |
|
|
|
|
45
|
|
|
'Product' => ProductPage::class, |
46
|
|
|
'Order' => Order::class, |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
private static $has_many = array( |
|
|
|
|
53
|
|
|
'OrderOptions' => OrderOption::class, |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var array |
58
|
|
|
*/ |
59
|
|
|
private static $many_many = [ |
|
|
|
|
60
|
|
|
'OptionItems' => OptionItem::class, |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var array |
65
|
|
|
*/ |
66
|
|
|
private static $summary_fields = array( |
|
|
|
|
67
|
|
|
'Product.Title', |
68
|
|
|
'Quantity', |
69
|
|
|
'Price.Nice', |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var string |
74
|
|
|
*/ |
75
|
|
|
private static $table_name = 'FS_OrderDetail'; |
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return FieldList |
79
|
|
|
*/ |
80
|
1 |
|
public function getCMSFields() |
81
|
|
|
{ |
82
|
1 |
|
$fields = parent::getCMSFields(); |
83
|
|
|
|
84
|
1 |
|
if ($this->ID) { |
85
|
1 |
|
$fields->addFieldsToTab('Root.Options', array( |
86
|
1 |
|
GridField::create( |
87
|
1 |
|
'Options', |
|
|
|
|
88
|
1 |
|
'Product Options', |
89
|
1 |
|
$this->OrderOptions(), |
|
|
|
|
90
|
1 |
|
GridFieldConfig_RecordViewer::create() |
91
|
|
|
), |
92
|
|
|
)); |
93
|
|
|
} |
94
|
|
|
|
95
|
1 |
|
return $fields; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param bool $member |
100
|
|
|
* |
101
|
|
|
* @return bool|int |
102
|
|
|
*/ |
103
|
49 |
|
public function canView($member = false) |
104
|
|
|
{ |
105
|
49 |
|
return Permission::check('Product_ORDERS', 'any', $member); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param null $member |
|
|
|
|
110
|
|
|
* |
111
|
|
|
* @return bool |
112
|
|
|
*/ |
113
|
1 |
|
public function canEdit($member = null) |
114
|
|
|
{ |
115
|
1 |
|
return false; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param null $member |
|
|
|
|
120
|
|
|
* |
121
|
|
|
* @return bool |
122
|
|
|
*/ |
123
|
1 |
|
public function canCreate($member = null, $context = []) |
124
|
|
|
{ |
125
|
1 |
|
return false; |
126
|
|
|
//return Permission::check('Product_ORDERS'); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
1 |
|
public function canDelete($member = null) |
130
|
|
|
{ |
131
|
1 |
|
return Permission::check('Product_ORDERS', 'any', $member); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|