1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @description: for the management of Product and Product Groups only |
5
|
|
|
* |
6
|
|
|
* |
7
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
8
|
|
|
* @package: ecommerce |
9
|
|
|
* @sub-package: cms |
10
|
|
|
**/ |
11
|
|
|
|
12
|
|
|
class SecondHandProductAdmin extends ModelAdminEcommerceBaseClass |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
private static $menu_priority = 3.2; |
|
|
|
|
15
|
|
|
|
16
|
|
|
private static $url_segment = 'secondhandproducts'; |
|
|
|
|
17
|
|
|
|
18
|
|
|
private static $menu_title = 'Second Hand'; |
|
|
|
|
19
|
|
|
|
20
|
|
|
private static $managed_models = array( |
|
|
|
|
21
|
|
|
'SecondHandProduct', |
22
|
|
|
'SecondHandArchive' |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
private static $allowed_actions = array( |
|
|
|
|
26
|
|
|
"editinsitetree", |
27
|
|
|
"ItemEditForm", |
28
|
|
|
"archive" => true, |
29
|
|
|
"restore" => true, |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* standard SS variable |
34
|
|
|
* @var String |
35
|
|
|
*/ |
36
|
|
|
private static $menu_icon = "ecommerce/images/icons/product-file.gif"; |
|
|
|
|
37
|
|
|
|
38
|
|
|
|
39
|
|
|
public function getEditForm($id = null, $fields = null) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
foreach (GoogleAddressField::js_requirements() as $jsFile) { |
42
|
|
|
Requirements::javascript($jsFile); |
43
|
|
|
} |
44
|
|
|
$form = parent::getEditForm(); |
45
|
|
|
if (singleton($this->modelClass) instanceof SiteTree) { |
46
|
|
|
if ($gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass))) { |
47
|
|
|
if ($gridField instanceof GridField) { |
48
|
|
|
$gridField->setConfig(GridFieldEditOriginalPageConfigSecondHandPage::create()); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
return $form; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
public function doCancel($data, $form) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
return $this->redirect(singleton('CMSMain')->Link()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
function archive($request){ |
|
|
|
|
62
|
|
|
if(isset($_GET['productid'])){ |
63
|
|
|
$id = intval($_GET['productid']); |
64
|
|
|
if($id) { |
65
|
|
|
$secondHandProduct = SecondHandProduct::get()->byID($id); |
66
|
|
|
$internalItemID = $secondHandProduct->InternalItemID; |
67
|
|
|
if (is_a($secondHandProduct, Object::getCustomClass('SiteTree'))) { |
68
|
|
|
$secondHandProduct->deleteFromStage('Live'); |
69
|
|
|
$secondHandProduct->deleteFromStage('Stage'); |
70
|
|
|
} else { |
71
|
|
|
$secondHandProduct->delete(); |
72
|
|
|
} |
73
|
|
|
//after deleting the product redirect to the archived page |
74
|
|
|
$archivedProduct = SecondHandArchive::get()->filter(['InternalItemID' => $internalItemID])->first(); |
75
|
|
|
if($archivedProduct){ |
76
|
|
|
$this->getResponse()->addHeader( |
77
|
|
|
'X-Status', |
78
|
|
|
rawurlencode(_t( |
79
|
|
|
'CMSMain.RESTORED', |
80
|
|
|
"Archived '{title}' successfully", |
81
|
|
|
array('title' => $archivedProduct->Title) |
|
|
|
|
82
|
|
|
)) |
83
|
|
|
); |
84
|
|
|
$cmsEditLink = '/admin/secondhandproducts/SecondHandArchive/EditForm/field/SecondHandArchive/item/'.$archivedProduct->ID.'/edit'; |
85
|
|
|
return Controller::curr()->redirect($cmsEditLink); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
return new SS_HTTPResponse("ERROR!", 400); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
function restore($request){ |
|
|
|
|
93
|
|
|
if(isset($_GET['productid'])){ |
94
|
|
|
$id = intval($_GET['productid']); |
95
|
|
|
if($id) { |
96
|
|
|
$restoredPage = Versioned::get_latest_version("SiteTree", $id); |
97
|
|
|
if(!$restoredPage) return new SS_HTTPResponse("SiteTree #$id not found", 400); |
98
|
|
|
$restoredPage = $restoredPage->doRestoreToStage(); |
99
|
|
|
$restoredPage->doPublish(); |
100
|
|
|
$this->getResponse()->addHeader( |
101
|
|
|
'X-Status', |
102
|
|
|
rawurlencode(_t( |
103
|
|
|
'CMSMain.RESTORED', |
104
|
|
|
"Restored '{title}' successfully", |
105
|
|
|
array('title' => $restoredPage->Title) |
|
|
|
|
106
|
|
|
)) |
107
|
|
|
); |
108
|
|
|
$cmsEditLink = '/admin/secondhandproducts/SecondHandProduct/EditForm/field/SecondHandProduct/item/'.$id.'/edit'; |
109
|
|
|
return Controller::curr()->redirect($cmsEditLink); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
return new SS_HTTPResponse("ERROR!", 400); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
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.