Esempio n. 1
0
 /**
  * Return order/orders info after the order placing
  * @param int   $order_id
  * @param array $response
  */
 public static function returnPlacedOrders($order_id, &$response, $items_per_page, $lang_code)
 {
     $order = self::getOrderInfo($order_id);
     $_error = false;
     $status = db_get_field('SELECT status FROM ?:orders WHERE order_id=?i', $order_id);
     if ($status == STATUS_PARENT_ORDER) {
         $child_orders = db_get_hash_single_array("SELECT order_id, status FROM ?:orders WHERE parent_order_id = ?i", array('order_id', 'status'), $order_id);
         $status = reset($child_orders);
         $order['child_orders'] = array_keys($child_orders);
     }
     if (!in_array($status, fn_get_order_paid_statuses())) {
         $_error = true;
         if ($status != 'B') {
             if (!empty($child_orders)) {
                 array_unshift($child_orders, $order_id);
             } else {
                 $child_orders = array();
                 $child_orders[] = $order_id;
             }
             $order_id_field = $status == 'N' ? 'processed_order_id' : 'failed_order_id';
             $_SESSION['cart'][$order_id_field] = $child_orders;
             $cart =& $_SESSION['cart'];
             if (!empty($cart['failed_order_id'])) {
                 $_ids = !empty($cart['failed_order_id']) ? $cart['failed_order_id'] : $cart['processed_order_id'];
                 $_order_id = reset($_ids);
                 $_payment_info = db_get_field("SELECT data\n                         FROM ?:order_data\n                         WHERE order_id = ?i AND type = 'P'", $_order_id);
                 if (!empty($_payment_info)) {
                     $_payment_info = unserialize(fn_decrypt_text($_payment_info));
                 }
                 $_msg = !empty($_payment_info['reason_text']) ? $_payment_info['reason_text'] : '';
                 $_msg .= empty($_msg) ? __('text_order_placed_error') : '';
                 $response->addError('ERROR_FAIL_POST_ORDER', $_msg);
                 $cart['processed_order_id'] = $cart['failed_order_id'];
                 unset($cart['failed_order_id']);
             } elseif (!fn_twg_set_internal_errors($response, 'ERROR_FAIL_POST_ORDER')) {
                 $response->addError('ERROR_FAIL_POST_ORDER', __('fail_post_order', $lang_code));
             }
         } else {
             if (!fn_twg_set_internal_errors($response, 'ERROR_ORDER_BACKORDERED')) {
                 $response->addError('ERROR_ORDER_BACKORDERED', __('text_order_backordered', $lang_code));
             }
         }
         $response->returnResponse();
     }
     $auth =& $_SESSION['auth'];
     $user = fn_get_user_info($auth['user_id']);
     $profile_points = !empty($user['points']) ? $user['points'] : 0;
     if (empty($order['child_orders'])) {
         $response->setData(array('order' => $order, 'profile_points' => $profile_points));
     } else {
         $params = array();
         if (empty($auth['user_id'])) {
             $params['order_id'] = $auth['order_ids'];
         } else {
             $params['user_id'] = $auth['user_id'];
         }
         list($orders, , $totals) = fn_get_orders($params, $items_per_page, true);
         $response->setMeta(!empty($totals['gross_total']) ? $totals['gross_total'] : 0, 'gross_total');
         $response->setMeta(!empty($totals['totally_paid']) ? $totals['totally_paid'] : 0, 'totally_paid');
         $response->setMeta($order, 'order');
         $response->setResponseList(TwigmoOrder::getOrdersAsApiList($orders, $lang_code));
         $response->setData($profile_points, 'profile_points');
         $pagination_params = array('items_per_page' => !empty($items_per_page) ? $items_per_page : TWG_RESPONSE_ITEMS_LIMIT, 'page' => !empty($_REQUEST['page']) ? $_REQUEST['page'] : 1);
         fn_twg_set_response_pagination($response, $pagination_params);
     }
 }
