Skip to content

Commit 9825549

Browse files
committed
feat: add api for order
1 parent 49e4f3e commit 9825549

File tree

77 files changed

+3954
-2457
lines changed

Some content is hidden

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

77 files changed

+3954
-2457
lines changed

controllers/admin/AdminVuefrontAjaxController.php

+66-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class AdminVuefrontAjaxController extends ModuleAdminController
1414
{
1515

16-
public function ajaxProcessVfTurnOff()
16+
public function ajaxProcessVfTurnOff()
1717
{
1818
if (strpos($_SERVER["SERVER_SOFTWARE"], "Apache") !== false) {
1919
if (file_exists(_PS_ROOT_DIR_ . '/modules/vuefront/.htaccess.txt')) {
@@ -36,9 +36,71 @@ public function ajaxProcessVfTurnOff()
3636
$this->ajaxProcessVfInformation();
3737
}
3838

39-
public function ajaxProcessVfTurnOn() {
40-
$catalog = Tools::getHttpHost(true). __PS_BASE_URI__;
41-
try {
39+
public function ajaxProcessVfAppsRemove() {
40+
$option = Configuration::get('vuefront-apps');
41+
42+
$setting = array();
43+
44+
try {
45+
$setting = Tools::jsonDecode($option, true);
46+
} catch(Exception $e) {
47+
48+
}
49+
unset($setting[$_POST['key']]);
50+
Configuration::updateValue('vuefront-apps', Tools::jsonEncode($setting), null,0,0);
51+
}
52+
53+
public function ajaxProcessVfAppsCreate() {
54+
55+
$option = Configuration::get('vuefront-apps');
56+
57+
$setting = array();
58+
59+
try {
60+
$setting = Tools::jsonDecode($option, true);
61+
} catch(Exception $e) {
62+
63+
}
64+
65+
$d = new DateTime();
66+
67+
$setting[] = array(
68+
'codename' => $_POST['codename'],
69+
'jwt' => $_POST['jwt'],
70+
'dateAdded' => $d->format('Y-m-d\TH:i:s.u')
71+
);
72+
73+
Configuration::updateValue('vuefront-apps', Tools::jsonEncode($setting), null,0,0);
74+
75+
die(
76+
Tools::jsonEncode(
77+
[
78+
'success' => 'success'
79+
]
80+
)
81+
);
82+
}
83+
84+
public function ajaxProcessVfApps() {
85+
$option = Configuration::get('vuefront-apps');
86+
87+
$setting = array();
88+
89+
try {
90+
$setting = Tools::jsonDecode($option, true);
91+
} catch(Exception $e) {
92+
93+
}
94+
die(
95+
Tools::jsonEncode(
96+
$setting
97+
)
98+
);
99+
}
100+
101+
public function ajaxProcessVfTurnOn() {
102+
$catalog = Tools::getHttpHost(true). __PS_BASE_URI__;
103+
try {
42104
$catalog_url_info = parse_url($catalog);
43105

44106
$catalog_path = $catalog_url_info['path'];

controllers/front/callback.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
require_once dirname(__FILE__) . '/../../system/startup.php';
14+
15+
/**
16+
* vuefront
17+
* vuefront.php
18+
*/
19+
class VuefrontCallbackModuleFrontController extends ModuleFrontController
20+
{
21+
private $codename = "vuefront";
22+
private $route = "vuefront";
23+
24+
public function initContent()
25+
{
26+
parent::initContent();
27+
28+
callback($this->context);
29+
}
30+
}

mapping.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
"addBlogPostReview": "blog/review/add",
3030

3131
"checkoutLink": "store/checkout/link",
32+
"paymentAddress": "store/checkout/paymentAddress",
33+
"shippingAddress": "store/checkout/shippingAddress",
34+
"paymentMethods": "store/checkout/paymentMethods",
35+
"shippingMethods": "store/checkout/shippingMethods",
36+
"createOrder": "store/checkout/createOrder",
3237

3338
"cart": "store/cart/get",
3439
"addToCart": "store/cart/add",
@@ -54,11 +59,11 @@
5459
"productsList": "store/product/getList",
5560
"product": "store/product/get",
5661
"addReview": "store/review/add",
57-
62+
5863
"wishlist": "store/wishlist/getList",
5964
"addToWishlist": "store/wishlist/add",
6065
"removeWishlist": "store/wishlist/remove",
6166

6267
"contactSend": "common/contact/send",
6368
"contact": "common/contact/get"
64-
}
69+
}

model/store/checkout.php

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
*
11+
* @version 0.1.0
12+
*/
13+
14+
15+
class ModelStoreCheckout extends Model {
16+
public function getJwt($codename) {
17+
$option = Configuration::get('vuefront-apps');
18+
19+
$setting = array();
20+
21+
try {
22+
$setting = Tools::jsonDecode($option, true);
23+
} catch(Exception $e) {
24+
25+
}
26+
27+
$result = false;
28+
29+
foreach ($setting as $key => $value) {
30+
if($value['codename'] == $codename) {
31+
$result = $value['jwt'];
32+
}
33+
}
34+
35+
return $result;
36+
}
37+
public function requestCheckout($query, $variables) {
38+
$jwt = $this->getJwt('vuefront-checkout-app');
39+
40+
$ch = curl_init();
41+
42+
$requestData = array(
43+
'operationName' => null,
44+
'variables' => $variables,
45+
'query' => $query
46+
);
47+
48+
$headr = array();
49+
50+
$headr[] = 'Content-type: application/json';
51+
$headr[] = 'Authorization: '.$jwt;
52+
53+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
54+
curl_setopt($ch, CURLOPT_HTTPHEADER,$headr);
55+
curl_setopt($ch, CURLOPT_POST,true);
56+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestData, JSON_FORCE_OBJECT) );
57+
// curl_setopt($ch, CURLOPT_URL, 'http://localhost:3005/graphql');
58+
curl_setopt($ch, CURLOPT_URL, 'https://api.checkout.vuefront.com/graphql');
59+
60+
$result = curl_exec($ch);
61+
62+
$result = json_decode($result, true);
63+
64+
return $result['data'];
65+
}
66+
}

0 commit comments

Comments
 (0)