1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AntonyThorpe\SilverShopJsonResponse; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Core\Extension; |
6
|
|
|
use SilverStripe\Control\HTTPRequest; |
7
|
|
|
use SilverShop\Cart\ShoppingCart; |
8
|
|
|
use SilverShop\Page\Product; |
9
|
|
|
use SilverShop\Extension\ProductImageExtension; |
10
|
|
|
use SilverShop\Extension\ProductVariationsExtension; |
11
|
|
|
use SilverShop\Model\Variation\Variation; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* ShopJsonResponse |
15
|
|
|
* |
16
|
|
|
* Json Response for shopping cart of Silverstripe Shop |
17
|
|
|
* @package shop |
18
|
|
|
*/ |
19
|
|
|
class SilvershopJsonResponse extends Extension |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Allow get action to obtain a copy of the shopping cart |
23
|
|
|
*/ |
24
|
|
|
private static $allowed_actions = array( |
|
|
|
|
25
|
|
|
'get' |
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* get the shopping cart |
30
|
|
|
* |
31
|
|
|
* @param SS_HTTPRequest $request |
|
|
|
|
32
|
|
|
* @return SS_HTTPResponse $response with JSON body |
|
|
|
|
33
|
|
|
*/ |
34
|
|
|
public function get(HTTPRequest $request) |
35
|
|
|
{ |
36
|
|
|
if (!$request->isAjax()) { |
37
|
|
|
return $this->owner->httpError(404, _t(ShoppingCart::class . 'GetCartAjaxOnly', 'Ajax request only Bo')); |
38
|
|
|
} |
39
|
|
|
$response = $this->owner->getResponse(); |
40
|
|
|
$response->removeHeader('Content-Type'); |
41
|
|
|
$response->addHeader('Content-Type', 'application/json; charset=utf-8'); |
42
|
|
|
|
43
|
|
|
$data = $this->getCurrentShoppingCart(); |
44
|
|
|
|
45
|
|
|
$this->owner->extend('updateGet', $data, $request, $response); |
46
|
|
|
return $response->setBody(json_encode($data)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Add one of an item to a cart (Category Page) |
51
|
|
|
* |
52
|
|
|
* @see 'add' function of ShoppingCart_Controller ($this->owner) |
53
|
|
|
* @param SS_HTTPRequest $request |
54
|
|
|
* @param AjaxHTTPResponse $response |
|
|
|
|
55
|
|
|
* @param Buyable $product [optional] |
|
|
|
|
56
|
|
|
* @param int $quantity [optional] |
57
|
|
|
*/ |
58
|
|
|
public function updateAddResponse(&$request, &$response, $product = null, $quantity = 1) |
59
|
|
|
{ |
60
|
|
|
if ($request->isAjax()) { |
61
|
|
|
if (!$response) { |
|
|
|
|
62
|
|
|
$response = $this->owner->getResponse(); |
63
|
|
|
} |
64
|
|
|
$response->removeHeader('Content-Type'); |
65
|
|
|
$response->addHeader('Content-Type', 'application/json; charset=utf-8'); |
66
|
|
|
$shoppingcart = ShoppingCart::curr(); |
67
|
|
|
$shoppingcart->calculate(); // recalculate the shopping cart |
68
|
|
|
|
69
|
|
|
$data = array( |
70
|
|
|
'id' => (string) $product->ID, |
71
|
|
|
'internalItemID' => $product->InternalItemID, |
72
|
|
|
'title' => $product->getTitle(), |
|
|
|
|
73
|
|
|
'url' => $product->URLSegment, |
74
|
|
|
'categories' => $product->getCategories()->column('Title'), |
75
|
|
|
'message' => array( |
76
|
|
|
'content' => $this->owner->cart->getMessage(), |
77
|
|
|
'type' => $this->owner->cart->getMessageType(), |
78
|
|
|
), |
79
|
|
|
); |
80
|
|
|
$this->owner->cart->clearMessage(); |
81
|
|
|
|
82
|
|
|
// add separately as these are absent with variations |
83
|
|
|
if (method_exists($product, "getPrice")) { |
84
|
|
|
$data['unitPrice'] = $product->getPrice(); |
85
|
|
|
} |
86
|
|
|
if (method_exists($product, "addLink")) { |
87
|
|
|
$data['addLink'] = $product->addLink(); |
88
|
|
|
} |
89
|
|
|
if (method_exists($product, "removeLink")) { |
90
|
|
|
$data['removeLink'] = $product->removeLink(); |
91
|
|
|
} |
92
|
|
|
if (method_exists($product, "removeallLink")) { |
93
|
|
|
$data['removeallLink'] = $product->removeallLink(); |
94
|
|
|
} |
95
|
|
|
if (method_exists($product->Item(), "setquantityLink")) { |
96
|
|
|
$data['setquantityLink'] = $product->Item()->setquantityLink(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if ($shoppingcart) { |
|
|
|
|
100
|
|
|
$data['subTotal'] = $shoppingcart->SubTotal(); |
101
|
|
|
$data['grandTotal'] = $shoppingcart->GrandTotal(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
if ($modifiers = $this->getCurrentShoppingCartModifiers()) { |
105
|
|
|
$data['modifiers'] = $modifiers; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
$this->owner->extend('updateAddResponseShopJsonResponse', $data, $request, $response, $product, $quantity); |
109
|
|
|
$response->setBody(json_encode($data)); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Remove one of an item from a cart (Cart Page) |
115
|
|
|
* |
116
|
|
|
* @see 'remove' function of ShoppingCart_Controller ($this->owner) |
117
|
|
|
* @param SS_HTTPRequest $request |
118
|
|
|
* @param AjaxHTTPResponse $response |
119
|
|
|
* @param Buyable $product [optional] |
120
|
|
|
* @param int $quantity [optional] |
121
|
|
|
*/ |
122
|
|
|
public function updateRemoveResponse(&$request, &$response, $product = null, $quantity = 1) |
123
|
|
|
{ |
124
|
|
|
if ($request->isAjax()) { |
125
|
|
|
if (!$response) { |
|
|
|
|
126
|
|
|
$response = $this->owner->getResponse(); |
127
|
|
|
} |
128
|
|
|
$response->removeHeader('Content-Type'); |
129
|
|
|
$response->addHeader('Content-Type', 'application/json; charset=utf-8'); |
130
|
|
|
$shoppingcart = ShoppingCart::curr(); |
131
|
|
|
$shoppingcart->calculate(); // recalculate the shopping cart |
132
|
|
|
|
133
|
|
|
$data = array( |
134
|
|
|
'id' => (string) $product->ID, |
135
|
|
|
'message' => array( |
136
|
|
|
'content' => $this->owner->cart->getMessage(), |
137
|
|
|
'type' => $this->owner->cart->getMessageType(), |
138
|
|
|
), |
139
|
|
|
); |
140
|
|
|
$this->owner->cart->clearMessage(); |
141
|
|
|
|
142
|
|
|
if ($shoppingcart) { |
|
|
|
|
143
|
|
|
$data['subTotal'] = $shoppingcart->SubTotal(); |
144
|
|
|
$data['grandTotal'] = $shoppingcart->GrandTotal(); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
if ($modifiers = $this->getCurrentShoppingCartModifiers()) { |
148
|
|
|
$data['modifiers'] = $modifiers; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
$this->owner->extend('updateRemoveResponseShopJsonResponse', $data, $request, $response, $product, $quantity); |
152
|
|
|
$response->setBody(json_encode($data)); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Remove all of an item from a cart (Cart Page) |
158
|
|
|
* Quantity is NIL |
159
|
|
|
* |
160
|
|
|
* @see 'removeall' function of ShoppingCart_Controller ($this->owner) |
161
|
|
|
* @param SS_HTTPRequest $request |
162
|
|
|
* @param AjaxHTTPResponse $response |
163
|
|
|
* @param Buyable $product [optional] |
164
|
|
|
*/ |
165
|
|
|
public function updateRemoveAllResponse(&$request, &$response, $product = null) |
166
|
|
|
{ |
167
|
|
|
if ($request->isAjax()) { |
168
|
|
|
if (!$response) { |
|
|
|
|
169
|
|
|
$response = $this->owner->getResponse(); |
170
|
|
|
} |
171
|
|
|
$response->removeHeader('Content-Type'); |
172
|
|
|
$response->addHeader('Content-Type', 'application/json; charset=utf-8'); |
173
|
|
|
$shoppingcart = ShoppingCart::curr(); |
174
|
|
|
$shoppingcart->calculate(); // recalculate the shopping cart |
175
|
|
|
|
176
|
|
|
$data = array( |
177
|
|
|
'id' => (string) $product->ID, |
178
|
|
|
'message' => array( |
179
|
|
|
'content' => $this->owner->cart->getMessage(), |
180
|
|
|
'type' => $this->owner->cart->getMessageType(), |
181
|
|
|
), |
182
|
|
|
); |
183
|
|
|
$this->owner->cart->clearMessage(); |
184
|
|
|
|
185
|
|
|
if ($shoppingcart) { |
|
|
|
|
186
|
|
|
$data['subTotal'] = $shoppingcart->SubTotal(); |
187
|
|
|
$data['grandTotal'] = $shoppingcart->GrandTotal(); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
if ($modifiers = $this->getCurrentShoppingCartModifiers()) { |
191
|
|
|
$data['modifiers'] = $modifiers; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
$this->owner->extend('updateRemoveAllResponseShopJsonResponse', $data, $request, $response, $product); |
195
|
|
|
$response->setBody(json_encode($data)); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* Update the quantity of an item in a cart (Cart Page) |
201
|
|
|
* |
202
|
|
|
* @see 'setquantity' function of ShoppingCart_Controller ($this->owner) |
203
|
|
|
* @param SS_HTTPRequest $request |
204
|
|
|
* @param AjaxHTTPResponse $response |
205
|
|
|
* @param Buyable $product [optional] |
206
|
|
|
* @param int $quantity [optional] |
207
|
|
|
*/ |
208
|
|
|
public function updateSetQuantityResponse(&$request, &$response, $product = null, $quantity = 1) |
|
|
|
|
209
|
|
|
{ |
210
|
|
|
if ($request->isAjax()) { |
211
|
|
|
if (!$response) { |
|
|
|
|
212
|
|
|
$response = $this->owner->getResponse(); |
213
|
|
|
} |
214
|
|
|
$response->removeHeader('Content-Type'); |
215
|
|
|
$response->addHeader('Content-Type', 'application/json; charset=utf-8'); |
216
|
|
|
$shoppingcart = ShoppingCart::curr(); |
217
|
|
|
$shoppingcart->calculate(); // recalculate the shopping cart |
218
|
|
|
|
219
|
|
|
$currentquantity = (int) $product->Item()->Quantity; // quantity of the order item left now in the cart |
220
|
|
|
|
221
|
|
|
$data = array( |
222
|
|
|
'id' => (string) $product->ID, |
223
|
|
|
'quantity' => $currentquantity, |
224
|
|
|
'message' => array( |
225
|
|
|
'content' => $this->owner->cart->getMessage(), |
226
|
|
|
'type' => $this->owner->cart->getMessageType(), |
227
|
|
|
), |
228
|
|
|
); |
229
|
|
|
$this->owner->cart->clearMessage(); |
230
|
|
|
|
231
|
|
|
// include totals if required |
232
|
|
|
if ($shoppingcart) { |
|
|
|
|
233
|
|
|
$data['subTotal'] = $shoppingcart->SubTotal(); |
234
|
|
|
$data['grandTotal'] = $shoppingcart->GrandTotal(); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
if ($modifiers = $this->getCurrentShoppingCartModifiers()) { |
238
|
|
|
$data['modifiers'] = $modifiers; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
$this->owner->extend('updateSetQuantityResponseShopJsonResponse', $data, $request, $response, $product, $currentquantity); |
242
|
|
|
$response->setBody(json_encode($data)); |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Clear all items from the cart (Cart Page) |
248
|
|
|
* |
249
|
|
|
* @see 'clear' function of ShoppingCart_Controller ($this->owner) |
250
|
|
|
* @param SS_HTTPRequest $request |
251
|
|
|
* @param AjaxHTTPResponse $response |
252
|
|
|
*/ |
253
|
|
|
public function updateClearResponse(&$request, &$response) |
254
|
|
|
{ |
255
|
|
|
if ($request->isAjax()) { |
256
|
|
|
if (!$response) { |
|
|
|
|
257
|
|
|
$response = $this->owner->getResponse(); |
258
|
|
|
} |
259
|
|
|
$response->removeHeader('Content-Type'); |
260
|
|
|
$response->addHeader('Content-Type', 'application/json; charset=utf-8'); |
261
|
|
|
|
262
|
|
|
$data = array( |
263
|
|
|
'message' => array( |
264
|
|
|
'content' => $this->owner->cart->getMessage(), |
265
|
|
|
'type' => $this->owner->cart->getMessageType(), |
266
|
|
|
), |
267
|
|
|
); |
268
|
|
|
$this->owner->cart->clearMessage(); |
269
|
|
|
|
270
|
|
|
$this->owner->extend('updateClearResponseShopJsonResponse', $data, $request, $response); |
271
|
|
|
$response->setBody(json_encode($data)); |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Update the variations of a product (Cart Page) |
277
|
|
|
* |
278
|
|
|
* @see 'addtocart' function of VariationForm ($this->owner) |
279
|
|
|
* @param SS_HTTPRequest $request |
280
|
|
|
* @param AjaxHTTPResponse $response |
281
|
|
|
* @param Buyable $variation [optional] |
282
|
|
|
* @param int $quantity [optional] |
283
|
|
|
* @param VariationForm $form [optional] |
|
|
|
|
284
|
|
|
*/ |
285
|
|
|
public function updateVariationFormResponse(&$request, &$response, $variation = null, $quantity = 1, $form = null) |
286
|
|
|
{ |
287
|
|
|
if ($request->isAjax()) { |
288
|
|
|
if (!$response) { |
|
|
|
|
289
|
|
|
$response = $this->owner->getResponse(); |
290
|
|
|
} |
291
|
|
|
$response->removeHeader('Content-Type'); |
292
|
|
|
$response->addHeader('Content-Type', 'application/json; charset=utf-8'); |
293
|
|
|
$shoppingcart = ShoppingCart::curr(); |
294
|
|
|
$shoppingcart->calculate(); // recalculate the shopping cart |
295
|
|
|
|
296
|
|
|
$data = array( |
297
|
|
|
'id' => (string) $variation->ID, |
298
|
|
|
'message' => array( |
299
|
|
|
'content' => $form->getMessage(), |
|
|
|
|
300
|
|
|
'type' => $form->getMessageType(), |
301
|
|
|
), |
302
|
|
|
); |
303
|
|
|
$form->clearMessage(); |
304
|
|
|
|
305
|
|
|
// include totals if required |
306
|
|
|
if ($shoppingcart) { |
|
|
|
|
307
|
|
|
$data['subTotal'] = $shoppingcart->SubTotal(); |
308
|
|
|
$data['grandTotal'] = $shoppingcart->GrandTotal(); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
if ($modifiers = $this->getCurrentShoppingCartModifiers()) { |
312
|
|
|
$data['modifiers'] = $modifiers; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
$this->owner->extend('updateVariationFormResponseShopJsonResponse', $data, $request, $response, $variation, $quantity, $form); |
316
|
|
|
$response->setBody(json_encode($data)); |
317
|
|
|
} |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Add one of an item to a cart (Product Page) |
322
|
|
|
* |
323
|
|
|
* @see the addtocart function within AddProductForm class |
324
|
|
|
* @param SS_HTTPRequest $request |
325
|
|
|
* @param AjaxHTTPResponse $response |
326
|
|
|
* @param Buyable $buyable [optional] |
327
|
|
|
* @param int $quantity [optional] |
328
|
|
|
* @param AddProductForm $form [optional] |
|
|
|
|
329
|
|
|
*/ |
330
|
|
|
public function updateAddProductFormResponse(&$request, &$response, $buyable, $quantity, $form) |
331
|
|
|
{ |
332
|
|
|
if ($request->isAjax()) { |
333
|
|
|
if (!$response) { |
|
|
|
|
334
|
|
|
$response = $this->owner->getController()->getResponse(); |
335
|
|
|
} |
336
|
|
|
$response->removeHeader('Content-Type'); |
337
|
|
|
$response->addHeader('Content-Type', 'application/json; charset=utf-8'); |
338
|
|
|
$shoppingcart = ShoppingCart::curr(); |
339
|
|
|
$shoppingcart->calculate(); // recalculate the shopping cart |
340
|
|
|
|
341
|
|
|
$data = array( |
342
|
|
|
'id' => (string) $buyable->ID, |
343
|
|
|
'internalItemID' => $buyable->InternalItemID, |
344
|
|
|
'title' => $buyable->getTitle(), |
345
|
|
|
'url' => $buyable->URLSegment, |
346
|
|
|
'categories' => $buyable->getCategories()->column('Title'), |
347
|
|
|
'addLink' => $buyable->addLink(), |
348
|
|
|
'removeLink' => $buyable->removeLink(), |
349
|
|
|
'removeallLink' => $buyable->removeallLink(), |
350
|
|
|
'setquantityLink' => $buyable->Item()->setquantityLink(), |
351
|
|
|
'message' => array( |
352
|
|
|
'content' => $form->getMessage(), |
353
|
|
|
'type' => $form->getMessageType(), |
354
|
|
|
), |
355
|
|
|
); |
356
|
|
|
$form->clearMessage(); |
357
|
|
|
|
358
|
|
|
// include totals if required |
359
|
|
|
if ($shoppingcart) { |
|
|
|
|
360
|
|
|
$data['subTotal'] = $shoppingcart->SubTotal(); |
361
|
|
|
$data['grandTotal'] = $shoppingcart->GrandTotal(); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
if ($modifiers = $this->getCurrentShoppingCartModifiers()) { |
365
|
|
|
$data['modifiers'] = $modifiers; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
$this->owner->extend('updateAddProductFormResponseShopJsonResponse', $data, $request, $response, $buyable, $quantity, $form); |
369
|
|
|
$response->setBody(json_encode($data)); |
370
|
|
|
} |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* Provide a copy of the current order in the required format |
375
|
|
|
* Note the id is the cart's id |
376
|
|
|
* @return array of product id, subTotal, grandTotal, and items & modifiers |
377
|
|
|
*/ |
378
|
|
|
public function getCurrentShoppingCart() |
379
|
|
|
{ |
380
|
|
|
$result = []; |
381
|
|
|
|
382
|
|
|
if ($shoppingcart = ShoppingCart::curr()) { |
383
|
|
|
$result['id'] = (string) $shoppingcart->getReference(); |
384
|
|
|
|
385
|
|
|
if ($items = $this->getCurrentShoppingCartItems()) { |
386
|
|
|
$result['items'] = $items; |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
if ($modifiers = $this->getCurrentShoppingCartModifiers()) { |
390
|
|
|
$result['modifiers'] = $modifiers; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
$result['subTotal'] = $shoppingcart->SubTotal(); |
394
|
|
|
$result['grandTotal'] = $shoppingcart->GrandTotal(); |
395
|
|
|
} |
396
|
|
|
return $result; |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* Provide a copy of the current order's items, including image details and variations |
401
|
|
|
* @todo what about subTitles? i.e the variation choosen (I think) |
402
|
|
|
* @return array |
403
|
|
|
*/ |
404
|
|
|
protected function getCurrentShoppingCartItems() |
405
|
|
|
{ |
406
|
|
|
$result = array(); |
407
|
|
|
$items = ShoppingCart::curr()->Items(); |
408
|
|
|
|
409
|
|
|
if ($items->exists()) { |
410
|
|
|
foreach ($items->getIterator() as $item) { |
411
|
|
|
// Definitions |
412
|
|
|
$data = array(); |
413
|
|
|
$product = $item->Product(); |
414
|
|
|
|
415
|
|
|
$data["id"] = (string) $item->ProductID; |
416
|
|
|
$data["internalItemID"] = $product->InternalItemID; |
417
|
|
|
$data["title"] = $product->getTitle(); |
418
|
|
|
$data["quantity"] = (int) $item->Quantity; |
419
|
|
|
$data["unitPrice"] = $product->getPrice(); |
420
|
|
|
$data["href"] = $item->Link(); |
421
|
|
|
$data['categories'] = $product->getCategories()->column('Title'); |
422
|
|
|
$data["addLink"] = $item->addLink(); |
423
|
|
|
$data["removeLink"] = $item->removeLink(); |
424
|
|
|
$data["removeallLink"] = $item->removeallLink(); |
425
|
|
|
$data["setquantityLink"] = $item->setquantityLink(); |
426
|
|
|
|
427
|
|
|
// Image |
428
|
|
|
if ($item->Image()) { |
429
|
|
|
$image = $item->Image()->ScaleWidth((int) ProductImageExtension::config()->cart_image_width); |
430
|
|
|
$data["image"] = array( |
431
|
|
|
'alt' => $image->getTitle(), |
432
|
|
|
'src' => $image->getAbsoluteURL(), |
433
|
|
|
'width' => $image->getWidth(), |
434
|
|
|
'height' => $image->getHeight(), |
435
|
|
|
); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
// Variations |
439
|
|
|
$extension = Product::has_extension(ProductVariationsExtension::class); |
440
|
|
|
if ($extension && Variation::get()->filter('ProductID', $item->ID)->first()) { |
441
|
|
|
$variations = $product->Variations(); |
442
|
|
|
if ($variations->exists()) { |
443
|
|
|
$data['variations'] = []; |
444
|
|
|
foreach ($variations as $variation) { |
445
|
|
|
$data['variations'][] = array( |
446
|
|
|
'id' => (string) $variation->ID, |
447
|
|
|
'title' => $variation->getTitle(), |
448
|
|
|
); |
449
|
|
|
} |
450
|
|
|
} |
451
|
|
|
} |
452
|
|
|
$result[] = $data; |
453
|
|
|
} |
454
|
|
|
} |
455
|
|
|
return $result; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* Provide a copy of the current order's modifiers |
460
|
|
|
* @todo Only FlatTaxModifier tested |
461
|
|
|
* @return array of modifiers (note: this excludes subtotal and grandtotal) |
462
|
|
|
*/ |
463
|
|
|
protected function getCurrentShoppingCartModifiers() |
464
|
|
|
{ |
465
|
|
|
$result = array(); |
466
|
|
|
$modifiers = ShoppingCart::curr()->Modifiers(); |
467
|
|
|
|
468
|
|
|
if ($modifiers->exists()) { |
469
|
|
|
foreach ($modifiers->sort('Sort')->getIterator() as $modifier) { |
470
|
|
|
if ($modifier->ShowInTable()) { |
471
|
|
|
$data = array( |
472
|
|
|
'id' => (string) $modifier->ID, |
473
|
|
|
'tableTitle' => $modifier->getTableTitle(), |
474
|
|
|
'tableValue' => (float) $modifier->TableValue(), |
475
|
|
|
); |
476
|
|
|
|
477
|
|
|
if (method_exists($modifier, 'Link')) { |
478
|
|
|
// add if there is a link |
479
|
|
|
$data["href"] = $modifier->Link(); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
if (method_exists($modifier, 'removeLink')) { |
483
|
|
|
// add if there is a canRemove method |
484
|
|
|
$data["removeLink"] = $modifier->removeLink(); |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
$result[] = $data; |
488
|
|
|
} |
489
|
|
|
} |
490
|
|
|
} |
491
|
|
|
$this->owner->extend('updateGetCurrentShoppingCartModifiers', $result); |
492
|
|
|
return $result; |
493
|
|
|
} |
494
|
|
|
} |
495
|
|
|
|