1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverCommerce\CatalogueAdmin\BulkManager; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Control\HTTPResponse; |
6
|
|
|
use SilverStripe\Control\HTTPRequest; |
7
|
|
|
use SilverStripe\Core\Convert; |
8
|
|
|
use Colymba\BulkManager\BulkAction\Handler as GridFieldBulkActionHandler; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* A {@link GridFieldBulkActionHandler} for bulk cancelling records |
12
|
|
|
* |
13
|
|
|
* @author i-lateral (http://www.i-lateral.com) |
14
|
|
|
* @package orders-admin |
15
|
|
|
*/ |
16
|
|
|
class CancelHandler extends GridFieldBulkActionHandler |
17
|
|
|
{ |
18
|
|
|
private static $url_segment = 'cancel'; |
|
|
|
|
19
|
|
|
|
20
|
|
|
private static $allowed_actions = [ |
|
|
|
|
21
|
|
|
'cancel' |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
private static $url_handlers = [ |
|
|
|
|
25
|
|
|
"" => "cancel" |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Front-end label for this handler's action |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $label = 'Cancel'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Front-end icon path for this handler's action. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $icon = ''; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Whether this handler should be called via an XHR from the front-end |
44
|
|
|
* |
45
|
|
|
* @var boolean |
46
|
|
|
*/ |
47
|
|
|
protected $xhr = true; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Set to true is this handler will destroy any data. |
51
|
|
|
* A warning and confirmation will be shown on the front-end. |
52
|
|
|
* |
53
|
|
|
* @var boolean |
54
|
|
|
*/ |
55
|
|
|
protected $destructive = false; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Return i18n localized front-end label |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
public function getI18nLabel() |
63
|
|
|
{ |
64
|
|
|
return _t('OrdersAdmin.Cancel', $this->getLabel()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function cancel(HTTPRequest $request) |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
$ids = []; |
70
|
|
|
|
71
|
|
|
foreach ($this->getRecords() as $record) { |
72
|
|
|
array_push($ids, $record->ID); |
73
|
|
|
$record->markCanceled(); |
74
|
|
|
$record->write(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$response = new HTTPResponse(Convert::raw2json([ |
78
|
|
|
'done' => true, |
79
|
|
|
'records' => $ids |
80
|
|
|
])); |
81
|
|
|
|
82
|
|
|
$response->addHeader('Content-Type', 'text/json'); |
83
|
|
|
|
84
|
|
|
return $response; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|