Example #1
0
/**
 * Prepare all settings, wich should be passed to js
 */
function fn_twg_get_all_settings()
{
    $settings = fn_twg_get_boot_settings();
    $addon_settings = TwigmoSettings::get();
    $settings['access_id'] = $addon_settings['access_id'];
    $settings['currency'] = Registry::get('currencies.' . CART_SECONDARY_CURRENCY);
    $settings['primaryCurrency'] = Registry::get('currencies.' . CART_PRIMARY_CURRENCY);
    $settings['url_for_facebook'] = isset($addon_settings['url_for_facebook']) ? fn_twg_get_external_info_url($addon_settings['url_for_facebook']) : '';
    $settings['url_for_twitter'] = isset($addon_settings['url_for_twitter']) ? fn_twg_get_external_info_url($addon_settings['url_for_twitter']) : '';
    $settings['lang'] = array_merge(fn_twg_get_default_customer_langvars(), Lang::getCustomerLangVars());
    // Countries/states
    list($countries) = fn_get_countries(array('only_avail' => true));
    $settings = array_merge($settings, Api::getAsList('countries', $countries));
    $settings['states'] = fn_twg_get_states();
    // Info pages
    $pages_location = $addon_settings['home_page_content'] == 'tw_home_page_blocks' ? 'twigmo.post' : 'index.index';
    $pages = TwigmoBlock::getBlocksForLocation($pages_location, array('pages'));
    $settings['info_pages'] = array();
    foreach ($pages as $page) {
        $settings['info_pages'] = array_merge($settings['info_pages'], $page['pages']['page']);
    }
    // If page link begin with # then interpret this link as twigmo page
    foreach ($settings['info_pages'] as $k => $page) {
        if (preg_match('/^\\#.*$/', $page['link'])) {
            $settings['info_pages'][$k]['twigmo_page'] = substr($page['link'], 1);
        }
    }
    // Only required profile fields
    $only_required = isset($addon_settings['only_req_profile_fields']) ? $addon_settings['only_req_profile_fields'] : 'N';
    $settings['profileFields'] = fn_twg_prepare_profile_fields(fn_get_profile_fields(), $only_required);
    $settings['profileFieldsCheckout'] = fn_twg_prepare_profile_fields(fn_get_profile_fields('O'), $only_required);
    $settings['show_product_code'] = isset($addon_settings['show_product_code']) ? $addon_settings['show_product_code'] : 'N';
    $settings['titles'] = array();
    $settings['profile'] = fn_twg_get_user_info($_SESSION['auth']['user_id']);
    $settings['cart'] = fn_twg_api_get_session_cart($_SESSION['cart']);
    $settings['sortings'] = fn_twg_get_sortings();
    $settings['security_hash'] = fn_generate_security_hash();
    $settings['productType'] = PRODUCT_EDITION;
    $settings['languages'] = array_values(Lang::getLanguages());
    $settings['cart_language'] = CART_LANGUAGE;
    $settings['cart_prices_w_taxes'] = Registry::get('settings.Appearance.cart_prices_w_taxes');
    $settings['show_prices_taxed_clean'] = Registry::get('settings.Appearance.show_prices_taxed_clean');
    $settings['no_image_path'] = Registry::get('config.no_image_path');
    // Suppliers
    $settings['suppliers_vendor'] = Registry::get('settings.Suppliers.apply_for_vendor');
    $settings['display_supplier'] = Registry::get('settings.Suppliers.display_supplier') === 'Y' || Registry::get('settings.Vendors.display_vendor') === 'Y';
    $settings['display_supplier'] = $settings['display_supplier'] ? 'Y' : 'N';
    // General section
    $fields = array('use_email_as_login', 'min_order_amount', 'min_order_amount_type', 'allow_negative_amount', 'inventory_tracking', 'allow_anonymous_shopping', 'tax_calculation');
    foreach ($fields as $field) {
        $settings[$field] = Registry::get('settings.General.' . $field);
    }
    $settings = array_merge($settings, fn_twg_get_checkout_settings());
    if (version_compare(PRODUCT_VERSION, '4.0.2', '>=')) {
        $anonymous_shopping_settings_map = array('allow_shopping' => 'Y', 'hide_price_and_add_to_cart' => 'P', 'hide_add_to_cart' => 'B');
        $settings['allow_anonymous_shopping'] = $anonymous_shopping_settings_map[$settings['allow_anonymous_shopping']];
    }
    $settings['default_location'] = array('country' => Registry::get('settings.General.default_country'), 'state' => Registry::get('settings.General.default_state'));
    $settings['show_modifiers'] = Registry::get('settings.General.display_options_modifiers');
    $settings['SEOEnabled'] = Registry::get('addons.seo.status') == 'A';
    $settings['GATrackEcommerce'] = Registry::get('addons.google_analytics.status') == 'A' && Registry::get('addons.google_analytics.track_ecommerce') == 'Y' && file_exists(Registry::get('config.dir.addons') . 'google_analytics/controllers/frontend/checkout.post.php');
    if (fn_allowed_for('MULTIVENDOR')) {
        $settings['company_data'] = !empty($_SESSION['auth']['company_id']) ? fn_get_company_data($_SESSION['auth']['company_id']) : array();
    } else {
        $settings['company_data'] = array();
    }
    $settings['checkout'] = Registry::get('settings.Checkout');
    fn_set_hook('twg_get_all_settings', $settings);
    $settings['lang'] = fn_twg_process_langvars($settings['lang']);
    return $settings;
}
Example #2
0
     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;
     $params = array('cart' => &$_SESSION['cart'], 'auth' => &$_SESSION['auth']);
     Registry::set('runtime.controller', 'checkout', true);
     $product_groups = fn_twg_api_get_shippings($params);
     Registry::set('runtime.controller', 'twigmo');
     $shipping_methods = Api::getAsList('companies_rates', $product_groups);
     $shipping_methods['shipping_failed'] = !empty($_SESSION['cart']['shipping_failed']) ? $_SESSION['cart']['shipping_failed'] : false;
     $response->setData($shipping_methods);
 } elseif ($meta['object'] == 'product_files') {
     $file_url = array('fileUrl' => fn_url("orders.get_file&ekey=" . $_REQUEST['ekey'] . "&file_id=" . $_REQUEST['file_id'] . "&product_id=" . $_REQUEST['product_id'], AREA, 'rel'));
     $response->setData($file_url);
 } elseif ($meta['object'] == 'errors') {
     $response->returnResponse();