|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class SecondHandArchive extends DataObject |
|
|
|
|
|
|
5
|
|
|
{ |
|
6
|
|
|
private static $db = array( |
|
|
|
|
|
|
7
|
|
|
'Title' => 'Varchar(255)', |
|
8
|
|
|
'Price' => 'Currency', |
|
9
|
|
|
'InternalItemID' => 'Varchar(50)', |
|
10
|
|
|
'PurchasePrice' => 'Currency', |
|
11
|
|
|
'ProductQuality' => 'ENUM("1, 2, 3, 4, 5, 6, 7, 8, 9, 10","10")', |
|
12
|
|
|
'IncludesBoxOrCase' => 'ENUM("No, Box, Case, Both","No")', |
|
13
|
|
|
'OriginalManual' => 'Boolean', |
|
14
|
|
|
'SerialNumber' => 'VarChar(50)', |
|
15
|
|
|
'PageID' => 'Int' |
|
16
|
|
|
); |
|
17
|
|
|
|
|
18
|
|
|
public static function create_from_page($page) |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
if ($page->InternalItemID) { |
|
21
|
|
|
$filter = array( |
|
22
|
|
|
'InternalItemID' => $page->InternalItemID |
|
23
|
|
|
); |
|
24
|
|
|
} else { |
|
25
|
|
|
$filter = array( |
|
26
|
|
|
'PageID' => $page->ID |
|
27
|
|
|
); |
|
28
|
|
|
} |
|
29
|
|
|
$obj = SecondHandArchive::get()->filter($filter)->first(); |
|
30
|
|
|
if (! $obj) { |
|
31
|
|
|
$obj = SecondHandArchive::create($filter); |
|
32
|
|
|
} |
|
33
|
|
|
$obj->Title = $page->Title; |
|
34
|
|
|
$obj->Price = $page->Price; |
|
35
|
|
|
$obj->InternalItemID = $page->InternalItemID; |
|
36
|
|
|
$obj->PageID = $page->ID; |
|
37
|
|
|
$obj->PurchasePrice = $page->PurchasePrice; |
|
38
|
|
|
$obj->ProductQuality = $page->ProductQuality; |
|
39
|
|
|
$obj->IncludesBoxOrCase = $page->IncludesBoxOrCase; |
|
40
|
|
|
$obj->OriginalManual = $page->OriginalManual; |
|
41
|
|
|
$obj->SerialNumber = $page->SerialNumber; |
|
42
|
|
|
$obj->write(); |
|
43
|
|
|
return $obj; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* stadard SS method |
|
49
|
|
|
* @return Boolean |
|
50
|
|
|
*/ |
|
51
|
|
|
public function canCreate($member = null) |
|
52
|
|
|
{ |
|
53
|
|
|
return false; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* stadard SS method |
|
59
|
|
|
* @return Boolean |
|
60
|
|
|
*/ |
|
61
|
|
|
public function canEdit($member = null) |
|
62
|
|
|
{ |
|
63
|
|
|
return false; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* stadard SS method |
|
68
|
|
|
* @return Boolean |
|
|
|
|
|
|
69
|
|
|
*/ |
|
70
|
|
|
public function canView($member = null) |
|
71
|
|
|
{ |
|
72
|
|
|
return Permission::check( |
|
73
|
|
|
EcommerceConfig::get('SecondHandProduct', 'second_hand_admin_permission_code') |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* stadard SS method |
|
79
|
|
|
* @return Boolean |
|
80
|
|
|
*/ |
|
81
|
|
|
public function canDelete($member = null) |
|
82
|
|
|
{ |
|
83
|
|
|
return false; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
private static $singular_name = 'Archived Second Hand Product'; |
|
|
|
|
|
|
88
|
|
|
|
|
89
|
|
|
public function i18n_singular_name() |
|
90
|
|
|
{ |
|
91
|
|
|
return self::$singular_name; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
private static $plural_name = 'Archived Second Hand Products'; |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
public function i18n_plural_name() |
|
97
|
|
|
{ |
|
98
|
|
|
return self::$plural_name; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
private static $indexes = array( |
|
|
|
|
|
|
102
|
|
|
'PageID' => true, |
|
103
|
|
|
'InternalItemID' => true |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
private static $default_sort = array( |
|
|
|
|
|
|
107
|
|
|
'Title' => 'ASC' |
|
108
|
|
|
); |
|
109
|
|
|
|
|
110
|
|
|
private static $summary_fields = array( |
|
|
|
|
|
|
111
|
|
|
'Title' => 'Title', |
|
112
|
|
|
'Price' => 'Sale Price', |
|
113
|
|
|
'InternalItemID' => 'Code', |
|
114
|
|
|
'PurchasePrice' => 'Purchase Price', |
|
115
|
|
|
'ProductQuality' => 'Quality', |
|
116
|
|
|
'IncludesBoxOrCase' => 'Includes', |
|
117
|
|
|
'OriginalManual.Nice' => 'Has Manual', |
|
118
|
|
|
'SerialNumber' => 'Serial Number' |
|
119
|
|
|
); |
|
120
|
|
|
|
|
121
|
|
|
private static $field_labels = array( |
|
|
|
|
|
|
122
|
|
|
'Title' => 'Title', |
|
123
|
|
|
'Price' => 'Sale Price', |
|
124
|
|
|
'InternalItemID' => 'Code', |
|
125
|
|
|
'PurchasePrice' => 'Purchase Price', |
|
126
|
|
|
'ProductQuality' => 'Quality', |
|
127
|
|
|
'IncludesBoxOrCase' => 'Includes', |
|
128
|
|
|
'OriginalManual' => 'Has Manual', |
|
129
|
|
|
'SerialNumber' => 'Serial Number' |
|
130
|
|
|
); |
|
131
|
|
|
|
|
132
|
|
|
private static $searchable_fields = array( |
|
|
|
|
|
|
133
|
|
|
'Title' => 'PartialMatchFilter', |
|
134
|
|
|
'Price' => 'ExactMatchFilter', |
|
135
|
|
|
'InternalItemID' => 'PartialMatchFilter', |
|
136
|
|
|
'PurchasePrice' => 'ExactMatchFilter', |
|
137
|
|
|
'ProductQuality' => 'ExactMatchFilter', |
|
138
|
|
|
'IncludesBoxOrCase' => 'ExactMatchFilter', |
|
139
|
|
|
'OriginalManual' => 'ExactMatchFilter', |
|
140
|
|
|
'SerialNumber' => 'PartialMatchFilter' |
|
141
|
|
|
); |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* stadard SS method |
|
145
|
|
|
* @return FieldList |
|
146
|
|
|
*/ |
|
147
|
|
|
public function getCMSFields() |
|
148
|
|
|
{ |
|
149
|
|
|
$fields = parent::getCMSFields(); |
|
150
|
|
|
$fields->addFieldsToTab( |
|
151
|
|
|
'Root.Main', |
|
152
|
|
|
array( |
|
153
|
|
|
EcommerceCMSButtonField::create( |
|
154
|
|
|
'RestoreButton', |
|
155
|
|
|
'/admin/secondhandproducts/SecondHandProduct/restore/?productid=' . $this->PageID, |
|
|
|
|
|
|
156
|
|
|
_t('SecondHandArchive.RESTORE_BUTTON', 'Restore Product') |
|
157
|
|
|
) |
|
158
|
|
|
) |
|
159
|
|
|
); |
|
160
|
|
|
return $fields; |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.