From c5623dd1819862e8ca7f9f29e927dd9382a76f92 Mon Sep 17 00:00:00 2001 From: Peter Ivanov Date: Tue, 9 Dec 2014 16:29:12 +0200 Subject: [PATCH] updates on shop #21 --- src/Microweber/Database.php | 12 +++-- src/Microweber/Install/Schema/Shop.php | 36 +++++++-------- src/Microweber/Providers/ShopManager.php | 44 ++++++++----------- src/Microweber/Traits/QueryFilter.php | 12 ++--- src/Microweber/functions/api_callbacks.php | 6 +++ src/Microweber/functions/shop.php | 27 ------------ .../modules/shop/orders/client_inner.php | 2 +- userfiles/modules/shop/orders/index.php | 12 ++--- userfiles/modules/shop/orders/manage.php | 4 +- 9 files changed, 66 insertions(+), 89 deletions(-) diff --git a/src/Microweber/Database.php b/src/Microweber/Database.php index 2465451..1e17282 100644 --- a/src/Microweber/Database.php +++ b/src/Microweber/Database.php @@ -127,10 +127,13 @@ public function get($table_name_or_params, $params = null) unset($params['groupby']); } - - + if (isset($orig_params['no_cache']) and ($orig_params['no_cache'])) { + $this->use_cache = false; + } $query = $this->map_filters($query, $params, $table); + $params = $this->map_array_to_table($table, $params); + $query = $this->map_values_to_query($query, $params); @@ -162,10 +165,11 @@ public function get($table_name_or_params, $params = null) } if (isset($orig_params['no_cache']) and ($orig_params['no_cache'])) { - $this->use_cache = true; + } - if (!$this->use_cache) { + if ($this->use_cache == false) { + $data = $query->get(); } else { diff --git a/src/Microweber/Install/Schema/Shop.php b/src/Microweber/Install/Schema/Shop.php index 218bde7..ee773c6 100644 --- a/src/Microweber/Install/Schema/Shop.php +++ b/src/Microweber/Install/Schema/Shop.php @@ -29,7 +29,7 @@ public function get() 'cart_orders' => [ 'updated_at' => 'dateTime', 'created_at' => 'dateTime', - 'country' => 'string', + 'promo_code' => 'longText', 'amount' => 'float', 'transaction_id' => 'longText', @@ -44,22 +44,22 @@ public function get() 'last_name' => 'longText', 'email' => 'longText', + 'country' => 'string', + 'city' => 'text', - 'city' => 'longText', - - 'state' => 'longText', + 'state' => 'string', - 'zip' => 'longText', + 'zip' => 'string', 'address' => 'longText', 'address2' => 'longText', - 'phone' => 'longText', + 'phone' => 'text', 'created_by' => 'integer', 'edited_by' => 'integer', 'session_id' => 'string', 'order_completed' => "integer", 'is_paid' => "integer", - 'url' => 'longText', + 'url' => 'text', 'user_ip' => 'string', 'items_count' => 'integer', 'custom_fields_data' => 'longText', @@ -71,23 +71,23 @@ public function get() 'payment_status' => 'string', - 'payment_email' => 'longText', - 'payment_receiver_email' => 'longText', + 'payment_email' => 'text', + 'payment_receiver_email' => 'text', - 'payment_name' => 'longText', + 'payment_name' => 'text', - 'payment_country' => 'longText', + 'payment_country' => 'text', - 'payment_address' => 'longText', + 'payment_address' => 'text', - 'payment_city' => 'longText', - 'payment_state' => 'longText', - 'payment_zip' => 'longText', + 'payment_city' => 'text', + 'payment_state' => 'string', + 'payment_zip' => 'string', - 'payer_id' => 'longText', + 'payer_id' => 'text', - 'payer_status' => 'longText', - 'payment_type' => 'longText', + 'payer_status' => 'text', + 'payment_type' => 'text', 'order_status' => 'string', 'payment_shipping' => 'float', diff --git a/src/Microweber/Providers/ShopManager.php b/src/Microweber/Providers/ShopManager.php index 364a8c9..4f47072 100644 --- a/src/Microweber/Providers/ShopManager.php +++ b/src/Microweber/Providers/ShopManager.php @@ -106,7 +106,7 @@ public function checkout($data) $this->app->cache_manager->delete('cart/global'); $this->app->cache_manager->delete('cart_orders/global'); - $exec_return = true; + $exec_return = true; } else if (isset($_REQUEST['mw_payment_failure']) and intval($_REQUEST['mw_payment_failure']) == 1) { $cur_sid = mw()->user_manager->session_id(); @@ -173,6 +173,7 @@ public function checkout($data) $checkout_errors = array(); $check_cart = $this->get_cart($cart); + if (!is_array($check_cart)) { $checkout_errors['cart_empty'] = 'Your cart is empty'; } else { @@ -260,7 +261,7 @@ public function checkout($data) $amount = $this->cart_sum(); if ($amount == 0) { - // $checkout_errors['cart_sum'] = 'Cart sum is 0?'; + // $checkout_errors['cart_sum'] = 'Cart sum is 0?'; } if (!empty($checkout_errors)) { @@ -369,8 +370,8 @@ public function checkout($data) $this->app->database->q($q); } - $this->app->cache_manager->delete('cart/global'); - $this->app->cache_manager->delete('cart_orders/global'); + $this->app->cache_manager->delete('cart'); + $this->app->cache_manager->delete('cart_orders'); if (isset($place_order['is_paid']) and $place_order['is_paid'] == 1) { @@ -379,7 +380,6 @@ public function checkout($data) $this->after_checkout($ord); - //$_SESSION['mw_payment_success'] = true; } $_SESSION['order_id'] = $ord; @@ -388,7 +388,7 @@ public function checkout($data) if (isset($place_order) and !empty($place_order)) { return array('success' => "Your order has been placed successfully!"); - // return ($place_order); + // return ($place_order); } } @@ -570,20 +570,22 @@ public function get_cart($params = false) } } } + $params['limit'] = 10000; if (!isset($params['order_completed'])) { if (!isset($params['order_id'])) { $params['order_completed'] = 0; } - } elseif (isset($params['order_completed']) and $params['order_completed'] == 'any') { + } elseif (isset($params['order_completed']) and $params['order_completed'] === 'any') { + unset($params['order_completed']); } // $params['debug'] = mw()->user_manager->session_id(); - if ($this->no_cache == true) { - $params['no_cache'] = 1; - } + + $params['no_cache'] = 1; $get = $this->app->database->get($params); + if (isset($params['count']) and $params['count'] != false) { return $get; } @@ -916,7 +918,7 @@ public function after_checkout($order_id, $suppress_output = true) } $ord_data = $this->get_orders('one=1&id=' . $order_id); - if (isarr($ord_data)) { + if (is_array($ord_data)) { $ord = $order_id; $notification = array(); @@ -1251,7 +1253,7 @@ public function update_cart($data) } if ($found_price == false) { // $found_price = 0; - // return array('error' => 'Invalid data: Please post a "price" field'); + // return array('error' => 'Invalid data: Please post a "price" field'); $found_price = 0; } if (is_array($prices)) { @@ -1322,7 +1324,7 @@ public function checkout_confirm_email_test($params) $email_from = $params['to']; } - $ord_data = $this->get_orders('order_completed=y&limit=50'); + $ord_data = $this->get_orders('order_completed=1&limit=50'); if (is_array($ord_data[0])) { shuffle($ord_data); $ord_test = $ord_data[0]; @@ -1381,12 +1383,7 @@ public function checkout_ipn($data) $this->app->cache_manager->save($data, $cache_id, $cache_gr); - //$data = $this->app->cache_manager->get($cache_id, $cache_gr); - //$ord_data = $this->get_orders('no_cache=1&limit=1&tansaction_id=[is]NULL&payment_verify_token=' . $payment_verify_token . ''); - //cache_save($ord_data,__FUNCTION__,'debug'); - - // d($ord_data);. $payment_verify_token = $this->app->database_manager->escape_string($payment_verify_token); $table = $this->tables['cart_orders']; $q = " SELECT * FROM $table WHERE payment_verify_token='{$payment_verify_token}' AND transaction_id IS NULL LIMIT 1"; @@ -1557,17 +1554,15 @@ public function update_order($params = false) $this->app->error("You must be admin"); } - if(isset($params['is_paid'])){ - if($params['is_paid'] == 'y'){ + if (isset($params['is_paid'])) { + if ($params['is_paid'] == 'y') { $params['is_paid'] = 1; - } elseif($params['is_paid'] == 'n'){ + } elseif ($params['is_paid'] == 'n') { $params['is_paid'] = 0; } } - - $table = $this->tables['cart_orders']; $params['table'] = $table; $this->app->cache_manager->delete('cart_orders'); @@ -1717,7 +1712,6 @@ public function currency_convert_rate($from, $to) $remote_host = 'http://api.microweber.com'; $service = "/service/currency/?from=" . $from . "&to=" . $to; $remote_host_s = $remote_host . $service; - // d($remote_host_s); $get_remote = $this->app->url_manager->download($remote_host_s); if ($get_remote != false) { return floatval($get_remote); @@ -1793,7 +1787,7 @@ public function currency_get() $row = 1; - $cur_file = MW_PATH . 'lib' . DS . 'currencies.csv'; + $cur_file = MW_PATH . 'lib' . DS . 'currencies.csv'; if (is_file($cur_file)) { if (($handle = fopen($cur_file, "r")) !== FALSE) { diff --git a/src/Microweber/Traits/QueryFilter.php b/src/Microweber/Traits/QueryFilter.php index 1917d9e..eb4645f 100644 --- a/src/Microweber/Traits/QueryFilter.php +++ b/src/Microweber/Traits/QueryFilter.php @@ -99,16 +99,12 @@ public function map_filters($query, &$params, $table) $compare_sign = 'not_in'; } - - if($filter == 'created_at' or $filter == 'updated_at'){ $compare_value = date('Y-m-d H:i:s', strtotime($value)); - // $compare_value = strtotime($value); } } - switch ($filter) { @@ -151,6 +147,7 @@ public function map_filters($query, &$params, $table) break; case 'single': + case 'one': break; @@ -329,6 +326,9 @@ public function map_array_to_table($table, $array) $r = array_intersect($r, array_keys($array)); $r = array_flip($r); $r = array_intersect_key($array, $r); + + + return $r; } @@ -340,12 +340,12 @@ public function map_values_to_query($query, &$params) switch ($value) { case '[not_null]': $query->whereNotNull($column); - unset($params[$column]); + // unset($params[$column]); break; case '[null]': $query->whereNull($column); - unset($params[$column]); + // unset($params[$column]); break; } diff --git a/src/Microweber/functions/api_callbacks.php b/src/Microweber/functions/api_callbacks.php index cdfc4d0..2fe6dd6 100644 --- a/src/Microweber/functions/api_callbacks.php +++ b/src/Microweber/functions/api_callbacks.php @@ -59,7 +59,13 @@ api_expose_admin('delete_order'); api_expose('checkout_ipn'); api_expose('checkout'); +api_expose('remove_cart_item'); + +api_expose('update_cart_item_qty'); api_bind('shop/update_order', function ($data) { return mw()->shop_manager->update_order($data); }); + + +api_expose_admin('checkout_confirm_email_test'); diff --git a/src/Microweber/functions/shop.php b/src/Microweber/functions/shop.php index dc43d6f..2e85954 100644 --- a/src/Microweber/functions/shop.php +++ b/src/Microweber/functions/shop.php @@ -16,8 +16,6 @@ function get_cart($params = false) } - - function update_cart($data) { return mw()->shop_manager->update_cart($data); @@ -51,15 +49,6 @@ function update_order($params = false) } - // shop/update_order - - - - - - - - function delete_client($data) { return mw()->shop_manager->delete_client($data); @@ -87,35 +76,28 @@ function cart_sum($return_amount = true) } - - function checkout_ipn($data) { return mw()->shop_manager->checkout_ipn($data); } - function checkout($data) { return mw()->shop_manager->checkout($data); } -api_expose('checkout_confirm_email_test'); function checkout_confirm_email_test($params) { return mw()->shop_manager->checkout_confirm_email_test($params); } -api_expose('update_cart_item_qty'); - function update_cart_item_qty($data) { return mw()->shop_manager->update_cart_item_qty($data); } -api_expose('remove_cart_item'); function remove_cart_item($data) { @@ -135,22 +117,13 @@ function currency_format($amount, $curr = false) } -// event_bind('recover_shopping_cart', 'mw_shop_recover_shopping_cart'); - function mw_shop_recover_shopping_cart($sid = false) { - return mw()->shop_manager->recover_shopping_cart($sid); } - - - -// event_bind('mw_db_init_options', 'create_mw_shop_default_options'); function create_mw_shop_default_options() { - return mw()->shop_manager->create_mw_shop_default_options(); - } diff --git a/userfiles/modules/shop/orders/client_inner.php b/userfiles/modules/shop/orders/client_inner.php index 5e81ccb..c609e52 100644 --- a/userfiles/modules/shop/orders/client_inner.php +++ b/userfiles/modules/shop/orders/client_inner.php @@ -4,7 +4,7 @@ ?>