Skip to content

Commit 883ec7d

Browse files
committed
Updted to new schema
1 parent c964c9e commit 883ec7d

File tree

10 files changed

+459
-81
lines changed

10 files changed

+459
-81
lines changed

mapping.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
"accountEdit": "common/account/edit",
66
"accountEditPassword": "common/account/editPassword",
77
"accountCheckLogged": "common/account/isLogged",
8+
"accountAddressList": "common/account/addressList",
9+
"accountAddress": "common/account/address",
10+
"accountAddAddress": "common/account/addAddress",
11+
"accountEditAddress": "common/account/editAddress",
12+
"accountRemoveAddress": "common/account/removeAddress",
13+
14+
"uploadFile": "common/file/upload",
15+
16+
"countriesList": "common/country/getList",
17+
"country": "common/country/get",
18+
19+
"zonesList": "common/zone/getList",
20+
"zone": "common/zone/get",
821

922
"categoryBlog": "blog/category/get",
1023
"categoriesBlogList": "blog/category/getList",
@@ -40,5 +53,8 @@
4053

4154
"wishlist": "store/wishlist/getList",
4255
"addToWishlist": "store/wishlist/add",
43-
"removeWishlist": "store/wishlist/remove"
56+
"removeWishlist": "store/wishlist/remove",
57+
58+
"contactSend": "common/contact/send",
59+
"contact": "common/contact/get"
4460
}

model/store/product.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function getProductImages($product_id)
1919

2020
$result = $wpdb->get_row("SELECT pm.`meta_value` AS images FROM `wp_postmeta` pm WHERE pm.`post_id` = '".(int)$product_id."' AND pm.`meta_key` = '_product_image_gallery'");
2121

22-
$product_data = explode(',', $result->images);
22+
$product_data = !empty($result->images) ? explode(',', $result->images) : array();
2323

2424
return $product_data;
2525
}
@@ -60,6 +60,7 @@ public function getProduct($product_id)
6060
ps2.meta_value as model,
6161
(pr.meta_value + 0) as rating,
6262
pss.meta_value as stock_status,
63+
(pvm.meta_value + 0) as price_variation,
6364
(pm.meta_value + 0) as price,
6465
(ps.meta_value + 0) as special,
6566
pt.meta_value as image_id,
@@ -68,6 +69,7 @@ public function getProduct($product_id)
6869
LEFT JOIN wp_terms t ON t.term_id = tax.term_id WHERE rel.`object_id` = p.ID AND tax.`taxonomy` = 'product_type') AS type
6970
FROM wp_posts p
7071
LEFT JOIN wp_postmeta pm ON (pm.post_id = p.ID AND pm.meta_key = '_regular_price')
72+
LEFT JOIN wp_postmeta pvm ON (pvm.post_id = p.ID AND pvm.meta_key = '_price')
7173
LEFT JOIN wp_postmeta ps ON (ps.post_id = p.ID AND ps.meta_key = '_sale_price')
7274
LEFT JOIN wp_postmeta pt ON (pt.post_id = p.ID AND pt.meta_key = '_thumbnail_id')
7375
LEFT JOIN wp_postmeta pr ON (pr.post_id = p.ID AND pr.meta_key = '_wc_average_rating')
@@ -76,7 +78,7 @@ public function getProduct($product_id)
7678
WHERE p.ID = '".(int)$product_id."'";
7779

7880
$result = $wpdb->get_row($sql);
79-
81+
8082
return $result;
8183
}
8284

resolver/common/account.php

Lines changed: 183 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,202 @@
11
<?php
22

