Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
updates on shop #21
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-mw committed Dec 9, 2014
1 parent 14a1f11 commit c5623dd
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 89 deletions.
12 changes: 8 additions & 4 deletions src/Microweber/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down Expand Up @@ -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 {
Expand Down
36 changes: 18 additions & 18 deletions src/Microweber/Install/Schema/Shop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down
44 changes: 19 additions & 25 deletions src/Microweber/Providers/ShopManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand All @@ -379,7 +380,6 @@ public function checkout($data)


$this->after_checkout($ord);
//$_SESSION['mw_payment_success'] = true;
}

$_SESSION['order_id'] = $ord;
Expand All @@ -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);
}

}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions src/Microweber/Traits/QueryFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {


Expand Down Expand Up @@ -151,6 +147,7 @@ public function map_filters($query, &$params, $table)
break;

case 'single':
case 'one':

break;

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Microweber/functions/api_callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Loading

0 comments on commit c5623dd

Please sign in to comment.