Exemplo n.º 1
0
function fn_twg_api_get_session_cart(&$cart, $lang_code = CART_LANGUAGE)
{
    $data = array('amount' => 0, 'subtotal' => 0);
    $auth = $_SESSION['auth'];
    if (empty($cart)) {
        return $data;
    }
    $payment_methods = fn_twg_get_payment_methods();
    if (isset($payment_methods['payment'])) {
        $payment_methods = $payment_methods['payment'];
    }
    if (false != ($first_method = reset($payment_methods)) && empty($cart['payment_id']) && isset($cart['total']) && floatval($cart['total']) != 0) {
        $cart['payment_id'] = $first_method['payment_id'];
    }
    if (isset($cart['total']) && floatval($cart['total']) == 0) {
        $cart['payment_id'] = 0;
    }
    // fetch cart data
    $cart_data = array_merge($data, Api::getAsApiObject('cart', $cart, array(), array('lang_code' => $lang_code)));
    if (!empty($cart_data['taxes'])) {
        $cart_data['taxes'] = Api::getAsList('taxes', $cart_data['taxes']);
    }
    if (!empty($cart_data['products'])) {
        $cart_data['products'] = array_reverse($cart_data['products']);
    }
    if (!empty($cart_data['payment_surcharge'])) {
        $cart_data['total'] += $cart_data['payment_surcharge'];
    } else {
        $cart_data['payment_surcharge'] = 0;
    }
    // ================ Payment buttons ========================================
    $payment_buttons = array();
    $checkout_processors = array('amazon_checkout.php', 'paypal_express.php', 'google_checkout.php');
    $included_files = get_included_files();
    $is_payments_included = false;
    foreach ($checkout_processors as $checkout_processor) {
        if (in_array(Registry::get('config.dir.payments') . $checkout_processor, $included_files)) {
            $is_payments_included = true;
            break;
        }
    }
    if ($is_payments_included) {
        // Get from templater
        $view = fn_twg_get_view_object();
        $smarty_vars = array('checkout_add_buttons', 'checkout_buttons');
        foreach ($smarty_vars as $smarty_var) {
            $buttons = $view->getTemplateVars($smarty_var);
            if ($buttons !== null) {
                $payment_buttons = $buttons;
                break;
            }
        }
    } else {
        // Get payments fiels
        if (!empty($cart['products'])) {
            foreach ($cart['products'] as $product_key => $product) {
                if (!isset($cart['products'][$product_key]['product'])) {
                    $product_data = fn_get_product_data($product['product_id'], $auth);
                    $cart['products'][$product_key]['product'] = $product_data['product'];
                    $cart['products'][$product_key]['short_description'] = $product_data['short_description'];
                }
            }
            $mode = Registry::get('runtime.mode');
            Registry::set('runtime.mode', 'cart');
            # for the paypal express checkout
            $payment_buttons = fn_get_checkout_payment_buttons($cart, $cart['products'], $auth);
            Registry::set('runtime.mode', $mode);
        }
    }
    $cart_data['payment_buttons'] = fn_twg_filter_payment_buttons($payment_buttons);
    // ================ /Payment buttons =======================================
    $cart_data['empty_payments'] = empty($payment_methods) ? 'Y' : 'N';
    $cart_data['coupons'] = empty($cart['coupons']) ? array() : array_keys($cart['coupons']);
    $cart_data['use_gift_certificates'] = array();
    $cart_data['gift_certificates_total'] = 0;
    if (isset($cart['use_gift_certificates'])) {
        foreach ($cart['use_gift_certificates'] as $code => $cert) {
            $cart_data['use_gift_certificates'][] = array('code' => $code, 'cost' => $cert['cost']);
            $cart_data['gift_certificates_total'] += $cert['cost'];
        }
    }
    foreach ($cart_data['products'] as &$product) {
        if (!empty($product['extra']['points_info']['reward']) && !is_array($product['extra']['points_info']['reward'])) {
            $product['extra']['points_info']['reward'] = array('amount' => $product['extra']['points_info']['reward']);
        }
        if (isset($product['extra']['points_info']) && Registry::get('addons.reward_points.status') != 'A') {
            unset($product['extra']['points_info']);
        }
    }
    if (!empty($cart['points_info'])) {
        $cart_data['points_info'] = $cart['points_info'];
    }
    return $cart_data;
}
Exemplo n.º 2
0
     $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();
     if (!empty($payment_methods['payment'])) {
         foreach ($payment_methods['payment'] as $k => $v) {
             if ($options = fn_twg_get_payment_options($v['payment_id'])) {
                 $payment_methods['payment'][$k]['options'] = $options;
             }
         }
         $cart['recalculate'] = true;
         $cart['calculate_shipping'] = true;
         Registry::set('runtime.controller', 'checkout', true);
         fn_calculate_cart_content($cart, $auth, 'E', true, 'F', true);
         Registry::set('runtime.controller', 'twigmo');
         $response->setData(array('payments' => $payment_methods['payment'], 'cart' => fn_twg_api_get_session_cart($cart, $lang_code)));
     }
 } elseif ($meta['object'] == 'shipping_methods') {
     $_SESSION['cart']['calculate_shipping'] = true;