Skip to content

Commit 996207e

Browse files
Alex KrasnyAlex Krasny
authored andcommitted
feat: update plugin to new api
1 parent 9b3ef7b commit 996207e

File tree

98 files changed

+15972
-5299
lines changed

Some content is hidden

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

98 files changed

+15972
-5299
lines changed

.DS_Store

6 KB
Binary file not shown.

mapping.json

Lines changed: 15 additions & 0 deletions
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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
class VFA_ModelCommonCustomer extends VFA_Model
4+
{
5+
public function getCustomer($id) {
6+
7+
}
8+
9+
public function getCustomers($data) {
10+
11+
}
12+
13+
public function getTotalCustomers($data) {
14+
15+
}
16+
}

model/common/seo.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
4+
class VFA_ModelCommonSeo extends VFA_Model {
5+
public function get_category_by_url($url) {
6+
foreach( (get_terms()) as $category) {
7+
$keyword = str_replace(get_site_url(), '', get_term_link((int)$category->term_id));
8+
$keyword = trim($keyword, '/?');
9+
$keyword = trim($keyword, '/');
10+
11+
if ( '/' . $keyword == $url )
12+
13+
return array('id' => $category->term_id, 'type' => $category->taxonomy);
14+
}
15+
return false;
16+
}
17+
public function searchKeyword($url) {
18+
$search = url_to_postid($url);
19+
$type = '';
20+
21+
if ($search != 0) {
22+
if (get_post_type($search) == 'post') {
23+
$type = 'post';
24+
} else if (get_post_type($search) == 'page') {
25+
$type = 'page';
26+
} else {
27+
$type = 'product';
28+
}
29+
} else {
30+
$search = $this->get_category_by_url($url);
31+
if ($search) {
32+
if ($search['type'] == 'category') {
33+
$type = 'blog-category';
34+
} else if($search['type'] == 'pwb-brand') {
35+
$type = 'manufacturer';
36+
} else {
37+
$type='category';
38+
}
39+
$search = $search['id'];
40+
} else {
41+
$search = '';
42+
}
43+
44+
}
45+
46+
return array(
47+
'id' => $search,
48+
'type' => $type,
49+
'url' => $url
50+
);
51+
}
52+
}

model/common/vuefront.php

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?php
2+
3+
class VFA_ModelCommonVuefront extends VFA_Model
4+
{
5+
6+
7+
public function editApp($name, $appSetting)
8+
{
9+
$appSetting['codename'] = $name;
10+
11+
$setting = get_option('vuefront-apps');
12+
13+
$app = $this->getApp($name);
14+
15+
if (!empty($app)) {
16+
foreach ($setting as $key => $value) {
17+
if ($value['codename'] == $name) {
18+
$setting[$key] = $appSetting;
19+
}
20+
}
21+
} else {
22+
$setting[] = $appSetting;
23+
}
24+
25+
update_option('vuefront-apps', $setting);
26+
}
27+
28+
public function checkAccess() {
29+
$setting = get_option('vuefront-settings') ? get_option('vuefront-settings') : array();
30+
if (!$this->request->get_param('accessKey')) {
31+
return false;
32+
}
33+
34+
$result = false;
35+
foreach ($setting as $key => $value) {
36+
if($key === 'accessKey' && $this->request->get_param('accessKey') === $value) {
37+
$result = true;
38+
}
39+
}
40+
return $result;
41+
}
42+
43+
public function getApp($name)
44+
{
45+
$setting = get_option('vuefront-apps');
46+
foreach ($setting as $value) {
47+
if ($value['codename'] == $name) {
48+
return $value;
49+
}
50+
}
51+
52+
return false;
53+
}
54+
55+
public function getAppsForEvent() {
56+
$setting = get_option('vuefront-apps');
57+
58+
$result = [];
59+
foreach ($setting as $value) {
60+
if (!empty($value['eventUrl'])) {
61+
$result[] = $value;
62+
}
63+
}
64+
65+
return $result;
66+
}
67+
68+
public function pushEvent($name, $data)
69+
{
70+
$apps = $this->getAppsForEvent();
71+
72+
foreach ($apps as $key => $value) {
73+
$output = $this->request($value['eventUrl'], [
74+
'name' => $name,
75+
'data' => $data,
76+
]);
77+
78+
if ($output) {
79+
$data = $output;
80+
}
81+
}
82+
83+
return $data;
84+
}
85+
86+
public function request($url, $data, $token = false) {
87+
$ch = curl_init();
88+
$headr = array();
89+
90+
$headr[] = 'Content-type: application/json';
91+
92+
if ($token) {
93+
$headers[] = 'Authorization: Bearer '.$token;
94+
}
95+
96+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
97+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
98+
curl_setopt($ch, CURLOPT_POST, true);
99+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
100+
curl_setopt($ch, CURLOPT_URL, $url);
101+
102+
$result = curl_exec($ch);
103+
104+
$error = curl_error($ch);
105+
106+
if ($error) {
107+
throw new Exception($error);
108+
}
109+
110+
$result = json_decode($result, true);
111+
return $result;
112+
}
113+
114+
115+
public function mergeSchemas($files) {
116+
$rootQueryType = '';
117+
$types = '';
118+
$rootMutationType = '';
119+
foreach ($files as $value) {
120+
preg_match('/type\s+RootQueryType\s\{\s*\n([^\}]+)/', $value, $matched);
121+
if (!empty($matched[1])) {
122+
$rootQueryType = $rootQueryType.PHP_EOL.$matched[1];
123+
}
124+
preg_match('/type\s+RootMutationType\s\{\s*\n([^\}]+)/', $value, $mutationMatched);
125+
if (!empty($mutationMatched[1])) {
126+
$rootMutationType = $rootMutationType.PHP_EOL.$mutationMatched[1];
127+
}
128+
preg_match('/([a-zA-Z0-9\=\s\}\_\-\@\{\:\[\]\(\)\!\"]+)type RootQueryType/', $value, $typesMatched);
129+
if (!empty($typesMatched[1])) {
130+
$types = $types.PHP_EOL.$typesMatched[1];
131+
}
132+
}
133+
134+
return "${types}".PHP_EOL."type RootQueryType {".PHP_EOL."${rootQueryType}".PHP_EOL."}".PHP_EOL."type RootMutationType {".PHP_EOL."${rootMutationType}".PHP_EOL."}";
135+
}
136+
}

