Exemplo 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);
     }
 }
Exemplo n.º 2
0
         $_data = array('product_id' => $_REQUEST['id'], 'viewed' => 1, 'total' => POPULARITY_VIEW);
         db_query("INSERT INTO ?:product_popularity ?e ON DUPLICATE KEY UPDATE viewed = viewed + 1, total = total + ?i", $_data, POPULARITY_VIEW);
         $_SESSION['products_popularity']['viewed'][$_REQUEST['id']] = true;
     }
 } elseif ($meta['object'] == 'categories') {
     $object = fn_twg_get_api_category_data($_REQUEST['id'], $lang_code);
     $title = 'category';
 } elseif ($meta['object'] == 'order') {
     $order_id = !empty($_REQUEST['id']) ? $_REQUEST['id'] : 0;
     TwigmoOrder::checkIfOrderAllowed($order_id, $_SESSION['auth'], $response);
     $object = TwigmoOrder::getOrderInfo($order_id);
     $title = 'order';
 } elseif ($meta['object'] == 'ga_orders_info') {
     $order_id = !empty($_REQUEST['id']) ? $_REQUEST['id'] : 0;
     TwigmoOrder::checkIfOrderAllowed($order_id, $_SESSION['auth'], $response);
     $order_info = TwigmoOrder::getOrderInfo($order_id);
     if (!empty($order_info['is_parent_order']) && $order_info['is_parent_order'] == 'Y') {
         $order_info['child_ids'] = implode(',', db_get_fields("SELECT order_id FROM ?:orders WHERE parent_order_id = ?i", $order_id));
     }
     $view = fn_twg_get_view_object();
     $view->assign('order_info', $order_info);
     $mode = 'complete';
     include_once Registry::get('config.dir.addons') . 'google_analytics/controllers/frontend/checkout.post.php';
     foreach ($orders_info as &$order_info) {
         if (isset($order_info['products'])) {
             $order_info['items'] = array_values($order_info['products']);
             unset($order_info['products']);
         }
     }
     $response->setData($orders_info);
     $response->returnResponse();
Exemplo n.º 3
0
     $carriers_data = fn_twg_get_carriers();
     $carriers = array();
     foreach ($carriers_data as $k => $v) {
         $carriers[] = array('carrier_id' => $k, 'carrier' => $v);
     }
     $result = array('shippings' => Api::getAsList('shippings', $shippings), 'carriers' => Api::getAsList('carriers', $carriers));
     $response->setData($result);
     $response->returnResponse($object);
 }
 if (empty($_REQUEST['id'])) {
     $response->addError('ERROR_WRONG_OBJECT_DATA', str_replace('[object]', $object, __('twgadmin_wrong_api_object_data')));
     $response->returnResponse();
 }
 if ($object == 'orders') {
     $order_id = $_REQUEST['id'];
     $order = TwigmoOrder::apiGetOrderDetails($order_id);
     if (empty($order)) {
         $response->addError('ERROR_OBJECT_WAS_NOT_FOUND', str_replace('[object]', $object, __('twgadmin_object_was_not_found')));
         $response->returnResponse();
     }
     $response->setData($order);
     $response->returnResponse('order');
 } elseif ($object == 'products') {
     $product = fn_twg_get_api_product_data($_REQUEST['id'], $lang_code);
     if (empty($product)) {
         $response->addError('ERROR_OBJECT_WAS_NOT_FOUND', str_replace('[object]', $object, __('twgadmin_object_was_not_found')));
         $response->returnResponse();
     }
     $response->setData($product);
     $response->returnResponse('product');
 } elseif ($object == 'categories') {
Exemplo 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']);
}