|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class ProductWishListControllerExtension |
|
5
|
|
|
*/ |
|
6
|
|
|
class ProductWishListControllerExtension extends Extension |
|
7
|
|
|
{ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @var array |
|
11
|
|
|
*/ |
|
12
|
|
|
private static $allowed_actions = [ |
|
13
|
|
|
'ProductWishListForm', |
|
14
|
|
|
'update', |
|
15
|
|
|
]; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @param null $wishList |
|
19
|
|
|
* |
|
20
|
|
|
* @return Form |
|
21
|
|
|
*/ |
|
22
|
1 |
|
public function ProductWishListForm($wishList = null) |
|
23
|
|
|
{ |
|
24
|
1 |
|
$wishList = ($wishList !== null && $wishList instanceof ProductWishList && $wishList->exists()) ? $wishList : Injector::inst()->get('ProductWishList'); |
|
25
|
|
|
|
|
26
|
1 |
|
$fields = $wishList->getFrontEndFields(); |
|
27
|
|
|
|
|
28
|
1 |
|
if ($wishList->getIsEditing()) { |
|
29
|
|
|
$fields->push(HiddenField::create('ID')->setValue($wishList->ID)); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
$actions = $wishList->getFrontEndActions(); |
|
33
|
|
|
|
|
34
|
1 |
|
$required = $wishList->getFrontEndRequiredFields(); |
|
35
|
|
|
|
|
36
|
1 |
|
$controller = $this->getController(); |
|
37
|
|
|
|
|
38
|
1 |
|
$form = Form::create($controller, 'ProductWishListForm', $fields, $actions, $required); |
|
39
|
|
|
|
|
40
|
1 |
|
$form->loadDataFrom($wishList); |
|
41
|
|
|
|
|
42
|
1 |
|
$this->owner->extend('updateProductWishListForm', $form); |
|
43
|
|
|
|
|
44
|
1 |
|
return $form; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return Object |
|
49
|
|
|
*/ |
|
50
|
1 |
|
protected function getController(){ |
|
51
|
1 |
|
return ($this->owner->hasMethod('getCurrentPage')) |
|
52
|
1 |
|
? $this->owner->getCurrentPage() |
|
53
|
1 |
|
: $this->owner; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param $data |
|
58
|
|
|
* @param Form $form |
|
59
|
|
|
*/ |
|
60
|
|
|
public function doProcessWishList($data, Form $form) |
|
61
|
|
|
{ |
|
62
|
|
|
$wishList = (isset($data['ID'])) ? ProductWishList::get()->byID($data['ID']) : ProductWishList::create(); |
|
63
|
|
|
$form->saveInto($wishList); |
|
64
|
|
|
if($wishList->write()){ |
|
65
|
|
|
return $this->getController()->redirect($this->getController()->Link($wishList->getUpdateLink())); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
return $this->getController()->redirect($this->getController()->Link('error')); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function update(SS_HTTPRequest $request = null) |
|
71
|
|
|
{ |
|
72
|
|
|
if ($request === null) { |
|
73
|
|
|
$request = Controller::curr()->getRequest(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$wishList = ProductWishList::get()->byID($request->param('ID')); |
|
77
|
|
|
|
|
78
|
|
|
return $this->owner->customise([ |
|
79
|
|
|
'ProductWishListForm' => $this->ProductWishListForm($wishList), |
|
|
|
|
|
|
80
|
|
|
]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
} |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.