Skip to content

Commit 8fd7d2a

Browse files
committed
feat: add new api
1 parent b984891 commit 8fd7d2a

File tree

86 files changed

+7317
-4467
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+7317
-4467
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
views/js/d_pax/node_modules

controllers/admin/AdminVuefrontAjaxController.php

+49
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,33 @@ public function ajaxProcessVfAppsCreate() {
8181
);
8282
}
8383

84+
public function ajaxProcessVfAppsEdit()
85+
{
86+
$option = Configuration::get('vuefront-apps');
87+
$setting = array();
88+
89+
try {
90+
$setting = Tools::jsonDecode($option, true);
91+
} catch(Exception $e) {
92+
93+
}
94+
$app = Tools::jsonDecode(html_entity_decode($_POST['app'], ENT_QUOTES, 'UTF-8'), true);
95+
96+
foreach ($app as $key => $value) {
97+
$setting[$_POST['key']][$key] = $value;
98+
}
99+
100+
Configuration::updateValue('vuefront-apps', Tools::jsonEncode($setting), null,0,0);
101+
102+
die(
103+
Tools::jsonEncode(
104+
[
105+
'success' => 'success'
106+
]
107+
)
108+
);
109+
}
110+
84111
public function ajaxProcessVfApps() {
85112
$option = Configuration::get('vuefront-apps');
86113

@@ -238,6 +265,28 @@ private function removeDir($dir)
238265
}
239266
}
240267

