Skip to content

Commit 0de6b1d

Browse files
committed
adds light bootstrap api
1 parent a78f887 commit 0de6b1d

File tree

3 files changed

+111
-2
lines changed

3 files changed

+111
-2
lines changed

Readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ You can access full documentation for REST endpoints on Postman publisher:
1515
https://documenter.getpostman.com/view/1491681/TzkyP1UC
1616

1717
### Change Log
18-
- #### 2.2.1 some response cleaning - ability to load menu item images
19-
- #### 2.2.0 improves bootstrap api - adds id and slug to menu items
18+
- #### 2.2.2. adds light bootstrap endpoint
19+
- 2.2.1 some response cleaning - ability to load menu item images
20+
- 2.2.0 improves bootstrap api - adds id and slug to menu items

binshopsrest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ public function hookModuleRoutes()
265265
'module' => 'binshopsrest'
266266
]
267267
],
268+
'module-binshopsrest-lightbootstrap' => [
269+
'rule' => 'rest/lightbootstrap',
270+
'keywords' => [],
271+
'controller' => 'lightbootstrap',
272+
'params' => [
273+
'fc' => 'module',
274+
'module' => 'binshopsrest'
275+
]
276+
],
268277
'module-binshopsrest-cartitems' => [
269278
'rule' => 'rest/cartitems',
270279
'keywords' => [],

controllers/front/lightbootstrap.php

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* BINSHOPS | Best In Shops
4+
*
5+
* @author BINSHOPS | Best In Shops
6+
* @copyright BINSHOPS | Best In Shops
7+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
8+
* Best In Shops eCommerce Solutions Inc.
9+
*
10+
*/
11+
12+
require_once dirname(__FILE__) . '/../AbstractRESTController.php';
13+
require_once dirname(__FILE__) . '/../../classes/RESTMainMenu.php';
14+
require_once dirname(__FILE__) . '/../../classes/RESTProductLazyArray.php';
15+
16+
use PrestaShop\PrestaShop\Adapter\Category\CategoryProductSearchProvider;
17+
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchContext;
18+
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
19+
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
20+
21+
/**
22+
* Description: This class bootstraps the main page of the application
23+
* */
24+
25+
class BinshopsrestLightbootstrapModuleFrontController extends AbstractRESTController
26+
{
27+
protected $banner;
28+
29+
protected function processGetRequest()
30+
{
31+
$messageCode = 200;
32+
$mainMenu = Module::getInstanceByName('ps_mainmenu');
33+
34+
$restMenu = new RESTMainMenu();
35+
36+
$menuItems = $restMenu->renderMenu($this->context, $mainMenu);
37+
38+
if (Tools::getValue('menu_with_images', false)){
39+
foreach ($menuItems as $key => $item) {
40+
$retriever = new \PrestaShop\PrestaShop\Adapter\Image\ImageRetriever(
41+
$this->context->link
42+
);
43+
$category = new Category(
44+
Tools::substr($item['page_identifier'], -1),
45+
$this->context->language->id
46+
);
47+
if (Tools::getValue('menu_with_images', 'all') === "single"){
48+
$menuItems[$key]['image']['src'] =$this->context->link->getImageLink(
49+
urlencode($item['slug']),
50+
($category->id . '-' . $category->id_image),
51+
$this->getImageType('large')
52+
);
53+
}else{
54+
$menuItems[$key]['images'] = $retriever->getImage(
55+
$category,
56+
$category->id_image
57+
);
58+
}
59+
}
60+
}
61+
62+
$psdata = array();
63+
$psdata['menuItems'] = $menuItems;
64+
65+
$this->ajaxRender(json_encode([
66+
'success' => true,
67+
'code' => $messageCode,
68+
'psdata' => $psdata
69+
]));
70+
die;
71+
}
72+
73+
protected function processPostRequest()
74+
{
75+
$this->ajaxRender(json_encode([
76+
'success' => true,
77+
'message' => 'POST not supported on this path'
78+
]));
79+
die;
80+
}
81+
82+
protected function processPutRequest()
83+
{
84+
$this->ajaxRender(json_encode([
85+
'success' => true,
86+
'message' => 'put not supported on this path'
87+
]));
88+
die;
89+
}
90+
91+
protected function processDeleteRequest()
92+
{
93+
$this->ajaxRender(json_encode([
94+
'success' => true,
95+
'message' => 'delete not supported on this path'
96+
]));
97+
die;
98+
}
99+
}

0 commit comments

Comments
 (0)