Skip to content

Commit 1393050

Browse files
committed
Merge branch 'develop'
2 parents c059611 + 64c7eb9 commit 1393050

40 files changed

+116
-1008
lines changed

binshopsrest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public function __construct()
4343
$this->module_key = 'b3c3c0c41d0223b9ff10c87b8acb65f5';
4444
}
4545

46+
public function isUsingNewTranslationSystem()
47+
{
48+
return true;
49+
}
50+
4651
/**
4752
* Don't forget to create update methods if needed:
4853
* http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update

classes/APIRoutes.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,6 @@ public static final function getRoutes(): array
113113
'module' => 'binshopsrest'
114114
]
115115
],
116-
'module-binshopsrest-checkout' => [
117-
'rule' => 'rest/checkout',
118-
'keywords' => [],
119-
'controller' => 'checkout',
120-
'params' => [
121-
'fc' => 'module',
122-
'module' => 'binshopsrest'
123-
]
124-
],
125116
'module-binshopsrest-featuredproducts' => [
126117
'rule' => 'rest/featuredproducts',
127118
'keywords' => [],

classes/RESTTrait.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
trait RESTTrait
4+
{
5+
protected function processGetRequest(){
6+
$this->ajaxRender(json_encode([
7+
'success' => true,
8+
'message' => $this->trans('GET not supported on this path', [], 'Modules.Binshopsrest.Admin')
9+
]));
10+
die;
11+
}
12+
13+
protected function processPostRequest(){
14+
$this->ajaxRender(json_encode([
15+
'success' => true,
16+
'message' => $this->trans('POST not supported on this path', [], 'Modules.Binshopsrest.Admin')
17+
]));
18+
die;
19+
}
20+
21+
protected function processPutRequest(){
22+
$this->ajaxRender(json_encode([
23+
'success' => true,
24+
'message' => $this->trans('PUT not supported on this path', [], 'Modules.Binshopsrest.Admin')
25+
]));
26+
die;
27+
}
28+
29+
protected function processDeleteRequest(){
30+
$this->ajaxRender(json_encode([
31+
'success' => true,
32+
'message' => $this->trans('DELETE not supported on this path', [], 'Modules.Binshopsrest.Admin')
33+
]));
34+
die;
35+
}
36+
}

controllers/AbstractAuthRESTController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
require_once dirname(__FILE__) . '/AbstractRESTController.php';
1313

1414
/**
15-
* Any REST request which needs authentication must extend this class
15+
* Protected REST endpoints should extend this class
1616
*/
1717
abstract class AbstractAuthRESTController extends AbstractRESTController
1818
{
@@ -26,7 +26,7 @@ public function init()
2626
$this->ajaxRender(json_encode([
2727
'code' => 410,
2828
'success' => false,
29-
'message' => 'User not authenticated'
29+
'message' => $this->trans('User Not Authenticated', [], 'Modules.Binshopsrest.Admin')
3030
]));
3131
die;
3232
}

controllers/AbstractCartRESTController.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22

3+
require_once dirname(__FILE__) . '/../classes/RESTTrait.php';
4+
35
abstract class AbstractCartRESTController extends CartControllerCore {
6+
use RESTTrait;
7+
48
public function init()
59
{
610
header('Content-Type: ' . "application/json");
@@ -24,14 +28,6 @@ public function init()
2428
}
2529
}
2630