268+
public function ajaxProcessVfSettings()
269+
{
270+
$result = Configuration::get('vuefront-settings');
271+
272+
if (!$result) {
273+
$result = Tools::jsonEncode(array());
274+
}
275+
276+
die($result);
277+
}
278+
279+
public function ajaxProcessVfSettingsEdit()
280+
{
281+
$vfSetting = Tools::jsonDecode(html_entity_decode($_POST['setting'], ENT_QUOTES, 'UTF-8'), true);
282+
283+
Configuration::updateValue('vuefront-settings', Tools::jsonEncode($vfSetting), null,0,0);
284+
285+
die(
286+
Tools::jsonEncode(['success' => 'success'])
287+
);
288+
}
289+
241290
public function ajaxProcessVfInformation() {
242291
$extensions = [];
243292

mapping.json

+15
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,21 @@
1111
"accountEditAddress": "common/account/editAddress",
1212
"accountRemoveAddress": "common/account/removeAddress",
1313

14+
"manufacturerList": "store/manufacturer/getList",
15+
"manufacturer": "store/manufacturer/get",
16+
17+
"customersList": "common/account/customerList",
18+
"customer": "common/account/getCustomer",
19+
20+
"optionsList": "store/option/getList",
21+
"option": "store/option/get",
22+
1423
"home": "common/home/get",
1524

25+
"updateApp": "common/home/updateApp",
26+
27+
"searchUrl": "common/home/searchUrl",
28+
1629
"uploadFile": "common/file/upload",
1730

1831
"countriesList": "common/country/getList",
@@ -38,6 +51,8 @@
3851
"confirmOrder": "store/checkout/confirmOrder",
3952
"totals": "store/checkout/totals",
4053

54+
"authProxy": "common/home/authProxy",
55+
4156
"cart": "store/cart/get",
4257
"addToCart": "store/cart/add",
4358
"updateCart": "store/cart/update",

model/common/customer.php

+53
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,59 @@
1212

1313
class ModelCommonCustomer extends Model
1414
{
15+
public function getCustomers($data = array())
16+
{
17+
$sort = '';
18+
if ($data['sort'] == 'email') {
19+
$sort = 'p.`email`';
20+
}
21+
22+
if ($data['sort'] == 'firstName') {
23+
$sort = 'p.`firstname`';
24+
}
25+
26+
if ($data['sort'] == 'lastName') {
27+
$sort = 'p.`lastname`';
28+
}
29+
30+
$sql = new DbQuery();
31+
$sql->select('*');
32+
$sql->from('customer', 'p');
33+
$sql->where('p.`active` = 1');
34+
35+
if (!empty($data['search'])) {
36+
$sql->where("p.`firstname` LIKE '%" . pSQL($data['search']) .
37+
"%' OR p.lastname LIKE '%" . pSQL($data['search']) .
38+
"%' OR p.email LIKE '%" . pSQL($data['search']). "%'");
39+
}
40+
41+
$sql->orderBy($sort . ' ' . $data['order']);
42+
if (!empty($data['limit']) && $data['limit'] != -1) {
43+
$sql->limit($data['limit'], $data['start']);
44+
}
45+
46+
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
47+
48+
return $result;
49+
}
50+
51+
public function getTotalCustomers($data = array())
52+
{
53+
$sql = new DbQuery();
54+
$sql->select('count(*)');
55+
$sql->from('customer', 'p');
56+
$sql->where('p.`active` = 1');
57+
58+
if (!empty($data['search'])) {
59+
$sql->where("p.`firstname` LIKE '%" . pSQL($data['search']) .
60+
"%' OR p.lastname LIKE '%" . pSQL($data['search']) .
61+
"%' OR p.email LIKE '%" . pSQL($data['search']). "%'");
62+
}
63+
64+
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
65+
return $result['count(*)'];
66+
}
67+
1568
public function updateCustomer($customer)
1669
{
1770
$this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ?

model/common/seo.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
class ModelCommonSeo extends Model {
4+
public function addUrl($url, $type, $id) {
5+
$sql = new DbQuery();
6+
$sql->select('*');
7+
$sql->from('vuefront_url', 'v');
8+
$sql->where('url LIKE \''.$url.'\'');
9+
10+
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
11+
if (!$result) {
12+
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('INSERT INTO `' . _DB_PREFIX_ . 'vuefront_url` SET url = \''.$url.'\',
13+
id = \''.$id.'\',
14+
type = \''.$type.'\'');
15+
}
16+
}
17+
18+
public function searchKeyword($url) {
19+
$sql = new DbQuery();
20+
$sql->select('*');
21+
$sql->from('vuefront_url', 'v');
22+
$sql->where('url LIKE \''.$url.'\'');
23+
24+
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
25+
if (!$result) {
26+
return array(
27+
'id' => '',
28+
'type' => '',
29+
'url' => $url
30+
);
31+
}
32+
33+
return array(
34+
'id' => $result[0]['id'],
35+
'type' => $result[0]['type'],
36+
'url' => $url
37+
);
38+
}
39+
}

model/common/vuefront.php

+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
<?php
2+
/**
3+
* 2019 (c) VueFront
4+
*
5+
* MODULE VueFront
6+
*
7+
* @author VueFront
8+
* @copyright Copyright (c) permanent, VueFront
9+
* @license MIT
10+
* @version 0.1.0
11+
*/
12+
13+
class ModelCommonVuefront extends Model
14+
{
15+
public function editApp($name, $appSetting)
16+
{
17+
$appSetting['codename'] = $name;
18+
19+
$option = Configuration::get('vuefront-apps');
20+
21+
$setting = array();
22+
23+
try {
24+
$setting = Tools::jsonDecode($option, true);
25+
} catch(Exception $e) {
26+
27+
}
28+
29+
$app = $this->getApp($name);
30+
31+
if (!empty($app)) {
32+
foreach ($setting as $key => $value) {
33+
if ($value['codename'] == $name) {
34+
$setting[$key] = $appSetting;
35+
}
36+
}
37+
} else {
38+
$setting[] = $appSetting;
39+
}
40+
41+
Configuration::updateValue('vuefront-apps', Tools::jsonEncode($setting), null,0,0);
42+
}
43+
44+
public function checkAccess() {
45+
46+
$option = Configuration::get('vuefront-settings');
47+
48+
$setting = array();
49+
50+
try {
51+
$setting = Tools::jsonDecode($option, true);
52+
} catch(Exception $e) {
53+
54+
}
55+
56+
if (!Tools::getValue('accessKey')) {
57+
return false;
58+
}
59+
60+
$result = false;
61+
foreach ($setting as $key => $value) {
62+
if($key === 'accessKey' && Tools::getValue('accessKey') === $value) {
63+
$result = true;
64+
}
65+
}
66+
return $result;
67+
}
68+
69+
public function getApp($name)
70+
{
71+
$option = Configuration::get('vuefront-apps');
72+
73+
$setting = array();
74+
75+
try {
76+
$setting = Tools::jsonDecode($option, true);
77+
} catch(Exception $e) {
78+
}
79+
foreach ($setting as $value) {
80+
if ($value['codename'] == $name) {
81+
return $value;
82+
}
83+
}
84+
85+
return false;
86+
}
87+
88+
public function getAppsForEvent() {
89+
$option = Configuration::get('vuefront-apps');
90+
91+
$setting = array();
92+
93+
try {
94+
$setting = Tools::jsonDecode($option, true);
95+
} catch(Exception $e) {
96+
}
97+
$result = [];
98+
foreach ($setting as $value) {
99+
if (!empty($value['eventUrl'])) {
100+
$result[] = $value;
101+
}
102+
}
103+
104+
return $result;
105+
}
106+
107+
public function pushEvent($name, $data)
108+
{
109+
$apps = $this->getAppsForEvent();
110+
111+
foreach ($apps as $key => $value) {
112+
$output = $this->request($value['eventUrl'], [
113+
'name' => $name,
114+
'data' => $data,
115+
]);
116+
117+
if ($output) {
118+
$data = $output;
119+
}
120+
}
121+
122+
return $data;
123+
}
124+
125+
public function request($url, $data, $token = false) {
126+
$ch = curl_init();
127+
$headers = array();
128+
129+
$headers[] = 'Content-type: application/json';
130+
131+
if ($token) {
132+
$headers[] = 'Authorization: Bearer '.$token;
133+
}
134+
135+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
136+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
137+
curl_setopt($ch, CURLOPT_POST, true);
138+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
139+
curl_setopt($ch, CURLOPT_URL, $url);
140+
141+
$result = curl_exec($ch);
142+
143+
$error = curl_error($ch);
144+
145+
if ($error) {
146+
throw new Exception($error);
147+
}
148+
149+
$result = json_decode($result, true);
150+
return $result;
151+
}
152+
153+
154+
public function mergeSchemas($files) {
155+
$rootQueryType = '';
156+
$types = '';
157+
$rootMutationType = '';
158+
foreach ($files as $value) {
159+
preg_match('/type\s+RootQueryType\s\{\s*\n([^\}]+)/', $value, $matched);
160+
if (!empty($matched[1])) {
161+
$rootQueryType = $rootQueryType.PHP_EOL.$matched[1];
162+
}
163+
preg_match('/type\s+RootMutationType\s\{\s*\n([^\}]+)/', $value, $mutationMatched);
164+
if (!empty($mutationMatched[1])) {
165+
$rootMutationType = $rootMutationType.PHP_EOL.$mutationMatched[1];
166+
}
167+
preg_match('/([a-zA-Z0-9\=\s\}\_\-\@\{\:\[\]\(\)\!\"]+)type RootQueryType/', $value, $typesMatched);
168+
if (!empty($typesMatched[1])) {
169+
$types = $types.PHP_EOL.$typesMatched[1];
170+
}
171+
}
172+
173+
return "${types}".PHP_EOL."type RootQueryType {".PHP_EOL."${rootQueryType}".PHP_EOL."}".PHP_EOL."type RootMutationType {".PHP_EOL."${rootMutationType}".PHP_EOL."}";
174+
}
175+
}

0 commit comments

Comments
 (0)