Esempio n. 1
0
     $cart['calculate_shipping'] = true;
 }
 if (!empty($_REQUEST['active_tab'])) {
     $active_tab = $_REQUEST['active_tab'];
     Tygh::$app['view']->assign('active_tab', $active_tab);
 }
 if (floatval($cart['total']) == 0 || !isset($cart['payment_id'])) {
     $cart['payment_id'] = 0;
 }
 $shipping_calculation_type = Registry::get('settings.General.estimate_shipping_cost') == 'Y' || $completed_steps['step_two'] ? 'A' : 'S';
 list($cart_products, $product_groups) = fn_calculate_cart_content($cart, $auth, $shipping_calculation_type, true, 'F');
 $payment_methods = fn_prepare_checkout_payment_methods($cart, $auth);
 if (!empty($payment_methods)) {
     $first_methods_group = reset($payment_methods);
     $first_method = reset($first_methods_group);
     $checkout_buttons = fn_get_checkout_payment_buttons($cart, $cart_products, $auth);
     if (!empty($checkout_buttons)) {
         Tygh::$app['view']->assign('checkout_buttons', $checkout_buttons, false);
     }
 } else {
     $first_method = false;
 }
 // Edit step postprocessing
 if ($recheck_edit_step) {
     if ($cart['edit_step'] == 'step_one' && $completed_steps['step_one']) {
         $cart['edit_step'] = 'step_two';
     }
 }
 if ($cart['edit_step'] == 'step_two' && $completed_steps['step_two'] && empty($_REQUEST['from_step'])) {
     if ($display_steps['step_three']) {
         $cart['edit_step'] = 'step_three';
Esempio n. 2
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;
}