-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathAbstractCartRESTController.php
66 lines (56 loc) · 1.96 KB
/
AbstractCartRESTController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
require_once dirname(__FILE__) . '/../classes/RESTTrait.php';
abstract class AbstractCartRESTController extends CartControllerCore {
use RESTTrait;
public function init()
{
header('Content-Type: ' . "application/json");
if (Tools::getValue('iso_currency')){
$_GET['id_currency'] = (string)Currency::getIdByIsoCode(Tools::getValue('currency'));
$_GET['SubmitCurrency'] = "1";
}
parent::init();
$response = [
'success' => true,
'code' => 210,
'psdata' => null,
'message' => 'empty'
];
switch ($_SERVER['REQUEST_METHOD']) {
case 'GET':
$response = $this->processGetRequest();
break;
case 'POST':
$response = $this->processPostRequest();
break;
case 'PATCH':
case 'PUT':
$response = $this->processPutRequest();
break;
case 'DELETE':
$response = $this->processDeleteRequest();
break;
default:
// throw some error or whatever
}
$this->ajaxRender(json_encode($response));
die;
}
protected function checkCartProductsMinimalQuantities()
{
$productList = $this->context->cart->getProducts();
foreach ($productList as $product) {
if ($product['minimal_quantity'] > $product['cart_quantity']) {
// display minimal quantity warning error message
$this->errors[] = $this->trans(
'The minimum purchase order quantity for the product %product% is %quantity%.',
[
'%product%' => $product['name'],
'%quantity%' => $product['minimal_quantity'],
],
'Shop.Notifications.Error'
);
}
}
}
}