27-
abstract protected function processGetRequest();
28-
29-
abstract protected function processPostRequest();
30-
31-
abstract protected function processPutRequest();
32-
33-
abstract protected function processDeleteRequest();
34-
3531
protected function checkCartProductsMinimalQuantities()
3632
{
3733
$productList = $this->context->cart->getProducts();

controllers/AbstractPaymentRESTController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use PrestaShop\PrestaShop\Adapter\Presenter\Order\OrderPresenter;
1111

1212
/**
13-
* Payment Controllers which process payments must extend this class
13+
* REST Payment Controllers should extend this class for payment processing
1414
*/
1515
abstract class AbstractPaymentRESTController extends ModuleFrontController
1616
{
@@ -24,7 +24,7 @@ public function init()
2424
$this->ajaxRender(json_encode([
2525
'code' => 410,
2626
'success' => false,
27-
'message' => 'User not authenticated'
27+
'message' => $this->trans('User Not Authenticated', [], 'Modules.Binshopsrest.Admin')
2828
]));
2929
die;
3030
}
@@ -58,7 +58,7 @@ protected final function processGetRequest(){
5858
$this->ajaxRender(json_encode([
5959
'success' => false,
6060
'code' => 301,
61-
'message' => 'payment processing failed'
61+
'message' => $this->trans('Payment processing failed', [], 'Modules.Binshopsrest.Payment')
6262
]));
6363
die;
6464
}

controllers/AbstractProductListingRESTController.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*
1010
*/
1111

12+
require_once dirname(__FILE__) . '/../classes/RESTTrait.php';
13+
1214
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
1315
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
1416
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
@@ -20,6 +22,8 @@
2022
*/
2123
abstract class AbstractProductListingRESTController extends ProductListingFrontController
2224
{
25+
use RESTTrait;
26+
2327
protected $category;
2428

2529
public function init()
@@ -45,14 +49,6 @@ public function init()
4549
}
4650
}
4751

48-
abstract protected function processGetRequest();
49-
50-
abstract protected function processPostRequest();
51-
52-
abstract protected function processPutRequest();
53-
54-
abstract protected function processDeleteRequest();
55-
5652
protected function getImage($object, $id_image)
5753
{
5854
$retriever = new ImageRetriever(

controllers/AbstractRESTController.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
*
1010
*/
1111

12+
require_once dirname(__FILE__) . '/../classes/RESTTrait.php';
13+
1214
abstract class AbstractRESTController extends ModuleFrontController
1315
{
16+
use RESTTrait;
17+
1418
private $img1 = 'large';
1519
private $img2 = 'medium';
1620
private $img3 = '_default';
@@ -38,14 +42,6 @@ public function init()
3842
}
3943
}
4044

41-
abstract protected function processGetRequest();
42-
43-
abstract protected function processPostRequest();
44-
45-
abstract protected function processPutRequest();
46-
47-
abstract protected function processDeleteRequest();
48-
4945
public function formatPrice($price)
5046
{
5147
return Tools::displayPrice(

controllers/front/accountedit.php

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,6 @@
1313

1414
class BinshopsrestAccounteditModuleFrontController extends AbstractRESTController
1515
{
16-
17-
protected function processGetRequest()
18-
{
19-
$this->ajaxRender(json_encode([
20-
'success' => true,
21-
'message' => 'GET not supported on this path'
22-
]));
23-
die;
24-
}
25-
2616
protected function processPostRequest()
2717
{
2818
$_POST = json_decode(Tools::file_get_contents('php://input'), true);
@@ -43,7 +33,7 @@ protected function processPostRequest()
4333
'success' => false,
4434
'code' => 310,
4535
'psdata' => null,
46-
'message' => 'The email is already used, please choose another one or sign in'
36+
'message' => $this->trans('The email is already used, please choose another one or sign in', [], 'Modules.Binshopsrest.Account')
4737
]));
4838
die;
4939
}
@@ -131,7 +121,7 @@ protected function processPostRequest()
131121
$message = 'User updated successfully';
132122
$psdata = array(
133123
'registered' => $status,
134-
'message' => 'User updated successfully',
124+
'message' => $this->trans('User updated successfully', [], 'Modules.Binshopsrest.Account'),
135125
'customer_id' => $customer->id,
136126
'session_data' => (int)$this->context->cart->id
137127
);
@@ -141,7 +131,7 @@ protected function processPostRequest()
141131
$message = 'could not update customer';
142132
$psdata = array(
143133
'registered' => $status,
144-
'message' => 'password incorrect',
134+
'message' => $this->trans('Password Incorrect', [], 'Modules.Binshopsrest.Account'),
145135
'customer_id' => $customer->id,
146136
'session_data' => (int)$this->context->cart->id
147137
);
@@ -161,22 +151,4 @@ protected function processPostRequest()
161151
]));
162152
die;
163153
}
164-
165-
protected function processPutRequest()
166-
{
167-
$this->ajaxRender(json_encode([
168-
'success' => true,
169-
'message' => 'put not supported on this path'
170-
]));
171-
die;
172-
}
173-
174-
protected function processDeleteRequest()
175-
{
176-
$this->ajaxRender(json_encode([
177-
'success' => true,
178-
'message' => 'delete not supported on this path'
179-
]));
180-
die;
181-
}
182154
}