model/store/cart.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
class VFA_ModelStoreCart extends VFA_Model {
4+
public function prepareCart() {
5+
$cart = array();
6+
foreach (WC()->cart->get_cart() as $product) {
7+
$this->load->model('store/product');
8+
$cart['products'] = array();
9+
foreach (WC()->cart->get_cart() as $product) {
10+
if ($product['variation_id'] !== 0) {
11+
$product_id = $product['variation_id'];
12+
} else {
13+
$product_id = $product['product_id'];
14+
}
15+
$option_data = array();
16+
17+
foreach ($product['variation'] as $key => $value) {
18+
$option_data[] = array(
19+
'option_id' => str_replace('attribute_', '', $key),
20+
'option_value_id' => $value
21+
);
22+
}
23+
24+
$cart['products'][] = array(
25+
'key' => $product['key'],
26+
'product' => array(
27+
'product_id' => $product_id,
28+
'price' => '1'
29+
),
30+
'quantity' => $product['quantity'],
31+
'option' => $option_data,
32+
'total' => $this->currency->format($product['line_total'])
33+
);
34+
}
35+
}
36+
}
37+
}

model/store/category.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public function getCategories( $data = array() ) {
7272
$implode[] = "tt.parent = '" . (int) $data['filter_parent_id'] . "'";
7373
}
7474

75+
if (isset($data['filter_search'])) {
76+
$implode[] = "t.`name` LIKE '%".$data['filter_search']."%'";
77+
}
78+
7579
if ( count( $implode ) > 0 ) {
7680
$sql .= ' AND ' . implode( ' AND ', $implode );
7781
}
@@ -106,7 +110,7 @@ public function getCategories( $data = array() ) {
106110

107111
$sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit'];
108112
}
109-
113+
110114
$results = get_transient(md5($sql));
111115
if($results === false) {
112116
$results = $wpdb->get_results( $sql );
@@ -132,6 +136,11 @@ public function getTotalCategories( $data = array() ) {
132136
$implode[] = "tt.parent = '" . (int) $data['filter_parent_id'] . "'";
133137
}
134138

139+
if (isset($data['filter_search'])) {
140+
$implode[] = "t.`name` LIKE '%".$data['filter_search']."%'";
141+
}
142+
143+
135144
if ( count( $implode ) > 0 ) {
136145
$sql .= ' AND ' . implode( ' AND ', $implode );
137146
}

0 commit comments

Comments
 (0)