Esempio n. 2
0
 } elseif ($meta['object'] == 'orders') {
     $_auth =& $_SESSION['auth'];
     $params = $_REQUEST;
     if (!empty($_auth['user_id'])) {
         $params['user_id'] = $_auth['user_id'];
     } elseif (!empty($_auth['order_ids'])) {
         $params['order_id'] = $_auth['order_ids'];
     } else {
         $response->addError('ERROR_ACCESS_DENIED', __('access_denied'));
         $response->returnResponse();
     }
     $params['page'] = !empty($params['page']) ? $params['page'] : 1;
     list($orders, $params, $totals) = fn_get_orders($params, $items_per_page, true);
     $response->setMeta(!empty($totals['gross_total']) ? $totals['gross_total'] : 0, 'gross_total');
     $response->setMeta(!empty($totals['totally_paid']) ? $totals['totally_paid'] : 0, 'totally_paid');
     $response->setResponseList(TwigmoOrder::getOrdersAsApiList($orders, $lang_code));
     $pagination_params = array('total_items' => $params['total_items'], 'items_per_page' => !empty($items_per_page) ? $items_per_page : TWG_RESPONSE_ITEMS_LIMIT, 'page' => !empty($params['page']) ? $params['page'] : 1);
     fn_twg_set_response_pagination($response, $pagination_params);
 } elseif ($meta['object'] == 'placed_order') {
     TwigmoOrder::checkIfOrderAllowed($_REQUEST['order_id'], $_SESSION['auth'], $response);
     TwigmoOrder::returnPlacedOrders($_REQUEST['order_id'], $response, $items_per_page, $lang_code);
 } elseif ($meta['object'] == 'homepage') {
     fn_twg_set_response_homepage($response);
 } elseif ($meta['object'] == 'payment_methods') {
     $cart =& $_SESSION['cart'];
     $auth =& $_SESSION['auth'];
     // Update shipping info
     if (!empty($_REQUEST['shipping_ids'])) {
         fn_checkout_update_shipping($cart, $_REQUEST['shipping_ids']);
     }
     $payment_methods = fn_twg_get_payment_methods();
Esempio n. 3
0
             $period_total_paid = empty($totals['total_paid']) ? 0 : $totals['total_paid'];
             $total_change = empty($prev_totals['total_paid']) ? 0 : $prev_totals['total_paid'];
             $order_amount_change = empty($prev_totals['order_amount']) ? 0 : $prev_totals['order_amount'];
             $total_paid_change = empty($prev_totals['total_paid']) ? 0 : $prev_totals['total_paid'];
             $item_amount_change = $prev_item_amount;
             $stat = array('title' => $title, 'time_from' => $time_from, 'total_paid' => $period_total_paid, 'total_paid_change' => $total_paid_change, 'total' => $period_total, 'total_change' => $total_change, 'order_amount' => $order_amount, 'order_amount_change' => $order_amount_change, 'item_amount' => $item_amount);
             if (!empty($status_orders)) {
                 $stat['status_stats'] = array('status_stat' => $status_orders);
             }
             $period_stats[] = $stat;
         }
         $response->setData(array('period' => $period_stats), 'periods');
         // Get latest orders
         $search_params = array('sort_by' => 'date', 'sort_order' => 'desc');
         list($orders) = fn_get_orders($search_params, $items_per_page, true);
         $orders = TwigmoOrder::getOrdersAsApiList($orders, $lang_code);
         $response->setData($orders, 'latest_orders');
         $response->returnResponse('orders_statistics');
     } else {
         if (!empty($search) && !empty($search['sort_by'])) {
             $sortings = array('sort_by' => $search['sort_by'], 'sort_order' => !empty($search['sort_order']) && $search['sort_order'] == 'desc' ? 'desc' : 'asc');
         }
         $response->setResponseList(Api::getApiSchemaData($object, $condition, array(), $options, $sortings));
     }
     $pagination_params = array('items_per_page' => !empty($items_per_page) ? $items_per_page : TWG_RESPONSE_ITEMS_LIMIT, 'page' => !empty($_REQUEST['page']) ? $_REQUEST['page'] : 1, 'total_items' => !empty($total_items) ? $total_items : 0);
     if ($is_paginate) {
         fn_twg_set_response_pagination($response, $pagination_params);
     }
     $response->returnResponse($object);
 }
 if ($_REQUEST['action'] == 'details') {
Esempio n. 4
0
function fn_twg_get_latest_orders($lang_code)
{
    list($orders, $search) = fn_get_orders(array('sort_by' => 'date', 'sort_order' => 'desc'), 7);
    $orders = TwigmoOrder::getOrdersAsApiList($orders, $lang_code);
    return array('orders' => $orders, 'total' => $search['total_items']);
}