controllers/front/accountinfo.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,4 @@ protected function processGetRequest()
2929
]));
3030
die;
3131
}
32-
33-
protected function processPostRequest()
34-
{
35-
$this->ajaxRender(json_encode([
36-
'success' => true,
37-
'message' => 'POST not supported on this path'
38-
]));
39-
die;
40-
}
41-
42-
protected function processPutRequest()
43-
{
44-
$this->ajaxRender(json_encode([
45-
'success' => true,
46-
'message' => 'put not supported on this path'
47-
]));
48-
die;
49-
}
50-
51-
protected function processDeleteRequest()
52-
{
53-
$this->ajaxRender(json_encode([
54-
'success' => true,
55-
'message' => 'delete not supported on this path'
56-
]));
57-
die;
58-
}
5932
}

controllers/front/address.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,6 @@ protected function processPostRequest()
143143
die;
144144
}
145145

146-
protected function processPutRequest()
147-
{
148-
$this->ajaxRender(json_encode([
149-
'success' => true,
150-
'message' => 'put not supported on this path'
151-
]));
152-
die;
153-
}
154-
155146
protected function processDeleteRequest()
156147
{
157148
$_POST = json_decode(Tools::file_get_contents('php://input'), true);
@@ -166,7 +157,7 @@ protected function processDeleteRequest()
166157
$this->ajaxRender(json_encode([
167158
'success' => true,
168159
'code' => 301,
169-
'message' => "There is not such address"
160+
'message' => $this->trans("Address is not available", [], 'Modules.Binshopsrest.Address')
170161
]));
171162
die;
172163
}
@@ -189,15 +180,15 @@ protected function processDeleteRequest()
189180
$this->ajaxRender(json_encode([
190181
'success' => true,
191182
'code' => 202,
192-
'message' => "Address was already deleted"
183+
'message' => $this->trans("Address was already deleted", [], 'Modules.Binshopsrest.Address')
193184
]));
194185
die;
195186
}
196187
} else {
197188
$this->ajaxRender(json_encode([
198189
'success' => true,
199190
'code' => 301,
200-
'message' => "There is not such address"
191+
'message' => $this->trans("Address is not available", [], 'Modules.Binshopsrest.Address')
201192
]));
202193
die;
203194
}
@@ -206,7 +197,7 @@ protected function processDeleteRequest()
206197
'success' => true,
207198
'code' => 200,
208199
'psdata' => $saved,
209-
'message' => "Address successfully deleted"
200+
'message' => $this->trans("Address successfully deleted", [], 'Modules.Binshopsrest.Address')
210201
]));
211202
die;
212203
}

controllers/front/addressform.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
class BinshopsrestAddressformModuleFrontController extends AbstractRESTController
1515
{
16-
1716
protected function processGetRequest()
1817
{
1918
if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) {
@@ -32,31 +31,4 @@ protected function processGetRequest()
3231
]));
3332
die;
3433
}
35-
36-
protected function processPostRequest()
37-
{
38-
$this->ajaxRender(json_encode([
39-
'success' => true,
40-
'message' => 'POST not supported on this path'
41-
]));
42-
die;
43-
}
44-
45-
protected function processPutRequest()
46-
{
47-
$this->ajaxRender(json_encode([
48-
'success' => true,
49-
'message' => 'put not supported on this path'
50-
]));
51-
die;
52-
}
53-
54-
protected function processDeleteRequest()
55-
{
56-
$this->ajaxRender(json_encode([
57-
'success' => true,
58-
'message' => 'delete not supported on this path'
59-
]));
60-
die;
61-
}
6234
}

0 commit comments

Comments
 (0)