1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* @description: CMS management for everything you have sold and all related data (e.g. logs, payments) |
6
|
|
|
* |
7
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
8
|
|
|
* @package: ecommerce |
9
|
|
|
* @sub-package: cms |
10
|
|
|
* @inspiration: Silverstripe Ltd, Jeremy |
11
|
|
|
**/ |
12
|
|
|
class SalesAdminExtras extends ModelAdminEcommerceBaseClass |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* standard SS variable. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private static $url_segment = 'sales-advanced'; |
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* standard SS variable. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private static $menu_title = 'Sales Details'; |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* standard SS variable. |
30
|
|
|
* |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
private static $menu_priority = 3.11; |
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Change this variable if you don't want the Import from CSV form to appear. |
37
|
|
|
* This variable can be a boolean or an array. |
38
|
|
|
* If array, you can list className you want the form to appear on. i.e. array('myClassOne','myClasstwo'). |
39
|
|
|
*/ |
40
|
|
|
public $showImportForm = false; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* standard SS variable. |
44
|
|
|
* |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
private static $menu_icon = 'ecommerce/images/icons/money-file.gif'; |
|
|
|
|
48
|
|
|
|
49
|
|
|
public function init() |
50
|
|
|
{ |
51
|
|
|
parent::init(); |
52
|
|
|
Requirements::javascript('ecommerce/javascript/EcomBuyableSelectField.js'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @return array Map of class name to an array of 'title' (see {@link $managed_models}) |
58
|
|
|
* we make sure that the Order Admin is FIRST |
59
|
|
|
*/ |
60
|
|
|
public function getManagedModels() |
61
|
|
|
{ |
62
|
|
|
$models = parent::getManagedModels(); |
63
|
|
|
$orderModelManagement = isset($models['Order']) ? $models['Order'] : null; |
64
|
|
|
if ($orderModelManagement) { |
65
|
|
|
unset($models['Order']); |
66
|
|
|
|
67
|
|
|
return array('Order' => $orderModelManagement) + $models; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $models; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return DataList |
75
|
|
|
*/ |
76
|
|
|
public function getList() |
77
|
|
|
{ |
78
|
|
|
$list = parent::getList(); |
79
|
|
|
if (is_subclass_of($this->modelClass, 'Order') || $this->modelClass === 'Order') { |
80
|
|
|
$submittedOrderStatusLogClassName = EcommerceConfig::get('OrderStatusLog', 'order_status_log_class_used_for_submitting_order'); |
81
|
|
|
$list = $list |
82
|
|
|
->LeftJoin('OrderStatusLog', '"Order"."ID" = "OrderStatusLog"."OrderID"') |
83
|
|
|
->LeftJoin($submittedOrderStatusLogClassName, '"OrderStatusLog"."ID" = "'.$submittedOrderStatusLogClassName.'"."ID"') |
84
|
|
|
->where('"OrderStatusLog"."ClassName" = \''.$submittedOrderStatusLogClassName.'\''); |
85
|
|
|
} |
86
|
|
|
$newLists = $this->extend('updateGetList', $list); |
87
|
|
|
if (is_array($newLists) && count($newLists)) { |
88
|
|
|
foreach ($newLists as $newList) { |
89
|
|
|
if ($newList instanceof DataList) { |
90
|
|
|
$list = $newList; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $list; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
public function getEditForm($id = null, $fields = null) |
100
|
|
|
{ |
101
|
|
|
$form = parent::getEditForm($id, $fields); |
102
|
|
|
if (is_subclass_of($this->modelClass, 'Order') || $this->modelClass === 'Order') { |
103
|
|
|
if ($gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass))) { |
104
|
|
|
if ($gridField instanceof GridField) { |
105
|
|
|
$config = $gridField->getConfig(); |
106
|
|
|
$exportButton = new GridFieldExportSalesButton('buttons-before-left'); |
107
|
|
|
$exportButton->setExportColumns($this->getExportFields()); |
108
|
|
|
$config->addComponent($exportButton); |
109
|
|
|
$printAllInvoices = new GridFieldPrintAllInvoicesButton('buttons-before-left'); |
110
|
|
|
$config->addComponent($printAllInvoices); |
111
|
|
|
$printAllPackingSlips = new GridFieldPrintAllPackingSlipsButton('buttons-before-left'); |
112
|
|
|
$config->addComponent($printAllPackingSlips); |
113
|
|
|
//per row ... |
114
|
|
|
$config->addComponent(new GridFieldPrintInvoiceButton()); |
115
|
|
|
// $config->addComponent(new GridFieldPrintPackingSlipButton()); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
return $form; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|