1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @description: this class is the base class for modifier forms in the checkout form... we could do with more stuff here.... |
5
|
|
|
* |
6
|
|
|
* |
7
|
|
|
* @authors: Nicolaas [at] Sunny Side Up .co.nz |
8
|
|
|
* @package: ecommerce |
9
|
|
|
* @sub-package: forms |
10
|
|
|
* @inspiration: Silverstripe Ltd, Jeremy |
11
|
|
|
**/ |
12
|
|
|
class OrderModifierForm extends Form |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Order |
16
|
|
|
*/ |
17
|
|
|
protected $order; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
*NOTE: we semi-enforce using the OrderModifier_Controller here to deal with the submission of the OrderModifierForm |
21
|
|
|
* You can use your own modifiers or an extension of OrderModifier_Controller by setting the first parameter (optionalController) |
22
|
|
|
* to your own controller. |
23
|
|
|
* |
24
|
|
|
*@param $optionalController Controller |
25
|
|
|
*@param $name String |
26
|
|
|
*@param $fields FieldList |
27
|
|
|
*@param $actions FieldList |
28
|
|
|
*@param $validator SS_Validator |
29
|
|
|
**/ |
30
|
|
|
public function __construct( |
31
|
|
|
Controller $optionalController = null, |
32
|
|
|
$name, |
|
|
|
|
33
|
|
|
FieldList $fields, |
34
|
|
|
FieldList $actions, |
35
|
|
|
Validator $optionalValidator = null |
36
|
|
|
) { |
37
|
|
|
if (!$optionalController) { |
38
|
|
|
$controllerClassName = EcommerceConfig::get('OrderModifierForm', 'controller_class'); |
39
|
|
|
$optionalController = new $controllerClassName(); |
40
|
|
|
} |
41
|
|
|
if (!$optionalValidator) { |
42
|
|
|
$validatorClassName = EcommerceConfig::get('OrderModifierForm', 'validator_class'); |
43
|
|
|
$optionalValidator = new $validatorClassName(); |
44
|
|
|
} |
45
|
|
|
parent::__construct($optionalController, $name, $fields, $actions, $optionalValidator); |
46
|
|
|
|
47
|
|
|
//extension point |
48
|
|
|
$this->extend('updateFields', $fields); |
49
|
|
|
$this->setFields($fields); |
50
|
|
|
$this->extend('updateActions', $actions); |
51
|
|
|
$this->setActions($actions); |
52
|
|
|
$this->extend('updateValidator', $optionalValidator); |
53
|
|
|
$this->setValidator($optionalValidator); |
54
|
|
|
|
55
|
|
|
$this->setAttribute('autocomplete', 'off'); |
56
|
|
|
Requirements::themedCSS($this->ClassName, 'ecommerce'); |
|
|
|
|
57
|
|
|
$this->addExtraClass($this->myLcFirst(ucwords($name))); |
|
|
|
|
58
|
|
|
Requirements::javascript(THIRDPARTY_DIR.'/jquery-form/jquery.form.js'); |
59
|
|
|
//add JS for the modifier - added in modifier |
60
|
|
|
$oldData = Session::get("FormInfo.{$this->FormName()}.data"); |
61
|
|
|
if ($oldData && (is_array($oldData) || is_object($oldData))) { |
62
|
|
|
$this->loadDataFrom($oldData); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
$this->extend('updateOrderModifierForm', $this); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function myLcFirst($str) |
68
|
|
|
{ |
69
|
|
|
if (function_exists('lcfirst') === false) { |
70
|
|
|
function lcfirst($str) |
71
|
|
|
{ |
72
|
|
|
$str[0] = strtolower($str[0]); |
73
|
|
|
|
74
|
|
|
return $str; |
75
|
|
|
} |
76
|
|
|
} else { |
77
|
|
|
return lcfirst($str); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param string $status |
83
|
|
|
* @param string $message |
84
|
|
|
*/ |
85
|
|
|
public function redirect($status = 'success', $message = '') |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
//return ShoppingCart::singleton()->addmessage($status, $message); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param array $data |
92
|
|
|
* @param Form $form |
93
|
|
|
* @param string $status |
94
|
|
|
* @param string $message |
95
|
|
|
* |
96
|
|
|
* @return ShoppingCart Response (JSON / Redirect Back) |
97
|
|
|
*/ |
98
|
|
|
public function submit(array $data, Form $form, $message = 'order updated', $status = 'good') |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
//to do - add other checks here... |
101
|
|
|
return ShoppingCart::singleton()->setMessageAndReturn($message, $status); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* saves the form into session. |
106
|
|
|
* |
107
|
|
|
* @param array $data - data from form. |
|
|
|
|
108
|
|
|
*/ |
109
|
|
|
public function saveDataToSession() |
110
|
|
|
{ |
111
|
|
|
$data = $this->getData(); |
112
|
|
|
Session::set("FormInfo.{$this->FormName()}.data", $data); |
|
|
|
|
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.