3-
class ResolverCommonAccount extends Resolver {
4-
public function login( $args ) {
5-
$creds = array();
6-
7-
$creds['user_login'] = $args["email"];
8-
$creds['user_password'] = $args["password"];
9-
$creds['remember'] = true;
10-
$user = wp_signon( $creds );
11-
12-
if ( ! is_wp_error( $user ) ) {
13-
global $current_user;
14-
15-
$current_user = $user;
16-
17-
return $this->get($current_user->ID);
18-
} else {
19-
$error = reset( $user->errors );
20-
throw new Exception( $error[0] );
21-
}
22-
}
23-
24-
public function logout( $args ) {
25-
wp_logout();
26-
27-
return array(
28-
'status' => is_user_logged_in()
29-
);
30-
}
31-
32-
public function register( $args ) {
33-
$customer = $args['customer'];
34-
35-
$userdata = array(
36-
'user_pass' => $customer['password'],
37-
'user_login' => $customer['email'],
38-
'user_email' => $customer['email'],
39-
'first_name' => $customer['firstName'],
40-
'last_name' => $customer['lastName']
41-
);
42-
43-
$user_id = wp_insert_user( $userdata );
44-
if ( ! is_wp_error( $user_id ) ) {
45-
return $this->get($user_id);
46-
} else {
47-
$error = reset( $user_id->errors );
48-
throw new Exception( $error[0] );
49-
}
3+
class ResolverCommonAccount extends Resolver
4+
{
5+
public function login($args)
6+
{
7+
$creds = array();
8+
9+
$creds['user_login'] = $args["email"];
10+
$creds['user_password'] = $args["password"];
11+
$creds['remember'] = true;
12+
$user = wp_signon($creds);
13+
14+
if (!is_wp_error($user)) {
15+
global $current_user;
16+
17+
$current_user = $user;
18+
19+
return $this->get($current_user->ID);
20+
} else {
21+
$error = reset($user->errors);
22+
throw new Exception($error[0]);
23+
}
5024
}
51-
52-
public function edit($args) {
25+
26+
public function logout($args)
27+
{
28+
wp_logout();
29+
30+
return array(
31+
'status' => is_user_logged_in()
32+
);
33+
}
34+
35+
public function register($args)
36+
{
37+
$customer = $args['customer'];
38+
39+
$userdata = array(
40+
'user_pass' => $customer['password'],
41+
'user_login' => $customer['email'],
42+
'user_email' => $customer['email'],
43+
'first_name' => $customer['firstName'],
44+
'last_name' => $customer['lastName']
45+
);
46+
47+
$user_id = wp_insert_user($userdata);
48+
if (!is_wp_error($user_id)) {
49+
return $this->get($user_id);
50+
} else {
51+
$error = reset($user_id->errors);
52+
throw new Exception($error[0]);
53+
}
54+
}
55+
56+
public function edit($args)
57+
{
5358
global $current_user;
5459

5560
return $this->get($current_user->ID);
5661
}
5762

58-
public function editPassword($args) {
63+
public function editPassword($args)
64+
{
5965
global $current_user;
6066

6167
return $this->get($current_user->ID);
6268
}
6369

64-
public function get($user_id) {
65-
$user = get_user_by( 'ID', $user_id );
70+
public function get($user_id)
71+
{
72+
$user = get_user_by('ID', $user_id);
73+
74+
return array(
75+
'id' => $user->ID,
76+
'email' => $user->user_email,
77+
'firstName' => get_user_meta($user->ID, 'first_name', true),
78+
'lastName' => get_user_meta($user->ID, 'last_name', true),
79+
);
80+
}
81+
82+
public function isLogged($args)
83+
{
84+
$customer = array();
85+
86+
if (is_user_logged_in()) {
87+
$user = wp_get_current_user();
88+
89+
$customer = array(
90+
'id' => $user->ID,
91+
'email' => $user->user_email,
92+
'firstName' => $user->user_firstname,
93+
'lastName' => $user->user_lasttname
94+
);
95+
}
6696

6797
return array(
68-
'id' => $user->ID,
69-
'email' => $user->user_email,
70-
'firstName' => get_user_meta( $user->ID, 'first_name', true ),
71-
'lastName' => get_user_meta( $user->ID, 'last_name', true ),
98+
'status' => is_user_logged_in(),
99+
'customer' => $customer
72100
);
73101
}
74102

75-
public function isLogged( $args ) {
76-
$customer = array();
77-
78-
if ( is_user_logged_in() ) {
79-
$user = wp_get_current_user();
80-
81-
$customer = array(
82-
'id' => $user->ID,
83-
'email' => $user->user_email,
84-
'firstName' => $user->user_firstname,
85-
'lastName' => $user->user_lasttname
86-
);
87-
}
88-
89-
return array(
90-
'status' => is_user_logged_in(),
91-
'customer' => $customer
92-
);
93-
}
103+
public function address($args)
104+
{
105+
$address = array();
106+
107+
global $current_user;
108+
109+
switch ($args['id']) {
110+
case 'billing':
111+
$address = array(
112+
'id' => 'billing',
113+
'firstName' => get_user_meta($current_user->ID, 'billing_first_name', true),
114+
'lastName' => get_user_meta($current_user->ID, 'billing_last_name', true),
115+
'company' => get_user_meta($current_user->ID, 'billing_company', true),
116+
'address1' => get_user_meta($current_user->ID, 'billing_address_1', true),
117+
'address2' => get_user_meta($current_user->ID, 'billing_address_2', true),
118+
'zoneId' => '',
119+
'zone' => array(
120+
'id' => '',
121+
'name' => ''
122+
),
123+
'country' => $this->load->resolver('common/country/get', array(
124+
'id' => get_user_meta($current_user->ID, 'billing_country', true)
125+
)),
126+
'countryId' => get_user_meta($current_user->ID, 'billing_country', true),
127+
'city' => get_user_meta($current_user->ID, 'billing_city', true),
128+
'zipcode' => get_user_meta($current_user->ID, 'billing_postcode', true)
129+
);
130+
break;
131+
case 'shipping':
132+
$address = array(
133+
'id' => 'shipping',
134+
'firstName' => get_user_meta($current_user->ID, 'shipping_first_name', true),
135+
'lastName' => get_user_meta($current_user->ID, 'shipping_last_name', true),
136+
'company' => get_user_meta($current_user->ID, 'shipping_company', true),
137+
'address1' => get_user_meta($current_user->ID, 'shipping_address_1', true),
138+
'address2' => get_user_meta($current_user->ID, 'shipping_address_2', true),
139+
'zoneId' => '',
140+
'zone' => array(
141+
'id' => '',
142+
'name' => ''
143+
),
144+
'country' => $this->load->resolver('common/country/get', array(
145+
'id' => get_user_meta($current_user->ID, 'shipping_country', true)
146+
)),
147+
'countryId' => get_user_meta($current_user->ID, 'shipping_country', true),
148+
'city' => get_user_meta($current_user->ID, 'shipping_city', true),
149+
'zipcode' => get_user_meta($current_user->ID, 'shipping_postcode', true)
150+
);
151+
break;
152+
}
153+
154+
return $address;
155+
}
156+
157+
public function addressList($args)
158+
{
159+
160+
$ids = array('billing', 'shipping');
161+
162+
$address = array();
163+
164+
foreach ($ids as $value) {
165+
$address[] = $this->address(array('id' => $value));
166+
}
167+
168+
return $address;
169+
}
170+
171+
public function editAddress($args)
172+
{
173+
global $current_user;
174+
175+
$prefix = $args['id'];
176+
177+
$data = array(
178+
'firstName' => '_first_name',
179+
'lastName' => '_last_name',
180+
'company' => '_company',
181+
'address1' => '_address_1',
182+
'address2' => '_address_2',
183+
'countryId' => '_country',
184+
'city' => '_city',
185+
'zipcode' => '_postcode'
186+
);
187+
188+
foreach ($data as $key => $value) {
189+
update_user_meta($current_user->ID, $prefix.$value, $args['address'][$key]);
190+
}
191+
192+
return $this->address($args);
193+
}
194+
195+
public function addAddress($args) {
196+
throw new Exception('Adding an address is not possible in Wordpress');
197+
}
198+
199+
public function removeAddress($args) {
200+
throw new Exception('Removing an address is not possible in Wordpress');
201+
}
94202
}

resolver/common/contact.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
class ResolverCommonContact extends Resolver
4+
{
5+
private $codename = "d_vuefront";
6+
7+
public function get()
8+
{
9+
$store_raw_country = get_option('woocommerce_default_country');
10+
$split_country = explode(":", $store_raw_country);
11+
12+
$address = array(
13+
'address_1' => get_option('woocommerce_store_address'),
14+
'address_2' => get_option('woocommerce_store_address_2'),
15+
'city' => get_option('woocommerce_store_city'),
16+
'postcode' => get_option('woocommerce_store_postcode'),
17+
'country' => $split_country[0],
18+
'state' => $split_country[1]
19+
);
20+
21+
$WC_Countries = new WC_Countries();
22+
23+
return array(
24+
'store' => get_bloginfo('name'),
25+
'email' => get_bloginfo('admin_email'),
26+
'address' => $WC_Countries->get_formatted_address($address, ', '),
27+
'geocode' => '',
28+
'locations' => array(),
29+
'telephone' => '',
30+
'fax' => '',
31+
'open' => '',
32+
'comment' => get_bloginfo('description')
33+
);
34+
}
35+
36+
public function send($args)
37+
{
38+
wp_mail(get_bloginfo('admin_email'), 'Enquiry '.$args['name'],$args['message'], array(
39+
'reply-to' => $args['email']
40+
));
41+
42+
return array(
43+
"status" => true
44+
);
45+
}
46+
}

0 commit comments

Comments
 (0)