Esempio n. 1
0
 public static function downloadDistr()
 {
     // Get needed version
     $version_info = self::GetNextVersionInfo();
     if (!$version_info['next_version'] || !$version_info['update_url']) {
         return false;
     }
     $download_file_dir = TWIGMO_UPGRADE_DIR . $version_info['next_version'] . '/';
     $download_file_path = $download_file_dir . 'twigmo.tgz';
     $unpack_path = $download_file_path . '_unpacked';
     fn_rm($download_file_dir);
     fn_mkdir($download_file_dir);
     fn_mkdir($unpack_path);
     $data = fn_get_contents($version_info['update_url']);
     if (!fn_is_empty($data)) {
         fn_put_contents($download_file_path, $data);
         $res = fn_decompress_files($download_file_path, $unpack_path);
         if (!$res) {
             fn_set_notification('E', __('error'), __('twgadmin_failed_to_decompress_files'));
             return false;
         }
         return $unpack_path . '/';
     } else {
         fn_set_notification('E', __('error'), __('text_uc_cant_download_package'));
         return false;
     }
 }
Esempio n. 2
0
 public function write($type, $object, $message = '')
 {
     $data = array(0 => '', 1 => '', 2 => '');
     if ($type == self::SKIP_PRODUCT) {
         $product_name = fn_substr($object['product'], 0, 20);
         if (strlen($object['product']) > 20) {
             $product_name .= "...";
         }
         $data[0] = '[SKIP PRODUCT]';
         $data[1] = $object['product_id'] . " (" . $product_name . ") - ";
         $data[2] = $message;
     } elseif ($type == self::INFO) {
         $data[0] = '[INFO]';
         if (!is_array($object)) {
             $data[1] = $object;
         }
         if (!empty($message)) {
             $data[2] = $message;
         }
     }
     if (!fn_is_empty($data)) {
         if ($this->format == 'csv') {
             fwrite($this->file, $this->csv($data) . PHP_EOL);
         } else {
             fwrite($this->file, implode(' ', $data) . PHP_EOL);
         }
     }
 }
Esempio n. 3
0
function fn_send_sms_notification($body)
{
    $access_data = fn_get_sms_auth_data();
    $to = Registry::get('addons.sms_notifications.phone_number');
    if (fn_is_empty($access_data) || empty($to)) {
        return false;
    }
    $concat = Registry::get('addons.sms_notifications.clickatel_concat');
    //get the last symbol
    if (!empty($concat)) {
        $concat = intval($concat[strlen($concat) - 1]);
    }
    if (!in_array($concat, array('1', '2', '3'))) {
        $concat = 1;
    }
    $data = array('user' => $access_data['login'], 'password' => $access_data['password'], 'api_id' => $access_data['api_id'], 'to' => $to, 'concat' => $concat);
    $unicode = Registry::get('addons.sms_notifications.clickatel_unicode') == 'Y' ? 1 : 0;
    $sms_length = $unicode ? SMS_NOTIFICATIONS_SMS_LENGTH_UNICODE : SMS_NOTIFICATIONS_SMS_LENGTH;
    if ($concat > 1) {
        $sms_length *= $concat;
        $sms_length -= $concat * SMS_NOTIFICATIONS_SMS_LENGTH_CONCAT;
        // If a message is concatenated, it reduces the number of characters contained in each message by 7
    }
    $body = html_entity_decode($body, ENT_QUOTES, 'UTF-8');
    $body = fn_substr($body, 0, $sms_length);
    if ($unicode) {
        $data['unicode'] = '1';
        $body = fn_convert_encoding('UTF-8', 'UCS-2', $body);
        $body = bin2hex($body);
    }
    $data['text'] = $body;
    Http::get('http://api.clickatell.com/http/sendmsg', $data);
}
Esempio n. 4
0
 function fn_exim_set_product_categories($product_id, $link_type, $data, $category_delimiter, $lang_code = CART_LANGUAGE)
 {
     if (empty($data)) {
         return false;
     }
     $set_delimiter = ';';
     $paths = array();
     $updated_categories = array();
     // Check if array is provided
     if (strpos($data, $set_delimiter) !== false) {
         $paths = explode($set_delimiter, $data);
         array_walk($paths, 'fn_trim_helper');
     } else {
         $paths[] = $data;
     }
     if (!fn_is_empty($paths)) {
         $old_data = db_get_hash_array("SELECT * FROM ?:products_categories WHERE product_id= ?i", 'category_id', $product_id);
         foreach ($old_data as $k => $v) {
             if ($v['link_type'] == $link_type) {
                 $updated_categories[] = $k;
             }
         }
         db_query("DELETE FROM ?:products_categories WHERE product_id = ?i AND link_type = ?s", $product_id, $link_type);
     }
     foreach ($paths as $category) {
         $categories = strpos($category, $category_delimiter) !== false ? explode($category_delimiter, $category) : array($category);
         if (!empty($categories)) {
             $parent_id = '0';
             foreach ($categories as $cat) {
                 $category_id = db_get_field("SELECT ?:categories.category_id FROM ?:category_descriptions INNER JOIN ?:categories ON ?:categories.category_id = ?:category_descriptions.category_id WHERE ?:category_descriptions.category = ?s AND lang_code = ?s AND parent_id = ?i", $cat, $lang_code, $parent_id);
                 if (!empty($category_id)) {
                     $parent_id = $category_id;
                 } else {
                     $category_data = array('parent_id' => $parent_id, 'category' => $cat);
                     $category_id = fn_update_category($category_data);
                     $parent_id = $category_id;
                 }
             }
             $data = array('product_id' => $product_id, 'category_id' => $category_id, 'link_type' => $link_type);
             if (!empty($old_data) && !empty($old_data[$category_id])) {
                 $data = fn_array_merge($old_data[$category_id], $data);
             }
             db_query("REPLACE INTO ?:products_categories ?e", $data);
             $updated_categories[] = $category_id;
         }
     }
     if (!empty($updated_categories)) {
         fn_update_product_count($updated_categories);
         return true;
     }
     return false;
 }
Esempio n. 5
0
function fn_statistics_get_banners(&$banners)
{
    if (AREA == 'C' && !fn_is_empty($banners) && !defined('AJAX_REQUEST')) {
        foreach ($banners as $k => $v) {
            if ($v['type'] == 'T' && !empty($v['description'])) {
                $i = $pos = 0;
                $matches = array();
                while (preg_match('/href=([\'|"])(.*?)([\'|"])/i', $banners[$k]['description'], $matches, PREG_OFFSET_CAPTURE, $pos)) {
                    $banners[$k]['description'] = substr_replace($banners[$k]['description'], fn_url("statistics.banners?banner_id={$v['banner_id']}&link=" . $i++, 'C'), $matches[2][1], strlen($matches[2][0]));
                    $pos = $matches[2][1];
                }
            } elseif (!empty($v['url'])) {
                $banners[$k]['url'] = "statistics.banners?banner_id={$v['banner_id']}";
            }
            db_query('INSERT INTO ?:stat_banners_log ?e', array('banner_id' => $v['banner_id'], 'type' => 'V', 'timestamp' => TIME));
        }
    } else {
        return false;
    }
}
    function content_55e354516160e0_24473059($_smarty_tpl)
    {
        if (!is_callable('smarty_modifier_date_format')) {
            include '/home/coriolan/public_html/lead/app/functions/smarty_plugins/modifier.date_format.php';
        }
        fn_preload_lang_vars(array('text_items_added', 'id', 'name', 'email', 'registered', 'active', 'disable', 'active', 'no_data', 'no_data', 'choose', 'add_companies_and_close', 'add_companies'));
        if (!$_REQUEST['extra']) {
            ?>
<script type="text/javascript">
(function(_, $) {

    _.tr('text_items_added', '<?php 
            echo strtr($_smarty_tpl->__("text_items_added"), array("\\" => "\\\\", "'" => "\\'", "\"" => "\\\"", "\r" => "\\r", "\n" => "\\n", "</" => "<\\/"));
            ?>
');
    var display_type = '<?php 
            echo strtr($_REQUEST['display'], array("\\" => "\\\\", "'" => "\\'", "\"" => "\\\"", "\r" => "\\r", "\n" => "\\n", "</" => "<\\/"));
            ?>
';

    $.ceEvent('on', 'ce.formpost_companies_form', function(frm, elm) {
        var companies = {};

        if ($('input.cm-item:checked', frm).length > 0) {
            $('input.cm-item:checked', frm).each( function() {
                var id = $(this).val();
                companies[id] = $('#company_' + id).text();
            });

            
            $.cePicker('add_js_item', frm.data('caResultId'), companies, 'm', {
                '{company_id}': '%id',
                '{company}': '%item'
            });
            

            if (display_type != 'radio') {
                $.ceNotification('show', {
                    type: 'N', 
                    title: _.tr('notice'), 
                    message: _.tr('text_items_added'), 
                    message_state: 'I'
                });
            }
        }

        return false;        
    });
}(Tygh, Tygh.$));
</script>
<?php 
        }
        ?>

<?php 
        echo $_smarty_tpl->getSubTemplate("views/companies/components/companies_search_form.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('dispatch' => "companies.picker", 'extra' => "<input type=\"hidden\" name=\"result_ids\" value=\"pagination_" . (string) $_REQUEST['data_id'] . "\">", 'put_request_vars' => true, 'form_meta' => "cm-ajax", 'in_popup' => true), 0);
        ?>


<form action="<?php 
        echo htmlspecialchars(fn_url($_REQUEST['extra']), ENT_QUOTES, 'UTF-8');
        ?>
" data-ca-result-id="<?php 
        echo htmlspecialchars($_REQUEST['data_id'], ENT_QUOTES, 'UTF-8');
        ?>
" method="post" name="companies_form">

<?php 
        echo $_smarty_tpl->getSubTemplate("common/pagination.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('div_id' => "pagination_" . (string) $_REQUEST['data_id']), 0);
        ?>


<table width="100%" class="table table-middle">
<thead>
<tr>
    <th width="1%" class="center">
        <?php 
        if ($_REQUEST['display'] != "radio") {
            ?>
        <?php 
            echo $_smarty_tpl->getSubTemplate("common/check_items.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array(), 0);
            ?>
</th>
        <?php 
        }
        ?>
    <th><?php 
        echo $_smarty_tpl->__("id");
        ?>
</th>
    <th><?php 
        echo $_smarty_tpl->__("name");
        ?>
</th>
    <?php 
        if (!fn_allowed_for("ULTIMATE")) {
            ?>
        <th><?php 
            echo $_smarty_tpl->__("email");
            ?>
</th>
    <?php 
        }
        ?>
    <th><?php 
        echo $_smarty_tpl->__("registered");
        ?>
</th>
    <?php 
        if (!fn_allowed_for("ULTIMATE")) {
            ?>
        <th class="right"><?php 
            echo $_smarty_tpl->__("active");
            ?>
</th>
    <?php 
        }
        ?>
</tr>
</thead>
<?php 
        $_smarty_tpl->tpl_vars['company'] = new Smarty_Variable();
        $_smarty_tpl->tpl_vars['company']->_loop = false;
        $_from = $_smarty_tpl->tpl_vars['companies']->value;
        if (!is_array($_from) && !is_object($_from)) {
            settype($_from, 'array');
        }
        foreach ($_from as $_smarty_tpl->tpl_vars['company']->key => $_smarty_tpl->tpl_vars['company']->value) {
            $_smarty_tpl->tpl_vars['company']->_loop = true;
            ?>
<tr>
    <td class="center">
        <?php 
            if ($_REQUEST['display'] == "radio") {
                ?>
        <input type="radio" name="<?php 
                echo htmlspecialchars(($tmp = @$_REQUEST['checkbox_name']) === null || $tmp === '' ? "companies_ids" : $tmp, ENT_QUOTES, 'UTF-8');
                ?>
" value="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['company']->value['company_id'], ENT_QUOTES, 'UTF-8');
                ?>
" class="radio" />
        <?php 
            } else {
                ?>
        <input type="checkbox" name="<?php 
                echo htmlspecialchars(($tmp = @$_REQUEST['checkbox_name']) === null || $tmp === '' ? "companies_ids" : $tmp, ENT_QUOTES, 'UTF-8');
                ?>
[<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['company']->value['company_id'], ENT_QUOTES, 'UTF-8');
                ?>
]" value="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['company']->value['company_id'], ENT_QUOTES, 'UTF-8');
                ?>
" class="checkbox cm-item" />
        <?php 
            }
            ?>
    </td>
    <td><a href="<?php 
            echo htmlspecialchars(fn_url("companies.update?company_id=" . (string) $_smarty_tpl->tpl_vars['company']->value['company_id']), ENT_QUOTES, 'UTF-8');
            ?>
">&nbsp;<span><?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['company']->value['company_id'], ENT_QUOTES, 'UTF-8');
            ?>
</span>&nbsp;</a></td>
    <td><a id="company_<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['company']->value['company_id'], ENT_QUOTES, 'UTF-8');
            ?>
" href="<?php 
            echo htmlspecialchars(fn_url("companies.update?company_id=" . (string) $_smarty_tpl->tpl_vars['company']->value['company_id']), ENT_QUOTES, 'UTF-8');
            ?>
"><?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['company']->value['company'], ENT_QUOTES, 'UTF-8');
            ?>
</a></td>
    <?php 
            if (!fn_allowed_for("ULTIMATE")) {
                ?>
        <td><a href="mailto:<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['company']->value['email'], ENT_QUOTES, 'UTF-8');
                ?>
"><?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['company']->value['email'], ENT_QUOTES, 'UTF-8');
                ?>
</a></td>
    <?php 
            }
            ?>
    <td><?php 
            echo htmlspecialchars(smarty_modifier_date_format($_smarty_tpl->tpl_vars['company']->value['timestamp'], (string) $_smarty_tpl->tpl_vars['settings']->value['Appearance']['date_format'] . ", " . (string) $_smarty_tpl->tpl_vars['settings']->value['Appearance']['time_format']), ENT_QUOTES, 'UTF-8');
            ?>
</td>
    <?php 
            if (!fn_allowed_for("ULTIMATE")) {
                ?>
        <td class="right"><?php 
                if ($_smarty_tpl->tpl_vars['company']->value['status'] != "A") {
                    echo $_smarty_tpl->__("disable");
                } else {
                    echo $_smarty_tpl->__("active");
                }
                ?>
</td>
    <?php 
            }
            ?>
</tr>
<?php 
        }
        if (!$_smarty_tpl->tpl_vars['company']->_loop) {
            ?>
<tr class="no-items">
    <?php 
            if (!fn_allowed_for("ULTIMATE")) {
                ?>
        <td colspan="6"><p><?php 
                echo $_smarty_tpl->__("no_data");
                ?>
</p></td>
    <?php 
            } else {
                ?>
        <td colspan="4"><p><?php 
                echo $_smarty_tpl->__("no_data");
                ?>
</p></td>
    <?php 
            }
            ?>
</tr>
<?php 
        }
        ?>
</table>

<?php 
        echo $_smarty_tpl->getSubTemplate("common/pagination.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('div_id' => "pagination_" . (string) $_REQUEST['data_id']), 0);
        ?>


<div class="buttons-container">
    <?php 
        if ($_REQUEST['display'] == "radio") {
            ?>
        <?php 
            $_smarty_tpl->tpl_vars["but_close_text"] = new Smarty_variable($_smarty_tpl->__("choose"), null, 0);
            ?>
    <?php 
        } else {
            ?>
        <?php 
            $_smarty_tpl->tpl_vars["but_close_text"] = new Smarty_variable($_smarty_tpl->__("add_companies_and_close"), null, 0);
            ?>
        <?php 
            $_smarty_tpl->tpl_vars["but_text"] = new Smarty_variable($_smarty_tpl->__("add_companies"), null, 0);
            ?>
    <?php 
        }
        ?>
    <?php 
        echo $_smarty_tpl->getSubTemplate("buttons/add_close.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('is_js' => fn_is_empty($_REQUEST['extra'])), 0);
        ?>

</div>

</form>
<?php 
    }
Esempio n. 7
0
             return array(CONTROLLER_STATUS_OK, 'categories.update?category_id=' . $_REQUEST['category_id']);
         }
     }
     $category_id = fn_update_category($_REQUEST['category_data'], $_REQUEST['category_id'], DESCR_SL);
     if (!empty($category_id)) {
         fn_attach_image_pairs('category_main', 'category', $category_id, DESCR_SL);
         $suffix = ".update?category_id={$category_id}" . (!empty($_REQUEST['category_data']['block_id']) ? "&selected_block_id=" . $_REQUEST['category_data']['block_id'] : "");
     } else {
         $suffix = '.manage';
     }
 }
 //
 // Processing mulitple addition of new category elements
 //
 if ($mode == 'm_add') {
     if (!fn_is_empty($_REQUEST['categories_data'])) {
         $is_added = false;
         foreach ($_REQUEST['categories_data'] as $k => $v) {
             if (!empty($v['category'])) {
                 // Checking for required fields for new category
                 if (fn_update_category($v)) {
                     $is_added = true;
                 }
             }
         }
         if ($is_added) {
             fn_set_notification('N', __('notice'), __('categories_have_been_added'));
         }
     }
     $suffix = ".manage";
 }
Esempio n. 8
0
     $parent = true;
 }
 $offer_type_parent_category = array();
 if (!empty($category_id)) {
     $offer_type_parent_category = fn_yml_get_parent_categories_field('yml2_offer_type', $category_id, $parent);
     $yml2_model_category = fn_yml_get_parent_categories_field('yml2_model', $category_id, $parent);
     $yml2_type_prefix_category = fn_yml_get_parent_categories_field('yml2_type_prefix', $category_id, $parent);
     $yml2_market_category = fn_yml_get_parent_categories_field('yml2_market_category', $category_id, $parent);
     $yml2_parent_type_prefix_select = fn_yml_get_parent_categories_field('yml2_type_prefix_select', $category_id, $parent);
     $yml2_parent_type_prefix_select = explode('.', $yml2_parent_type_prefix_select);
     if (fn_is_empty($yml2_parent_type_prefix_select)) {
         $yml2_parent_type_prefix_select = array();
     }
     $yml2_parent_model_select = fn_yml_get_parent_categories_field('yml2_model_select', $category_id, $parent);
     $yml2_parent_model_select = explode('.', $yml2_parent_model_select);
     if (fn_is_empty($yml2_parent_model_select)) {
         $yml2_parent_model_select = array();
     }
     Tygh::$app['view']->assign('yml2_model_category', $yml2_model_category);
     Tygh::$app['view']->assign('yml2_type_prefix_category', $yml2_type_prefix_category);
     Tygh::$app['view']->assign('yml2_market_category', $yml2_market_category);
     Tygh::$app['view']->assign('yml2_parent_type_prefix_select', $yml2_parent_type_prefix_select);
     Tygh::$app['view']->assign('yml2_parent_model_select', $yml2_parent_model_select);
 }
 $offer_types = fn_get_schema('yml', 'offer_types');
 unset($offer_types['common']);
 Tygh::$app['view']->assign('yml2_offer_types', $offer_types);
 Tygh::$app['view']->assign('offer_type_parent_category', $offer_type_parent_category);
 if (!empty($offer_type_parent_category)) {
     Tygh::$app['view']->assign('offer_type_parent_name', $offer_types[$offer_type_parent_category]);
 }
function fn_paypal_apply_discount($data, &$order_data, $product_index)
{
    $discount_applied = false;
    if (!fn_is_empty(floatval($data['subtotal_discount']))) {
        $order_data['L_PAYMENTREQUEST_0_NAME' . $product_index] = __('discount');
        $order_data['L_PAYMENTREQUEST_0_QTY' . $product_index] = 1;
        $order_data['L_PAYMENTREQUEST_0_AMT' . $product_index] = -$data['subtotal_discount'];
        $discount_applied = true;
    }
    fn_set_hook('paypal_apply_discount_post', $data, $order_data, $product_index, $discount_applied);
}
Esempio n. 10
0
     $cart['chosen_shipping'] = array();
     if (!empty($_REQUEST['shipping_ids'])) {
         fn_checkout_update_shipping($cart, $_REQUEST['shipping_ids']);
     }
     $cart['calculate_shipping'] = true;
     list($cart_products, $product_groups) = fn_calculate_cart_content($cart, $auth, 'A', true, 'F', true);
     if (Registry::get('settings.Checkout.display_shipping_step') != 'Y' && fn_allowed_for('ULTIMATE')) {
         Tygh::$app['view']->assign('show_only_first_shipping', true);
     }
     Tygh::$app['view']->assign('product_groups', $cart['product_groups']);
     Tygh::$app['view']->assign('cart', $cart);
     Tygh::$app['view']->assign('cart_products', array_reverse($cart_products, true));
     Tygh::$app['view']->assign('location', empty($_REQUEST['location']) ? 'cart' : $_REQUEST['location']);
     Tygh::$app['view']->assign('additional_id', empty($_REQUEST['additional_id']) ? '' : $_REQUEST['additional_id']);
     if (defined('AJAX_REQUEST')) {
         if (fn_is_empty($cart_products) && fn_is_empty($cart['product_groups'])) {
             Tygh::$app['ajax']->assignHtml('shipping_estimation_sidebox' . (empty($_REQUEST['additional_id']) ? '' : '_' . $_REQUEST['additional_id']), __('no_rates_for_empty_cart'));
         } else {
             Tygh::$app['view']->display(empty($_REQUEST['location']) ? 'views/checkout/components/checkout_totals.tpl' : 'views/checkout/components/shipping_estimation.tpl');
         }
         exit;
     }
     $redirect_mode = !empty($_REQUEST['current_mode']) ? $_REQUEST['current_mode'] : 'cart';
     return array(CONTROLLER_STATUS_OK, 'checkout.' . $redirect_mode . '?show_shippings=Y');
 }
 if ($mode == 'update_shipping') {
     if (!empty($_REQUEST['shipping_ids'])) {
         fn_checkout_update_shipping($cart, $_REQUEST['shipping_ids']);
     }
     return array(CONTROLLER_STATUS_OK, 'checkout.' . $_REQUEST['redirect_mode']);
 }
Esempio n. 11
0
 * This source file is subject to the EULA
 * that is bundled with this package in the file CR-LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.cscartrocks.com/CR-LICENSE.txt
 *
 * @copyright  Copyright (c) 2010 cscartrocks.com
 * @license    http://www.cscartrocks.com/CR-LICENSE.txt
 */
use Tygh\Registry;
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    if ($mode == 'place_order' || $mode == 'subscribe_customer') {
        $subscriber = db_get_row("SELECT * FROM ?:subscribers WHERE email = ?s", $_SESSION['cart']['user_data']['email']);
        if (!empty($_REQUEST['mailing_lists']) && !fn_is_empty($_REQUEST['mailing_lists'])) {
            if (empty($subscriber)) {
                $_data = array('email' => $_SESSION['cart']['user_data']['email'], 'timestamp' => TIME);
                $subscriber_id = db_query("INSERT INTO ?:subscribers ?e", $_data);
            } else {
                $subscriber_id = $subscriber['subscriber_id'];
            }
            fn_update_subscriptions($subscriber_id, $_REQUEST['mailing_lists'], NULL, fn_get_notification_rules(true));
        } elseif (isset($_REQUEST['mailing_lists'])) {
            if (!empty($subscriber)) {
                fn_delete_subscribers($subscriber['subscriber_id']);
            }
        }
    }
    if ($mode == 'subscribe_customer') {
        return array(CONTROLLER_STATUS_REDIRECT, 'onestepcheckout.checkout');
Esempio n. 12
0
     $table_conditions[$table['table_id']] = fn_reports_get_conditions($_table_cond);
 }
 $_values = fn_get_report_statistics($table);
 $report['tables'][$table_id]['values'] = $_values;
 // Calculate totals
 $report['tables'][$table_id]['totals'] = array();
 foreach ($_values as $v) {
     foreach ($v as $_k => $_v) {
         $report['tables'][$table_id]['totals'][$_k] = empty($report['tables'][$table_id]['totals'][$_k]) ? $_v : $report['tables'][$table_id]['totals'][$_k] + $_v;
     }
 }
 $_element_id = db_get_field("SELECT element_id FROM ?:sales_reports_table_elements WHERE table_id = ?i", $table['table_id']);
 if (!empty($_element_id)) {
     $report['tables'][$table_id]['parameter'] = __("reports_parameter_{$_element_id}");
 }
 if (fn_is_empty($_values)) {
     $report['tables'][$table_id]['empty_values'] = 'Y';
 }
 // Find max value
 $_max = 0;
 foreach (@$_values as $kkk => $vvv) {
     foreach ($vvv as $kk => $vv) {
         if ($vv > $_max) {
             $_max = $vv;
         }
     }
 }
 $report['tables'][$table_id]['max_value'] = $_max;
 if ($table['type'] == 'B' && $intervals_limits[count($table['elements'])] < count($table['intervals'])) {
     $report['tables'][$table_id]['pages'] = ceil(count($table['intervals']) / $intervals_limits[count($table['elements'])]);
 }
Esempio n. 13
0
function fn_gift_certificates_exclude_products_from_calculation(&$cart, &$auth, &$pure_subtotal, &$subtotal)
{
    if (isset($cart['gift_certificates']) && !fn_is_empty($cart['gift_certificates'])) {
        foreach ($cart['gift_certificates'] as $k => $v) {
            if (isset($v['extra']['exclude_from_calculate'])) {
                unset($cart['gift_certificates'][$k]);
            } else {
                $subtotal += $v['amount'];
                $pure_subtotal += $v['amount'];
            }
        }
    }
    if (!empty($cart['use_gift_certificates'])) {
        foreach ($cart['use_gift_certificates'] as $code => $value) {
            // This step is performed when editing the existent order only.
            if (is_array($value) && isset($value['log_id'])) {
                // indicates that the order is being edited
                $gift_cert_data = $value;
                // Merge with the current balance.
                $last_log_item = db_get_row("SELECT log_id, debit, debit_products FROM ?:gift_certificates_log WHERE gift_cert_id = ?i ORDER BY log_id DESC", $value['gift_cert_id']);
                $last_log_item['debit_products'] = unserialize($last_log_item['debit_products']);
                $gift_cert_data['amount'] = $gift_cert_data['previous_state']['cost'] + $last_log_item['debit'];
                if (!empty($last_log_item['debit_products'])) {
                    foreach ($last_log_item['debit_products'] as $product_id => $quantity) {
                        if (!isset($gift_cert_data['products'][$product_id])) {
                            $gift_cert_data['products'][$product_id] = $quantity['amount'];
                        } else {
                            $gift_cert_data['products'][$product_id] = (isset($gift_cert_data['previous_state']['products'][$product_id]) ? $gift_cert_data['previous_state']['products'][$product_id] : 0) + $quantity['amount'];
                        }
                    }
                }
                $cart['use_gift_certificates_previous_state'][$code] = $gift_cert_data;
                // This step is performed when editing the existent order only.
            } elseif (defined('ORDER_MANAGEMENT') && !empty($cart['use_gift_certificates_previous_state'][$code])) {
                //
                // If the certificate was deleted when editing, and then it was applied again.
                // It is necessary to set its data (not currect ones) again with the performed changes.
                //
                $gift_cert_data = $cart['use_gift_certificates_previous_state'][$code];
                // This step is performed only on Create order and in the frontend.
            } else {
                $gift_cert_data = db_get_row("SELECT gift_cert_id, amount, products  FROM ?:gift_certificates WHERE gift_cert_code = ?s ?p", $code, fn_get_gift_certificate_company_condition('company_id'));
                if (!$gift_cert_data) {
                    return false;
                }
                $gift_cert_data['products'] = empty($gift_cert_data['products']) ? array() : @unserialize($gift_cert_data['products']);
                $debit_balance = db_get_row("SELECT debit AS amount, debit_products as products FROM ?:gift_certificates_log WHERE gift_cert_id = ?i ORDER BY log_id DESC", $gift_cert_data['gift_cert_id']);
                if (!empty($debit_balance)) {
                    $debit_balance['products'] = @unserialize($debit_balance['products']);
                    $gift_cert_data = fn_array_merge($gift_cert_data, $debit_balance);
                }
            }
            $cart['use_gift_certificates'][$code] = $gift_cert_data;
            if (!empty($gift_cert_data['products']) && AREA == 'C') {
                $product_data = array();
                foreach ((array) $gift_cert_data['products'] as $key => $product_item) {
                    if (!empty($debit_balance) && !isset($debit_balance['products'][$key])) {
                        continue;
                    }
                    $product_data[$product_item['product_id']] = array('product_id' => $product_item['product_id'], 'amount' => $product_item['amount'], 'extra' => array('exclude_from_calculate' => GIFT_CERTIFICATE_EXCLUDE_PRODUCTS, 'in_use_certificate' => array($code => $product_item['amount'])));
                    if (isset($product_item['product_options'])) {
                        $product_data[$product_item['product_id']]['product_options'] = $product_item['product_options'];
                    }
                    // Сhoose the option which the product had before editing.
                    if (!empty($value['log_id']) && !empty($value['product_options'][$product_id])) {
                        $product_data[$product_id]['product_options'] = $value['product_options'][$product_id];
                    }
                }
                fn_add_product_to_cart($product_data, $cart, $auth);
                $cart['recalculate'] = true;
            }
        }
    }
}
Esempio n. 14
0
 public function _addDellinCities($url_cities, $post)
 {
     $file_dir = fn_get_files_dir_path() . "dellin/";
     fn_mkdir($file_dir);
     @chmod($file_dir, 0777);
     $file_path = $file_dir . date("Y-m-d", TIME) . '_cities.csv';
     if (!file_exists($file_path)) {
         $response = Http::post($url_cities, json_encode($post), $this->url_params);
         $result = (array) json_decode($response);
         file_put_contents($file_path, file_get_contents($result['url']));
         if (!empty($result['url'])) {
             $max_line_size = 65536;
             // 64 Кб
             $data_city = array();
             $delimiter = ',';
             $encoding = fn_detect_encoding($result['url'], 'F', CART_LANGUAGE);
             if (!empty($encoding)) {
                 $result['url'] = fn_convert_encoding($encoding, 'UTF-8', $result['url'], 'F');
             } else {
                 fn_set_notification('W', __('warning'), __('text_exim_utf8_file_format'));
             }
             $f = false;
             if ($result['url'] !== false) {
                 $f = fopen($result['url'], 'rb');
             }
             if ($f) {
                 $import_schema = fgetcsv($f, $max_line_size, $delimiter);
                 $schema_size = sizeof($import_schema);
                 $skipped_lines = array();
                 $line_it = 1;
                 while (($data = fn_fgetcsv($f, $max_line_size, $delimiter)) !== false) {
                     $line_it++;
                     if (fn_is_empty($data)) {
                         continue;
                     }
                     if (sizeof($data) != $schema_size) {
                         $skipped_lines[] = $line_it;
                         continue;
                     }
                     $data = str_replace(array('\\r', '\\n', '\\t', '"'), '', $data);
                     $data_city = array_combine($import_schema, Bootstrap::stripSlashes($data));
                     if (!empty($data_city)) {
                         $dellin_city = array('number_city' => $data_city['id'], 'code_kladr' => str_replace(' ', '', $data_city['codeKLADR']), 'is_terminal' => $data_city['isTerminal']);
                         $first_pos = strpos($data_city['name'], '(');
                         $end_pos = strpos($data_city['name'], ')') - $first_pos;
                         if (!empty($first_pos)) {
                             $dellin_city['state'] = str_replace(array("(", ")"), "", substr($data_city['name'], $first_pos, $end_pos));
                             $dellin_city['city'] = str_replace(array('(' . $dellin_city['state'] . ')', '"'), "", $data_city['name']);
                         } else {
                             $dellin_city['state'] = str_replace(array('г.', 'г', 'г. ', 'г '), '', $data_city['name']);
                             $dellin_city['city'] = $data_city['name'];
                         }
                         $dellin_city['city_id'] = db_get_field("SELECT city_id FROM ?:rus_dellin_cities WHERE code_kladr = ?s", $dellin_city['code_kladr']);
                         db_query("REPLACE INTO ?:rus_dellin_cities ?e", $dellin_city);
                     }
                 }
             }
         }
     }
 }
Esempio n. 15
0
function fn_is_not_empty($var)
{
    return !fn_is_empty($var);
}
Esempio n. 16
0
function fn_calculate_tax_rates($taxes, $price, $amount, $auth, &$cart)
{
    static $destination_id;
    static $tax_description;
    static $user_data;
    $taxed_price = $price;
    if (!empty($cart['user_data']) && !fn_is_empty($cart['user_data'])) {
        $profile_fields = fn_get_profile_fields('O', $auth);
        $billing_population = fn_check_profile_fields_population($cart['user_data'], 'B', $profile_fields);
        $shipping_population = fn_check_profile_fields_population($cart['user_data'], 'S', $profile_fields);
        if (empty($auth['user_id']) && (!$shipping_population || !$billing_population)) {
            fn_define('ESTIMATION', true);
        }
    }
    if (empty($auth['user_id']) && (empty($cart['user_data']) || fn_is_empty($cart['user_data']) || $billing_population != true || $shipping_population != true) && Registry::get('runtime.checkout') && Registry::get('settings.Appearance.taxes_using_default_address') !== 'Y' && !defined('ESTIMATION')) {
        return false;
    }
    if (empty($destination_id) || $user_data != @$cart['user_data']) {
        // Get billing location
        $location = fn_get_customer_location($auth, $cart, true);
        $destination_id['B'] = fn_get_available_destination($location);
        // Get shipping location
        $location = fn_get_customer_location($auth, $cart);
        $destination_id['S'] = fn_get_available_destination($location);
    }
    if (!empty($cart['user_data'])) {
        $user_data = $cart['user_data'];
    }
    $_tax = 0;
    $previous_priority = -1;
    $previous_price = '';
    foreach ($taxes as $key => $tax) {
        if (empty($tax['tax_id'])) {
            $tax['tax_id'] = $key;
        }
        if (empty($tax['priority'])) {
            $tax['priority'] = 0;
        }
        $_is_zero = floatval($taxed_price);
        if (empty($_is_zero)) {
            continue;
        }
        if (!empty($cart['stored_taxes']) && $cart['stored_taxes'] == 'Y' && (!empty($tax['rate_type']) || isset($cart['taxes'][$tax['tax_id']]['rate_value']))) {
            $rate = array('rate_value' => isset($cart['taxes'][$tax['tax_id']]['rate_value']) ? $cart['taxes'][$tax['tax_id']]['rate_value'] : $tax['rate_value'], 'rate_type' => isset($cart['taxes'][$tax['tax_id']]['rate_type']) ? $cart['taxes'][$tax['tax_id']]['rate_type'] : $tax['rate_type']);
        } else {
            if (!isset($destination_id[$tax['address_type']])) {
                continue;
            }
            $rate = db_get_row("SELECT destination_id, rate_value, rate_type FROM ?:tax_rates WHERE tax_id = ?i AND destination_id = ?i", $tax['tax_id'], $destination_id[$tax['address_type']]);
            if (!@floatval($rate['rate_value'])) {
                continue;
            }
        }
        $base_price = $tax['priority'] == $previous_priority ? $previous_price : $taxed_price;
        if ($rate['rate_type'] == 'P') {
            // Percent dependence
            // If tax is included into the price
            if ($tax['price_includes_tax'] == 'Y') {
                $_tax = fn_format_price($base_price - $base_price / (1 + $rate['rate_value'] / 100));
                // If tax is NOT included into the price
            } else {
                $_tax = fn_format_price($base_price * ($rate['rate_value'] / 100));
                $taxed_price += $_tax;
            }
        } else {
            $_tax = fn_format_price($rate['rate_value']);
            // If tax is NOT included into the price
            if ($tax['price_includes_tax'] != 'Y') {
                $taxed_price += $_tax;
            }
        }
        $previous_priority = $tax['priority'];
        $previous_price = $base_price;
        if (empty($tax_description[$tax['tax_id']])) {
            $tax_description[$tax['tax_id']] = db_get_field("SELECT tax FROM ?:tax_descriptions WHERE tax_id = ?i AND lang_code = ?s", $tax['tax_id'], CART_LANGUAGE);
        }
        $taxes_data[$tax['tax_id']] = array('rate_type' => $rate['rate_type'], 'rate_value' => $rate['rate_value'], 'price_includes_tax' => $tax['price_includes_tax'], 'regnumber' => @$tax['regnumber'], 'priority' => @$tax['priority'], 'tax_subtotal' => fn_format_price($_tax * $amount), 'description' => $tax_description[$tax['tax_id']]);
    }
    return empty($taxes_data) ? false : $taxes_data;
}
Esempio n. 17
0
function fn_yml_update_price_list($price_id, $price_list)
{
    if (!empty($price_id)) {
        $price_list['price_id'] = $price_id;
    }
    if (!empty($price_list['delivery_options'])) {
        foreach ($price_list['delivery_options'] as $index => $delivery_option) {
            if (fn_is_empty($delivery_option)) {
                unset($price_list['delivery_options'][$index]);
            }
        }
        $price_list['delivery_options'] = array_slice($price_list['delivery_options'], 0, 5);
    }
    fn_yml_get_categories_data($price_list);
    $company_id = Registry::get('runtime.company_id');
    if (Registry::get('runtime.simple_ultimate')) {
        $company_id = Registry::get('runtime.forced_company_id');
    }
    $price_list['company_id'] = $company_id;
    $data = array('param_type' => 'price_list', 'param_key' => $price_list['access_key'], 'param_data' => serialize($price_list), 'company_id' => $company_id);
    if (!empty($price_id)) {
        $data['param_id'] = $price_id;
    }
    $new_price_id = db_query("INSERT INTO ?:yml_param ?e ON DUPLICATE KEY UPDATE ?u", $data, $data);
    return !empty($new_price_id) ? $new_price_id : $price_id;
}
Esempio n. 18
0
function fn_delete_rate_values($delete_rate_data, $shipping_id, $destination_id)
{
    $rate_values = db_get_field("SELECT rate_value FROM ?:shipping_rates WHERE shipping_id = ?i AND destination_id = ?i", $shipping_id, $destination_id);
    if (!empty($rate_values)) {
        $rate_values = unserialize($rate_values);
    }
    foreach ((array) $rate_values as $rate_type => $rd) {
        foreach ((array) $rd as $amount => $data) {
            if (isset($delete_rate_data[$rate_type][$amount]) && $delete_rate_data[$rate_type][$amount] == 'Y') {
                unset($rate_values[$rate_type][$amount]);
            }
        }
    }
    if (is_array($rate_values)) {
        foreach ($rate_values as $k => $v) {
            if (count($v) == 1 && floatval($v[0]['value']) == 0) {
                unset($rate_values[$k]);
                continue;
            }
        }
    }
    if (fn_is_empty($rate_values)) {
        db_query("DELETE FROM ?:shipping_rates WHERE shipping_id = ?i AND destination_id = ?i", $shipping_id, $destination_id);
    } else {
        db_query("UPDATE ?:shipping_rates SET ?u WHERE shipping_id = ?i AND destination_id = ?i", array('rate_value' => serialize($rate_values)), $shipping_id, $destination_id);
    }
}
Esempio n. 19
0
 //
 if ($mode == 'shipping_estimation') {
     $customer_location = empty($_REQUEST['customer_location']) ? array() : $_REQUEST['customer_location'];
     foreach ($customer_location as $k => $v) {
         $cart['user_data']['s_' . $k] = $v;
     }
     $_SESSION['customer_loc'] = $customer_location;
     $cart['recalculate'] = true;
     list($cart_products, $_SESSION['shipping_rates']) = fn_calculate_cart_content($cart, $auth, 'A', true, 'F', true);
     $view->assign('shipping_rates', $_SESSION['shipping_rates']);
     $view->assign('cart', $cart);
     $view->assign('cart_products', array_reverse($cart_products, true));
     $view->assign('location', empty($_REQUEST['location']) ? 'cart' : $_REQUEST['location']);
     $view->assign('additional_id', empty($_REQUEST['additional_id']) ? '' : $_REQUEST['additional_id']);
     if (defined('AJAX_REQUEST')) {
         if (fn_is_empty($cart_products) && fn_is_empty($_SESSION['shipping_rates'])) {
             $ajax->assign_html('shipping_estimation_sidebox' . (empty($_REQUEST['additional_id']) ? '' : '_' . $_REQUEST['additional_id']), fn_get_lang_var('no_rates_for_empty_cart'));
         } else {
             $view->display(empty($_REQUEST['location']) ? 'views/checkout/components/checkout_totals.tpl' : 'views/checkout/components/shipping_estimation.tpl');
         }
         exit;
     }
     $_suffix = '.' . (empty($_REQUEST['current_mode']) ? 'cart' : $_REQUEST['current_mode']) . '?show_shippings=Y';
 }
 if ($mode == 'update_shipping') {
     if (!empty($_REQUEST['shipping_ids'])) {
         fn_checkout_update_shipping($cart, $_REQUEST['shipping_ids']);
     }
     $_suffix = ".{$_REQUEST['redirect_mode']}";
 }
 // Apply Discount Coupon
Esempio n. 20
0
function fn_sdek_get_ticket_order($data_auth, $order_id, $chek_id)
{
    unset($data_auth['Number']);
    $xml = '            ' . RusSdek::arraySimpleXml('OrdersPrint', $data_auth, 'open');
    $order_sdek = array('Number' => $order_id . '_' . $chek_id, 'Date' => $data_auth['Date']);
    $xml .= '            ' . RusSdek::arraySimpleXml('Order', $order_sdek);
    $xml .= '            ' . '</OrdersPrint>';
    $response = RusSdek::xmlRequest('http://gw.edostavka.ru:11443/orders_print.php', $xml, $data_auth);
    $download_file_dir = fn_get_files_dir_path() . '/sdek' . '/' . $chek_id . '/';
    fn_rm($download_file_dir);
    fn_mkdir($download_file_dir);
    $name = $order_id . '.pdf';
    $download_file_path = $download_file_dir . $name;
    if (!fn_is_empty($response)) {
        fn_put_contents($download_file_path, $response);
    }
}
Esempio n. 21
0
<?php

/***************************************************************************
*                                                                          *
*    Copyright (c) 2004 Simbirsk Technologies Ltd. All rights reserved.    *
*                                                                          *
* This  is  commercial  software,  only  users  who have purchased a valid *
* license  and  accept  to the terms of the  License Agreement can install *
* and use this program.                                                    *
*                                                                          *
****************************************************************************
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
//
// $Id: index.php 7688 2009-07-10 05:58:05Z zeke $
//
if (!defined('AREA')) {
    die('Access denied');
}
// Generate dashboard
if ($mode == 'index') {
    $events = fn_get_recurring_events();
    if (!fn_is_empty($events)) {
        $msg = fn_get_lang_var('rb_have_events');
        $msg = str_replace('[link]', fn_url("subscriptions.events"), $msg);
        fn_delete_notification('rb_events');
        fn_set_notification('N', fn_get_lang_var('notice'), $msg, true, 'rb_events');
    }
}
Esempio n. 22
0
/**
 * Filters data from instant file uploader
 * @param string $name name of uploaded data
 * @param array $filter_by_ext allow file extensions
 * @return mixed filtered file data on success, false otherwise
 */
function fn_filter_uploaded_data($name, $filter_by_ext = array())
{
    $udata_local = fn_rebuild_files('file_' . $name);
    $udata_other = !empty($_REQUEST['file_' . $name]) ? $_REQUEST['file_' . $name] : array();
    $utype = !empty($_REQUEST['type_' . $name]) ? $_REQUEST['type_' . $name] : array();
    if (empty($utype)) {
        return array();
    }
    $filtered = array();
    foreach ($utype as $id => $type) {
        if ($type == 'local' && !fn_is_empty(@$udata_local[$id])) {
            $filtered[$id] = fn_get_local_data(Bootstrap::stripSlashes($udata_local[$id]));
        } elseif ($type == 'server' && !fn_is_empty(@$udata_other[$id]) && (Registry::get('runtime.skip_area_checking') || AREA == 'A')) {
            fn_get_last_key($udata_other[$id], 'fn_get_server_data', true);
            $filtered[$id] = $udata_other[$id];
        } elseif ($type == 'url' && !fn_is_empty(@$udata_other[$id])) {
            fn_get_last_key($udata_other[$id], 'fn_get_url_data', true);
            $filtered[$id] = $udata_other[$id];
        }
        if (isset($filtered[$id]) && $filtered[$id] === false) {
            unset($filtered[$id]);
            fn_set_notification('E', __('error'), __('cant_upload_file'));
            continue;
        }
        if (!empty($filtered[$id]['name'])) {
            $filtered[$id]['name'] = str_replace(' ', '_', urldecode($filtered[$id]['name']));
            // replace spaces with underscores
            if (!fn_check_uploaded_data($filtered[$id], $filter_by_ext)) {
                unset($filtered[$id]);
            }
        }
    }
    static $shutdown_inited;
    if (!$shutdown_inited) {
        $shutdown_inited = true;
        register_shutdown_function('fn_remove_temp_data');
    }
    return $filtered;
}
Esempio n. 23
0
function fn_get_dir_contents($dir, $get_dirs = true, $get_files = false, $extension = '', $prefix = '')
{
    $contents = array();
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            // $extention - can be string or array. Transform to array.
            $extension = is_array($extension) ? $extension : array($extension);
            while (($file = readdir($dh)) !== false) {
                if ($file == '.' || $file == '..' || $file[0] == '.') {
                    continue;
                }
                if (is_dir($dir . '/' . $file) && $get_dirs == true || is_file($dir . '/' . $file) && $get_files == true) {
                    if ($get_files == true && !fn_is_empty($extension)) {
                        // Check all extentions for file
                        foreach ($extension as $_ext) {
                            if (substr($file, -strlen($_ext)) == $_ext) {
                                $contents[] = $prefix . $file;
                                break;
                            }
                        }
                    } else {
                        $contents[] = $prefix . $file;
                    }
                }
            }
            closedir($dh);
        }
    }
    asort($contents, SORT_STRING);
    return $contents;
}
function fn_exim_set_product_options($product_id, $data, $lang_code)
{
    //for compatibility with the old format
    $data = preg_replace('{\\{\\d*\\}}', '', $data);
    if (!fn_is_empty($data)) {
        $data = fn_exim_parse_data($data);
        $updated_ids = array();
        // store updated ids, delete other (if exist)
        foreach ($data as $option_key => $option) {
            $global_option = isset($option['global']) ? $option['global'] : false;
            if (!empty($option['group_name'])) {
                $company_id = fn_get_company_id_by_name($option['group_name']);
            }
            $option_id = db_get_field("SELECT o.option_id FROM ?:product_options_descriptions as d INNER JOIN ?:product_options as o ON o.option_id = d.option_id AND o.product_id = ?i WHERE d.option_name = ?s AND d.lang_code = ?s LIMIT 1", $global_option ? 0 : $product_id, $option['name'], $lang_code);
            $variant_ids = array();
            $option['variants'] = isset($option['variants']) ? $option['variants'] : array();
            foreach ($option['variants'] as $variant_pos => $variant) {
                $variant_ids[$variant_pos] = db_get_field("SELECT d.variant_id FROM ?:product_option_variants_descriptions as d INNER JOIN ?:product_option_variants as o ON o.variant_id = d.variant_id AND o.option_id = ?i WHERE d.variant_name = ?s AND d.lang_code = ?s LIMIT 1", $option_id, $variant, $lang_code);
            }
            $option_data = fn_exim_build_option_data($option, $option_id, $variant_ids, $lang_code);
            $option_data['company_id'] = !empty($company_id) ? $company_id : 0;
            if (empty($option_id)) {
                $option_data['product_id'] = !empty($global_option) ? 0 : $product_id;
                $option_data['position'] = $option_key;
                $updated_id = fn_update_product_option($option_data, 0, $lang_code);
                // Option is exist, update it
            } else {
                $updated_id = fn_update_product_option($option_data, $option_id, $lang_code);
            }
            if ($global_option) {
                $glob_link = array('option_id' => $updated_id, 'product_id' => $product_id);
                db_query('REPLACE INTO ?:product_global_option_links ?e', $glob_link);
            }
            $variant_ids = array();
            foreach ($option['variants'] as $variant_pos => $variant) {
                $variant_ids[$variant_pos] = db_get_field("SELECT d.variant_id FROM ?:product_option_variants_descriptions as d INNER JOIN ?:product_option_variants as o ON o.variant_id = d.variant_id AND o.option_id = ?i WHERE d.variant_name = ?s AND d.lang_code = ?s LIMIT 1", $updated_id, $variant, $lang_code);
            }
            $updated_ids[] = $updated_id;
        }
        // Delete all other options
        if (!empty($updated_ids)) {
            $obsolete_ids = db_get_fields("SELECT option_id FROM ?:product_options WHERE option_id NOT IN (?n) AND product_id = ?i", $updated_ids, $product_id);
            if (!empty($obsolete_ids)) {
                foreach ($obsolete_ids as $o_id) {
                    fn_delete_product_option($o_id, $product_id);
                }
            }
        }
    }
    return true;
}
Esempio n. 25
0
/**
 * Filter data from file uploader
 *
 * @param string $name
 * @return array $filtered
 */
function fn_filter_uploaded_data($name)
{
    $udata_local = fn_rebuid_files('file_' . $name);
    $udata_other = !empty($_REQUEST['file_' . $name]) ? $_REQUEST['file_' . $name] : array();
    $utype = !empty($_REQUEST['type_' . $name]) ? $_REQUEST['type_' . $name] : array();
    //var_dump($udata_local);var_dump($udata_other);var_dump($utype);
    if (empty($utype)) {
        return array();
    }
    $filtered = array();
    //var_dump($udata_local);
    foreach ($utype as $id => $type) {
        if ($type == 'local' && !fn_is_empty(@$udata_local[$id])) {
            $filtered[$id] = fn_get_local_data(fn_strip_slashes($udata_local[$id]));
        } elseif ($type == 'server' && !fn_is_empty(@$udata_other[$id]) && AREA == 'A') {
            fn_get_last_key($udata_other[$id], 'fn_get_server_data', true);
            $filtered[$id] = $udata_other[$id];
        } elseif ($type == 'url' && !fn_is_empty(@$udata_other[$id])) {
            fn_get_last_key($udata_other[$id], 'fn_get_url_data', true);
            $filtered[$id] = $udata_other[$id];
        }
        if (!empty($filtered[$id]['name'])) {
            $filtered[$id]['name'] = str_replace(' ', '_', urldecode($filtered[$id]['name']));
            // replace spaces with underscores
            $ext = fn_get_file_ext($filtered[$id]['name']);
            if (in_array($ext, Registry::get('config.forbidden_file_extensions'))) {
                unset($filtered[$id]);
                $msg = fn_get_lang_var('text_forbidden_file_extension');
                $msg = str_replace('[ext]', $ext, $msg);
                fn_set_notification('E', fn_get_lang_var('error'), $msg);
            }
        }
    }
    static $shutdown_inited;
    if (!$shutdown_inited) {
        $shutdown_inited = true;
        register_shutdown_function('fn_remove_temp_data');
    }
    //var_dump($filtered);
    //die();
    return $filtered;
}
Esempio n. 26
0
function fn_get_csv($pattern, $file, $options)
{
    $max_line_size = 65536;
    // 64 Кб
    $result = array();
    if ($options['delimiter'] == 'C') {
        $delimiter = ',';
    } elseif ($options['delimiter'] == 'T') {
        $delimiter = "\t";
    } else {
        $delimiter = ';';
    }
    if (!empty($file) && file_exists($file)) {
        $encoding = fn_detect_encoding($file, 'F', !empty($options['lang_code']) ? $options['lang_code'] : CART_LANGUAGE);
        if (!empty($encoding)) {
            $file = fn_convert_encoding($encoding, 'UTF-8', $file, 'F');
        } else {
            fn_set_notification('W', __('warning'), __('text_exim_utf8_file_format'));
        }
        $f = false;
        if ($file !== false) {
            $f = fopen($file, 'rb');
        }
        if ($f) {
            // Get import schema
            $import_schema = fgetcsv($f, $max_line_size, $delimiter);
            if (empty($import_schema)) {
                fn_set_notification('E', __('error'), __('error_exim_cant_read_file'));
                return false;
            }
            // Check if we selected correct delimiter
            // If line was read without delimition, array size will be == 1.
            if (sizeof($import_schema) == 1) {
                // we could export one column if it is correct, otherwise show error
                if (!in_array($import_schema[0], array_keys($pattern['export_fields']))) {
                    fn_set_notification('E', __('error'), __('error_exim_incorrent_delimiter'));
                    return false;
                }
            }
            // Analyze schema - check for required fields
            if (fn_analyze_schema($import_schema, $pattern) == false) {
                return false;
            }
            // Collect data
            $schema_size = sizeof($import_schema);
            $skipped_lines = array();
            $line_it = 1;
            while (($data = fn_fgetcsv($f, $max_line_size, $delimiter)) !== false) {
                $line_it++;
                if (fn_is_empty($data)) {
                    continue;
                }
                if (sizeof($data) != $schema_size) {
                    $skipped_lines[] = $line_it;
                    continue;
                }
                $result[] = array_combine($import_schema, Bootstrap::stripSlashes($data));
            }
            if (!empty($skipped_lines)) {
                fn_set_notification('W', __('warning'), __('error_exim_incorrect_lines', array('[lines]' => implode(', ', $skipped_lines))));
            }
            return $result;
        } else {
            fn_set_notification('E', __('error'), __('error_exim_cant_open_file'));
            return false;
        }
    } else {
        fn_set_notification('E', __('error'), __('error_exim_file_doesnt_exist'));
        return false;
    }
}
Esempio n. 27
0
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
// rus_build_unisender
use Tygh\Registry;
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
if ($_SERVER['REQUEST_METHOD'] == "POST") {
    if ($mode == 'update') {
        $email = $_REQUEST['user_data']['email'];
        $subscriber_id = fn_unisender_get_subscriber_id($email);
        if (!empty($auth['user_id'])) {
            $_REQUEST['user_data']['user_id'] = $auth['user_id'];
        }
        if (!empty($_REQUEST['unisender_lists']) && !fn_is_empty($_REQUEST['unisender_lists'])) {
            if (empty($subscriber_id)) {
                $subscriber_id = fn_unisender_add_subscriber($email);
            }
            fn_unisender_subscribe($_REQUEST['user_data'], reset($_REQUEST['unisender_lists']), true);
        } else {
            if (!empty($subscriber_id)) {
                fn_unisender_unsubscribe($subscriber_id);
            }
        }
    }
}
if ($mode == 'add' || $mode == 'update') {
    Tygh::$app['view']->assign('unisender_page_mailing_lists', fn_unisender_get_enabled_lists());
}
if ($mode == 'update') {
Esempio n. 28
0
function fn_get_products($params, $items_per_page = 0, $lang_code = CART_LANGUAGE)
{
    /**
     * Changes params for selecting products
     *
     * @param array  $params         Product search params
     * @param int    $items_per_page Items per page
     * @param string $lang_code      Two-letter language code (e.g. 'en', 'ru', etc.)
     */
    fn_set_hook('get_products_pre', $params, $items_per_page, $lang_code);
    // Init filter
    $params = LastView::instance()->update('products', $params);
    // Set default values to input params
    $default_params = array('area' => AREA, 'extend' => array('product_name', 'prices', 'categories'), 'custom_extend' => array(), 'pname' => '', 'pshort' => '', 'pfull' => '', 'pkeywords' => '', 'feature' => array(), 'type' => 'simple', 'page' => 1, 'action' => '', 'variants' => array(), 'ranges' => array(), 'custom_range' => array(), 'field_range' => array(), 'features_hash' => '', 'limit' => 0, 'bid' => 0, 'match' => '', 'tracking' => array(), 'get_frontend_urls' => false, 'items_per_page' => $items_per_page);
    if (empty($params['custom_extend'])) {
        $params['extend'] = !empty($params['extend']) ? array_merge($default_params['extend'], $params['extend']) : $default_params['extend'];
    } else {
        $params['extend'] = $params['custom_extend'];
    }
    $params = array_merge($default_params, $params);
    if ((empty($params['pname']) || $params['pname'] != 'Y') && (empty($params['pshort']) || $params['pshort'] != 'Y') && (empty($params['pfull']) || $params['pfull'] != 'Y') && (empty($params['pkeywords']) || $params['pkeywords'] != 'Y') && (empty($params['feature']) || $params['feature'] != 'Y') && !empty($params['q'])) {
        $params['pname'] = 'Y';
    }
    $auth =& $_SESSION['auth'];
    // Define fields that should be retrieved
    if (empty($params['only_short_fields'])) {
        $fields = array('products.*');
    } else {
        $fields = array('product_id' => 'products.product_id', 'product_code' => 'products.product_code', 'product_type' => 'products.product_type', 'status' => 'products.status', 'company_id' => 'products.company_id', 'list_price' => 'products.list_price', 'amount' => 'products.amount', 'weight' => 'products.weight', 'tracking' => 'products.tracking', 'is_edp' => 'products.is_edp', 'return_period' => 'products.return_period');
    }
    //AS started_price
    $fields['subtitle'] = 'descr1.subtitle';
    $fields['top_title'] = 'descr1.top_title';
    $fields['started_price'] = 'prices.price AS started_price';
    // Define sort fields
    $sortings = array('code' => 'products.product_code', 'status' => 'products.status', 'product' => 'product', 'position' => 'products_categories.position', 'price' => 'price', 'list_price' => 'products.list_price', 'weight' => 'products.weight', 'amount' => 'products.amount', 'timestamp' => 'products.timestamp', 'updated_timestamp' => 'products.updated_timestamp', 'popularity' => 'popularity.total', 'company' => 'company_name', 'null' => 'NULL');
    if (!empty($params['get_subscribers'])) {
        $sortings['num_subscr'] = 'num_subscr';
        $fields['num_subscr'] = 'COUNT(DISTINCT product_subscriptions.subscription_id) as num_subscr';
    }
    if (!empty($params['order_ids'])) {
        $sortings['p_qty'] = 'purchased_qty';
        $sortings['p_subtotal'] = 'purchased_subtotal';
        $fields['purchased_qty'] = "SUM(?:order_details.amount) as purchased_qty";
        $fields['purchased_subtotal'] = "SUM(?:order_details.price * ?:order_details.amount) as purchased_subtotal";
    }
    if (isset($params['compact']) && $params['compact'] == 'Y') {
        $union_condition = ' OR ';
    } else {
        $union_condition = ' AND ';
    }
    $join = $condition = $u_condition = $inventory_condition = '';
    $having = array();
    $extraCondition = array();
    // Search string condition for SQL query
    if (isset($params['q']) && fn_string_not_empty($params['q'])) {
        $params['q'] = trim($params['q']);
        if ($params['match'] == 'any') {
            $pieces = fn_explode(' ', $params['q']);
            $search_type = ' OR ';
        } elseif ($params['match'] == 'all') {
            $pieces = fn_explode(' ', $params['q']);
            $search_type = ' AND ';
        } else {
            $pieces = array($params['q']);
            $search_type = '';
        }
        $_condition = array();
        foreach ($pieces as $piece) {
            if (strlen($piece) == 0) {
                continue;
            }
            $tmp = db_quote("(descr1.search_words LIKE ?l)", '%' . $piece . '%');
            // check search words
            if ($params['pname'] == 'Y') {
                $tmp .= db_quote(" OR descr1.product LIKE ?l", '%' . $piece . '%');
            }
            if ($params['pshort'] == 'Y') {
                $tmp .= db_quote(" OR descr1.short_description LIKE ?l", '%' . $piece . '%');
                $tmp .= db_quote(" OR descr1.short_description LIKE ?l", '%' . htmlentities($piece, ENT_QUOTES, 'UTF-8') . '%');
            }
            if ($params['pfull'] == 'Y') {
                $tmp .= db_quote(" OR descr1.full_description LIKE ?l", '%' . $piece . '%');
                $tmp .= db_quote(" OR descr1.full_description LIKE ?l", '%' . htmlentities($piece, ENT_QUOTES, 'UTF-8') . '%');
            }
            if ($params['pkeywords'] == 'Y') {
                $tmp .= db_quote(" OR (descr1.meta_keywords LIKE ?l OR descr1.meta_description LIKE ?l)", '%' . $piece . '%', '%' . $piece . '%');
            }
            if (!empty($params['feature']) && $params['action'] != 'feature_search') {
                $tmp .= db_quote(" OR ?:product_features_values.value LIKE ?l", '%' . $piece . '%');
            }
            fn_set_hook('additional_fields_in_search', $params, $fields, $sortings, $condition, $join, $sorting, $group_by, $tmp, $piece, $having);
            $_condition[] = '(' . $tmp . ')';
        }
        $_cond = implode($search_type, $_condition);
        if (!empty($_condition)) {
            $condition .= ' AND (' . $_cond . ') ';
        }
        if (!empty($params['feature']) && $params['action'] != 'feature_search') {
            $join .= " LEFT JOIN ?:product_features_values ON ?:product_features_values.product_id = products.product_id";
            $condition .= db_quote(" AND (?:product_features_values.feature_id IN (?n) OR ?:product_features_values.feature_id IS NULL)", array_values($params['feature']));
        }
        //if perform search we also get additional fields
        if ($params['pname'] == 'Y') {
            $params['extend'][] = 'product_name';
        }
        if ($params['pshort'] == 'Y' || $params['pfull'] == 'Y' || $params['pkeywords'] == 'Y') {
            $params['extend'][] = 'description';
        }
        unset($_condition);
    }
    //
    // [Advanced and feature filters]
    //
    if (!empty($params['apply_limit']) && $params['apply_limit'] && !empty($params['pid'])) {
        $pids = array();
        foreach ($params['pid'] as $pid) {
            if ($pid != $params['exclude_pid']) {
                if (count($pids) == $params['limit']) {
                    break;
                } else {
                    $pids[] = $pid;
                }
            }
        }
        $params['pid'] = $pids;
    }
    if (!empty($params['features_hash']) || !fn_is_empty($params['variants']) || !empty($params['feature_code'])) {
        $join .= db_quote(" LEFT JOIN ?:product_features_values ON ?:product_features_values.product_id = products.product_id AND ?:product_features_values.lang_code = ?s", $lang_code);
    }
    if (!empty($params['variants'])) {
        $params['features_hash'] .= implode('.', $params['variants']);
    }
    // Feature code
    if (!empty($params['feature_code'])) {
        $join .= db_quote(" LEFT JOIN ?:product_features ON ?:product_features_values.feature_id = ?:product_features.feature_id");
        $condition .= db_quote(" AND ?:product_features.feature_code = ?s", $params['feature_code']);
    }
    $advanced_variant_ids = $simple_variant_ids = $ranges_ids = $fields_ids = $fields_ids_revert = $slider_vals = array();
    if (!empty($params['features_hash'])) {
        list($av_ids, $ranges_ids, $fields_ids, $slider_vals, $fields_ids_revert) = fn_parse_features_hash($params['features_hash']);
        $advanced_variant_ids = db_get_hash_multi_array("SELECT feature_id, variant_id FROM ?:product_feature_variants WHERE variant_id IN (?n)", array('feature_id', 'variant_id'), $av_ids);
    }
    if (!empty($params['multiple_variants'])) {
        $simple_variant_ids = $params['multiple_variants'];
    }
    if (!empty($advanced_variant_ids)) {
        $join .= db_quote(" LEFT JOIN (SELECT product_id, GROUP_CONCAT(?:product_features_values.variant_id) AS advanced_variants FROM ?:product_features_values WHERE lang_code = ?s GROUP BY product_id) AS pfv_advanced ON pfv_advanced.product_id = products.product_id", $lang_code);
        $where_and_conditions = array();
        foreach ($advanced_variant_ids as $k => $variant_ids) {
            $where_or_conditions = array();
            foreach ($variant_ids as $variant_id => $v) {
                $where_or_conditions[] = db_quote(" FIND_IN_SET('?i', advanced_variants)", $variant_id);
            }
            $where_and_conditions[] = '(' . implode(' OR ', $where_or_conditions) . ')';
        }
        $condition .= ' AND ' . implode(' AND ', $where_and_conditions);
    }
    if (!empty($simple_variant_ids)) {
        $join .= db_quote(" LEFT JOIN (SELECT product_id, GROUP_CONCAT(?:product_features_values.variant_id) AS simple_variants FROM ?:product_features_values WHERE lang_code = ?s GROUP BY product_id) AS pfv_simple ON pfv_simple.product_id = products.product_id", $lang_code);
        $where_conditions = array();
        foreach ($simple_variant_ids as $k => $variant_id) {
            $where_conditions[] = db_quote(" FIND_IN_SET('?i', simple_variants)", $variant_id);
        }
        $condition .= ' AND ' . implode(' AND ', $where_conditions);
    }
    //
    // Ranges from text inputs
    //
    // Feature ranges
    if (!empty($params['custom_range'])) {
        foreach ($params['custom_range'] as $k => $v) {
            $k = intval($k);
            if (isset($v['from']) && fn_string_not_empty($v['from']) || isset($v['to']) && fn_string_not_empty($v['to'])) {
                if (!empty($v['type'])) {
                    if ($v['type'] == 'D') {
                        $v['from'] = fn_parse_date($v['from']);
                        $v['to'] = fn_parse_date($v['to']);
                    }
                }
                $join .= db_quote(" LEFT JOIN ?:product_features_values as custom_range_{$k} ON custom_range_{$k}.product_id = products.product_id AND custom_range_{$k}.lang_code = ?s", $lang_code);
                if (fn_string_not_empty($v['from']) && fn_string_not_empty($v['to'])) {
                    $condition .= db_quote(" AND (custom_range_{$k}.value_int >= ?i AND custom_range_{$k}.value_int <= ?i AND custom_range_{$k}.value = '' AND custom_range_{$k}.feature_id = ?i) ", $v['from'], $v['to'], $k);
                } else {
                    $condition .= " AND custom_range_{$k}.value_int" . (fn_string_not_empty($v['from']) ? db_quote(' >= ?i', $v['from']) : db_quote(" <= ?i AND custom_range_{$k}.value = '' AND custom_range_{$k}.feature_id = ?i ", $v['to'], $k));
                }
            }
        }
    }
    // Product field ranges
    $filter_fields = fn_get_product_filter_fields();
    if (!empty($params['field_range'])) {
        foreach ($params['field_range'] as $field_type => $v) {
            $structure = $filter_fields[$field_type];
            if (!empty($structure) && (!empty($v['from']) || !empty($v['to']))) {
                if ($field_type == 'P') {
                    // price
                    $v['cur'] = !empty($v['cur']) ? $v['cur'] : CART_SECONDARY_CURRENCY;
                    if (empty($v['orig_cur'])) {
                        // saving the first user-entered values
                        // will be always search by it
                        $v['orig_from'] = $v['from'];
                        $v['orig_to'] = $v['to'];
                        $v['orig_cur'] = $v['cur'];
                        $params['field_range'][$field_type] = $v;
                    }
                    if ($v['orig_cur'] != CART_PRIMARY_CURRENCY) {
                        // calc price in primary currency
                        $cur_prim_coef = Registry::get('currencies.' . $v['orig_cur'] . '.coefficient');
                        $decimals = Registry::get('currencies.' . CART_PRIMARY_CURRENCY . '.decimals');
                        $search_from = round($v['orig_from'] * floatval($cur_prim_coef), $decimals);
                        $search_to = round($v['orig_to'] * floatval($cur_prim_coef), $decimals);
                    } else {
                        $search_from = $v['orig_from'];
                        $search_to = $v['orig_to'];
                    }
                    // if user switch the currency, calc new values for displaying in filter
                    if ($v['cur'] != CART_SECONDARY_CURRENCY) {
                        if (CART_SECONDARY_CURRENCY == $v['orig_cur']) {
                            $v['from'] = $v['orig_from'];
                            $v['to'] = $v['orig_to'];
                        } else {
                            $prev_coef = Registry::get('currencies.' . $v['cur'] . '.coefficient');
                            $cur_coef = Registry::get('currencies.' . CART_SECONDARY_CURRENCY . '.coefficient');
                            $v['from'] = floor(floatval($v['from']) * floatval($prev_coef) / floatval($cur_coef));
                            $v['to'] = ceil(floatval($v['to']) * floatval($prev_coef) / floatval($cur_coef));
                        }
                        $v['cur'] = CART_SECONDARY_CURRENCY;
                        $params['field_range'][$field_type] = $v;
                    }
                }
                $params["{$structure['db_field']}_from"] = trim(isset($search_from) ? $search_from : $v['from']);
                $params["{$structure['db_field']}_to"] = trim(isset($search_to) ? $search_to : $v['to']);
            }
        }
    }
    // Ranges from database
    if (!empty($ranges_ids)) {
        $filter_conditions = db_get_hash_multi_array("SELECT `from`, `to`, feature_id, filter_id, range_id FROM ?:product_filter_ranges WHERE range_id IN (?n)", array('filter_id', 'range_id'), $ranges_ids);
        $where_conditions = array();
        foreach ($filter_conditions as $fid => $range_conditions) {
            foreach ($range_conditions as $k => $range_condition) {
                $k = $fid . "_" . $k;
                $join .= db_quote(" LEFT JOIN ?:product_features_values as var_val_{$k} ON var_val_{$k}.product_id = products.product_id AND var_val_{$k}.lang_code = ?s", $lang_code);
                $where_conditions[] = db_quote("(var_val_{$k}.value_int >= ?i AND var_val_{$k}.value_int <= ?i AND var_val_{$k}.value = '' AND var_val_{$k}.feature_id = ?i)", $range_condition['from'], $range_condition['to'], $range_condition['feature_id']);
            }
            $condition .= db_quote(" AND (?p)", implode(" OR ", $where_conditions));
            $where_conditions = array();
        }
    }
    // Field ranges
    //$fields_ids = empty($params['fields_ids']) ? $fields_ids : $params['fields_ids'];
    if (!empty($params['fields_ids'])) {
        foreach ($fields_ids as $rid => $field_type) {
            if (!empty($filter_fields[$field_type])) {
                $structure = $filter_fields[$field_type];
                if ($structure['condition_type'] == 'D' && empty($structure['slider'])) {
                    $range_condition = db_get_row("SELECT `from`, `to`, range_id FROM ?:product_filter_ranges WHERE range_id = ?i", $rid);
                    if (!empty($range_condition)) {
                        $params["{$structure['db_field']}_from"] = $range_condition['from'];
                        $params["{$structure['db_field']}_to"] = $range_condition['to'];
                    }
                } elseif ($structure['condition_type'] == 'F') {
                    $params['filter_params'][$structure['db_field']][] = $rid;
                } elseif ($structure['condition_type'] == 'C') {
                    $params['filter_params'][$structure['db_field']][] = $rid == 1 ? 'Y' : 'N';
                }
            }
        }
    } elseif (!empty($fields_ids_revert)) {
        foreach ($fields_ids_revert as $field_type => $rids) {
            if (!empty($filter_fields[$field_type])) {
                $structure = $filter_fields[$field_type];
                if ($structure['condition_type'] == 'D' && empty($structure['slider'])) {
                    foreach ($rids as $rid) {
                        $range_condition = db_get_row("SELECT `from`, `to`, range_id FROM ?:product_filter_ranges WHERE range_id = ?i", $rid);
                        if (!empty($range_condition)) {
                            $params["{$structure['db_field']}_from"] = $range_condition['from'];
                            $params["{$structure['db_field']}_to"] = $range_condition['to'];
                        }
                    }
                } elseif ($structure['condition_type'] == 'F') {
                    $params['filter_params'][$structure['db_field']] = $rids;
                } elseif ($structure['condition_type'] == 'C') {
                    if (count($rids) > 1) {
                        foreach ($rids as $rid) {
                            if ($fields_ids[$rid] == $field_type) {
                                unset($fields_ids[$rid]);
                            }
                            $params['features_hash'] = fn_delete_range_from_url($params['features_hash'], array('range_id' => $rid), $field_type);
                        }
                    } else {
                        $params['filter_params'][$structure['db_field']][] = $rids[0] == 1 ? 'Y' : 'N';
                    }
                }
            }
        }
    }
    // Slider ranges
    $slider_vals = empty($params['slider_vals']) ? $slider_vals : $params['slider_vals'];
    if (!empty($slider_vals)) {
        foreach ($slider_vals as $field_type => $vals) {
            if (!empty($filter_fields[$field_type])) {
                if ($field_type == 'P') {
                    $currency = !empty($vals[2]) ? $vals[2] : CART_PRIMARY_CURRENCY;
                    if ($currency != CART_PRIMARY_CURRENCY) {
                        $coef = Registry::get('currencies.' . $currency . '.coefficient');
                        $decimals = Registry::get('currencies.' . CART_PRIMARY_CURRENCY . '.decimals');
                        $vals[0] = round(floatval($vals[0]) * floatval($coef), $decimals);
                        $vals[1] = round(floatval($vals[1]) * floatval($coef), $decimals);
                    }
                }
                $structure = $filter_fields[$field_type];
                $params["{$structure['db_field']}_from"] = $vals[0];
                $params["{$structure['db_field']}_to"] = $vals[1];
            }
        }
    }
    // Checkbox features
    if (!empty($params['ch_filters']) && !fn_is_empty($params['ch_filters'])) {
        foreach ($params['ch_filters'] as $k => $v) {
            // Product field filter
            if (is_string($k) == true && !empty($v) && ($structure = $filter_fields[$k])) {
                $condition .= db_quote(" AND {$structure['table']}.{$structure['db_field']} IN (?a)", $v == 'A' ? array('Y', 'N') : $v);
                // Feature filter
            } elseif (!empty($v)) {
                $fid = intval($k);
                $join .= db_quote(" LEFT JOIN ?:product_features_values as ch_features_{$fid} ON ch_features_{$fid}.product_id = products.product_id AND ch_features_{$fid}.lang_code = ?s", $lang_code);
                $condition .= db_quote(" AND ch_features_{$fid}.feature_id = ?i AND ch_features_{$fid}.value IN (?a)", $fid, $v == 'A' ? array('Y', 'N') : $v);
            }
        }
    }
    // Text features
    if (!empty($params['tx_features'])) {
        foreach ($params['tx_features'] as $k => $v) {
            if (fn_string_not_empty($v)) {
                $fid = intval($k);
                $join .= " LEFT JOIN ?:product_features_values as tx_features_{$fid} ON tx_features_{$fid}.product_id = products.product_id";
                $condition .= db_quote(" AND tx_features_{$fid}.value LIKE ?l AND tx_features_{$fid}.lang_code = ?s", "%" . trim($v) . "%", $lang_code);
            }
        }
    }
    $total = 0;
    fn_set_hook('get_products_before_select', $params, $join, $condition, $u_condition, $inventory_condition, $sortings, $total, $items_per_page, $lang_code, $having);
    //
    // [/Advanced filters]
    //
    $feature_search_condition = '';
    if (!empty($params['feature'])) {
        // Extended search by product fields
        $_cond = array();
        $total_hits = 0;
        foreach ($params['feature'] as $f_id) {
            if (!empty($f_val)) {
                $total_hits++;
                $_cond[] = db_quote("(?:product_features_values.feature_id = ?i)", $f_id);
            }
        }
        $params['extend'][] = 'categories';
        if (!empty($_cond)) {
            $cache_feature_search = db_get_fields("SELECT product_id, COUNT(product_id) as cnt FROM ?:product_features_values WHERE (" . implode(' OR ', $_cond) . ") GROUP BY product_id HAVING cnt = {$total_hits}");
            $feature_search_condition .= db_quote(" AND products_categories.product_id IN (?n)", $cache_feature_search);
        }
    }
    // Category search condition for SQL query
    if (!empty($params['cid'])) {
        $cids = is_array($params['cid']) ? $params['cid'] : explode(',', $params['cid']);
        if (!empty($params['subcats']) && $params['subcats'] == 'Y') {
            $_ids = db_get_fields("SELECT a.category_id FROM ?:categories as a LEFT JOIN ?:categories as b ON b.category_id IN (?n) WHERE a.id_path LIKE CONCAT(b.id_path, '/%')", $cids);
            $cids = fn_array_merge($cids, $_ids, false);
        }
        $params['extend'][] = 'categories';
        $condition .= db_quote(" AND ?:categories.category_id IN (?n)", $cids);
    }
    // If we need to get the products by IDs and no IDs passed, don't search anything
    if (!empty($params['force_get_by_ids']) && empty($params['pid']) && empty($params['product_id'])) {
        return array(array(), $params, 0);
    }
    // Product ID search condition for SQL query
    if (!empty($params['pid'])) {
        $u_condition .= db_quote($union_condition . ' products.product_id IN (?n)', $params['pid']);
    }
    // Exclude products from search results
    if (!empty($params['exclude_pid'])) {
        $condition .= db_quote(' AND products.product_id NOT IN (?n)', $params['exclude_pid']);
    }
    // Search by feature comparison flag
    if (!empty($params['feature_comparison'])) {
        $condition .= db_quote(' AND products.feature_comparison = ?s', $params['feature_comparison']);
    }
    // Search products by localization
    $condition .= fn_get_localizations_condition('products.localization', true);
    $company_condition = '';
    if (fn_allowed_for('MULTIVENDOR')) {
        if ($params['area'] == 'C') {
            $company_condition .= " AND companies.status = 'A' ";
            $params['extend'][] = 'companies';
        } else {
            $company_condition .= fn_get_company_condition('products.company_id');
        }
    } else {
        $cat_company_condition = '';
        if (Registry::get('runtime.company_id')) {
            $params['extend'][] = 'categories';
            $cat_company_condition .= fn_get_company_condition('?:categories.company_id');
        } elseif (!empty($params['company_ids'])) {
            $params['extend'][] = 'categories';
            $cat_company_condition .= db_quote(' AND ?:categories.company_id IN (?a)', explode(',', $params['company_ids']));
        }
        $company_condition .= $cat_company_condition;
    }
    $condition .= $company_condition;
    if (!fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id') && isset($params['company_id'])) {
        $params['company_id'] = Registry::get('runtime.company_id');
    }
    if (isset($params['company_id']) && $params['company_id'] != '') {
        $condition .= db_quote(' AND products.company_id = ?i ', $params['company_id']);
    }
    if (!empty($params['filter_params'])) {
        foreach ($params['filter_params'] as $field => $f_vals) {
            $condition .= db_quote(' AND products.' . $field . ' IN (?a) ', $f_vals);
        }
    }
    if (isset($params['price_from']) && fn_is_numeric($params['price_from'])) {
        $having['price_from'] = db_quote(' price >= ?d', fn_convert_price(trim($params['price_from'])));
        $extraCondition["price_from"] = db_quote(' price >= ?d', fn_convert_price(trim($params['price_from'])));
        //$condition .= db_quote(' AND prices.price >= ?d', fn_convert_price(trim($params['price_from'])));
        $params['extend'][] = 'prices2';
    }
    if (isset($params['price_to']) && fn_is_numeric($params['price_to'])) {
        $having['price_to'] = db_quote(' price <= ?d', fn_convert_price(trim($params['price_to'])));
        $extraCondition["price_to"] = db_quote(' price <= ?d', fn_convert_price(trim($params['price_to'])));
        //$condition .= db_quote(' AND prices.price <= ?d', fn_convert_price(trim($params['price_to'])));
        $params['extend'][] = 'prices2';
    }
    if (isset($params['weight_from']) && fn_is_numeric($params['weight_from'])) {
        $condition .= db_quote(' AND products.weight >= ?d', fn_convert_weight(trim($params['weight_from'])));
    }
    if (isset($params['weight_to']) && fn_is_numeric($params['weight_to'])) {
        $condition .= db_quote(' AND products.weight <= ?d', fn_convert_weight(trim($params['weight_to'])));
    }
    // search specific inventory status
    if (!empty($params['tracking'])) {
        $condition .= db_quote(' AND products.tracking IN(?a)', $params['tracking']);
    }
    if (isset($params['amount_from']) && fn_is_numeric($params['amount_from'])) {
        $condition .= db_quote(" AND IF(products.tracking = 'O', inventory.amount >= ?i, products.amount >= ?i)", $params['amount_from'], $params['amount_from']);
        $inventory_condition .= db_quote(' AND inventory.amount >= ?i', $params['amount_from']);
    }
    if (isset($params['amount_to']) && fn_is_numeric($params['amount_to'])) {
        $condition .= db_quote(" AND IF(products.tracking = 'O', inventory.amount <= ?i, products.amount <= ?i)", $params['amount_to'], $params['amount_to']);
        $inventory_condition .= db_quote(' AND inventory.amount <= ?i', $params['amount_to']);
    }
    if (Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.show_out_of_stock_products') == 'N' && $params['area'] == 'C') {
        // FIXME? Registry in model
        $condition .= " AND IF(products.tracking = 'O', inventory.amount > 0, products.amount > 0)";
    }
    if (!empty($params['status'])) {
        $condition .= db_quote(' AND products.status IN (?a)', $params['status']);
    }
    if (!empty($params['shipping_freight_from'])) {
        $condition .= db_quote(' AND products.shipping_freight >= ?d', $params['shipping_freight_from']);
    }
    if (!empty($params['shipping_freight_to'])) {
        $condition .= db_quote(' AND products.shipping_freight <= ?d', $params['shipping_freight_to']);
    }
    if (!empty($params['free_shipping'])) {
        $condition .= db_quote(' AND products.free_shipping = ?s', $params['free_shipping']);
    }
    if (!empty($params['downloadable'])) {
        $condition .= db_quote(' AND products.is_edp = ?s', $params['downloadable']);
    }
    if (isset($params['pcode']) && fn_string_not_empty($params['pcode'])) {
        $pcode = trim($params['pcode']);
        $fields['combination'] = 'inventory.combination';
        $u_condition .= db_quote(" {$union_condition} (inventory.product_code LIKE ?l OR products.product_code LIKE ?l)", "%{$pcode}%", "%{$pcode}%");
        $inventory_condition .= db_quote(" AND inventory.product_code LIKE ?l", "%{$pcode}%");
    }
    if (isset($params['amount_to']) && fn_is_numeric($params['amount_to']) || isset($params['amount_from']) && fn_is_numeric($params['amount_from']) || !empty($params['pcode']) || Registry::get('settings.General.inventory_tracking') == 'Y' && Registry::get('settings.General.show_out_of_stock_products') == 'N' && $params['area'] == 'C') {
        $join .= " LEFT JOIN ?:product_options_inventory as inventory ON inventory.product_id = products.product_id {$inventory_condition}";
    }
    if (!empty($params['period']) && $params['period'] != 'A') {
        list($params['time_from'], $params['time_to']) = fn_create_periods($params);
        $condition .= db_quote(" AND (products.timestamp >= ?i AND products.timestamp <= ?i)", $params['time_from'], $params['time_to']);
    }
    if (!empty($params['item_ids'])) {
        $condition .= db_quote(" AND products.product_id IN (?n)", explode(',', $params['item_ids']));
    }
    if (isset($params['popularity_from']) && fn_is_numeric($params['popularity_from'])) {
        $params['extend'][] = 'popularity';
        $condition .= db_quote(' AND popularity.total >= ?i', $params['popularity_from']);
    }
    if (isset($params['popularity_to']) && fn_is_numeric($params['popularity_to'])) {
        $params['extend'][] = 'popularity';
        $condition .= db_quote(' AND popularity.total <= ?i', $params['popularity_to']);
    }
    if (!empty($params['order_ids'])) {
        $arr = strpos($params['order_ids'], ',') !== false || !is_array($params['order_ids']) ? explode(',', $params['order_ids']) : $params['order_ids'];
        $condition .= db_quote(" AND ?:order_details.order_id IN (?n)", $arr);
        $join .= " LEFT JOIN ?:order_details ON ?:order_details.product_id = products.product_id";
    }
    $limit = '';
    $group_by = 'products.product_id';
    // Show enabled products
    $_p_statuses = array('A');
    if ($params['p_status']) {
        $_p_statuses = array('A', 'H');
    }
    $condition .= $params['area'] == 'C' ? ' AND (' . fn_find_array_in_set($auth['usergroup_ids'], 'products.usergroup_ids', true) . ')' . db_quote(' AND products.status IN (?a)', $_p_statuses) : '';
    // -- JOINS --
    if (in_array('product_name', $params['extend'])) {
        $fields['product'] = 'descr1.product as product';
        $join .= db_quote(" LEFT JOIN ?:product_descriptions as descr1 ON descr1.product_id = products.product_id AND descr1.lang_code = ?s ", $lang_code);
    }
    // get prices
    $price_condition = '';
    if (in_array('prices', $params['extend'])) {
        //        //$fields['price'] = 'MIN(IF(prices.percentage_discount = 0, prices.price, prices.price - (prices.price * prices.percentage_discount)/100)) as price';
        $join .= " LEFT JOIN ?:product_prices as prices ON prices.product_id = products.product_id AND prices.lower_limit = 1";
        $price_condition = db_quote(' AND prices.usergroup_id IN (?n)', $params['area'] == 'A' ? USERGROUP_ALL : array_merge(array(USERGROUP_ALL), $auth['usergroup_ids']));
        $condition .= $price_condition;
        //$price_usergroup_cond_2 = db_quote(' AND usergroup_id IN (?n)', (($params['area'] == 'A') ? USERGROUP_ALL : array_merge(array(USERGROUP_ALL), $auth['usergroup_ids'])));
        $extraConditionString = "";
        if (count($extraCondition) > 0) {
            $extraConditionString = "WHERE " . implode(" AND ", $extraCondition);
        }
        $fields['price'] = 'case  
		when p2.min_price > 0 then p2.min_price 
                else p3.price2 
	end';
        $join .= "  LEFT JOIN (SELECT product_id, MIN(price) as min_price FROM ?:product_options_inventory_prices " . $extraConditionString . " GROUP BY product_id) AS p2 ON p2.product_id = products.product_id\n                    LEFT JOIN (SELECT product_id, MIN(IF(percentage_discount = 0, price, price - (price * percentage_discount)/100)) as price2  FROM ?:product_prices WHERE lower_limit = 1 GROUP by product_id) AS p3 ON p3.product_id=products.product_id ";
    }
    /*
    // get prices for search by price
    if (in_array('prices2', $params['extend'])) {
        $price_usergroup_cond_2 = db_quote(' AND prices_2.usergroup_id IN (?n)', (($params['area'] == 'A') ? USERGROUP_ALL : array_merge(array(USERGROUP_ALL), $auth['usergroup_ids'])));
        $join .= " LEFT JOIN ?:product_prices as prices_2 ON prices.product_id = prices_2.product_id AND prices_2.lower_limit = 1 AND prices_2.price < prices.price " . $price_usergroup_cond_2;
        $condition .= ' AND prices_2.price IS NULL';
        $price_condition .= ' AND prices_2.price IS NULL';
    }
    */
    //    if (in_array('prices2', $params['extend'])) {
    //        $price_usergroup_cond_2 = db_quote(' AND usergroup_id IN (?n)', (($params['area'] == 'A') ? USERGROUP_ALL : array_merge(array(USERGROUP_ALL), $auth['usergroup_ids'])));
    //        $fields['price'] = 'case
    //		when p2.min_price > 0 then p2.min_price
    //                else p3.price2
    //	end';
    //        $join .= "  LEFT JOIN (SELECT product_id, MIN(price) as min_price FROM ?:product_options_inventory_prices GROUP BY product_id) AS p2 ON p2.product_id = products.product_id
    //                    LEFT JOIN (SELECT product_id, MIN(IF(percentage_discount = 0, price, price - (price * percentage_discount)/100)) as price2  FROM ?:product_prices WHERE lower_limit = 1 ".$price_usergroup_cond_2." GROUP by product_id) AS p3 ON p3.product_id=products.product_id ";
    //    }
    // get short & full description
    if (in_array('search_words', $params['extend'])) {
        $fields['search_words'] = 'descr1.search_words';
    }
    // get short & full description
    if (in_array('description', $params['extend'])) {
        $fields['short_description'] = 'descr1.short_description';
        if (in_array('full_description', $params['extend'])) {
            $fields['full_description'] = "descr1.full_description";
        } else {
            $fields['full_description'] = "IF(descr1.short_description = '', descr1.full_description, '') as full_description";
        }
    }
    // get companies
    $companies_join = db_quote(" LEFT JOIN ?:companies AS companies ON companies.company_id = products.company_id ");
    if (in_array('companies', $params['extend'])) {
        $fields['company_name'] = 'companies.company as company_name';
        $join .= $companies_join;
    }
    // for compatibility
    if (in_array('category_ids', $params['extend'])) {
        $params['extend'][] = 'categories';
    }
    // get categories
    $_c_statuses = array('A', 'H');
    // Show enabled categories
    $skip_checking_usergroup_permissions = fn_is_preview_action($auth, $params);
    if ($skip_checking_usergroup_permissions) {
        $category_avail_cond = '';
    } else {
        $category_avail_cond = $params['area'] == 'C' ? ' AND (' . fn_find_array_in_set($auth['usergroup_ids'], '?:categories.usergroup_ids', true) . ')' : '';
    }
    $category_avail_cond .= $params['area'] == 'C' ? db_quote(" AND ?:categories.status IN (?a) ", $_c_statuses) : '';
    $categories_join = " INNER JOIN ?:products_categories as products_categories ON products_categories.product_id = products.product_id INNER JOIN ?:categories ON ?:categories.category_id = products_categories.category_id {$category_avail_cond} {$feature_search_condition}";
    if (!empty($params['order_ids'])) {
        // Avoid duplicating by sub-categories
        $condition .= db_quote(' AND products_categories.link_type = ?s', 'M');
    }
    if (in_array('categories', $params['extend'])) {
        $fields['category_ids'] = "GROUP_CONCAT(IF(products_categories.link_type = 'M', CONCAT(products_categories.category_id, 'M'), products_categories.category_id)) as category_ids";
        $fields['categories_position'] = 'products_categories.position';
        $join .= $categories_join;
        $condition .= fn_get_localizations_condition('?:categories.localization', true);
    }
    // get popularity
    $popularity_join = db_quote(" LEFT JOIN ?:product_popularity as popularity ON popularity.product_id = products.product_id");
    if (in_array('popularity', $params['extend'])) {
        $fields['popularity'] = 'popularity.total as popularity';
        $join .= $popularity_join;
    }
    if (!empty($params['get_subscribers'])) {
        $join .= " LEFT JOIN ?:product_subscriptions as product_subscriptions ON product_subscriptions.product_id = products.product_id";
    }
    //  -- \JOINs --
    if (!empty($u_condition)) {
        $condition .= " {$union_condition} ((" . ($union_condition == ' OR ' ? '0 ' : '1 ') . $u_condition . ')' . $company_condition . $price_condition . ')';
    }
    /**
     * Changes additional params for selecting products
     *
     * @param array  $params    Product search params
     * @param array  $fields    List of fields for retrieving
     * @param array  $sortings  Sorting fields
     * @param string $condition String containing SQL-query condition possibly prepended with a logical operator (AND or OR)
     * @param string $join      String with the complete JOIN information (JOIN type, tables and fields) for an SQL-query
     * @param string $sorting   String containing the SQL-query ORDER BY clause
     * @param string $group_by  String containing the SQL-query GROUP BY field
     * @param string $lang_code Two-letter language code (e.g. 'en', 'ru', etc.)
     * @param array  $having    HAVING condition
     */
    fn_set_hook('get_products', $params, $fields, $sortings, $condition, $join, $sorting, $group_by, $lang_code, $having);
    // -- SORTINGS --
    if (empty($params['sort_by']) || empty($sortings[$params['sort_by']])) {
        $params = array_merge($params, fn_get_default_products_sorting());
        if (empty($sortings[$params['sort_by']])) {
            $_products_sortings = fn_get_products_sorting();
            $params['sort_by'] = key($_products_sortings);
        }
    }
    $default_sorting = fn_get_products_sorting();
    if ($params['sort_by'] == 'popularity' && !in_array('popularity', $params['extend'])) {
        $join .= $popularity_join;
    }
    if ($params['sort_by'] == 'company' && !in_array('companies', $params['extend'])) {
        $join .= $companies_join;
    }
    if (empty($params['sort_order'])) {
        if (!empty($default_sorting[$params['sort_by']]['default_order'])) {
            $params['sort_order'] = $default_sorting[$params['sort_by']]['default_order'];
        } else {
            $params['sort_order'] = 'asc';
        }
    }
    $sorting = db_sort($params, $sortings);
    if (fn_allowed_for('ULTIMATE')) {
        if (in_array('sharing', $params['extend'])) {
            $fields['is_shared_product'] = "IF(COUNT(IF(?:categories.company_id = products.company_id, NULL, ?:categories.company_id)), 'Y', 'N') as is_shared_product";
            if (strpos($join, $categories_join) === false) {
                $join .= $categories_join;
            }
        }
    }
    // -- \SORTINGS --
    // Used for View cascading
    if (!empty($params['get_query'])) {
        return "SELECT products.product_id FROM ?:products as products {$join} WHERE 1 {$condition} GROUP BY products.product_id";
    }
    // Used for Extended search
    if (!empty($params['get_conditions'])) {
        return array($fields, $join, $condition);
    }
    if (!empty($params['limit'])) {
        $limit = db_quote(" LIMIT 0, ?i", $params['limit']);
    } elseif (!empty($params['items_per_page'])) {
        $limit = db_paginate($params['page'], $params['items_per_page']);
    }
    $calc_found_rows = '';
    if (empty($total)) {
        $calc_found_rows = 'SQL_CALC_FOUND_ROWS';
    }
    if (!empty($having)) {
        $having = ' HAVING ' . implode(' AND ', $having);
    } else {
        $having = '';
    }
    $products = db_get_array("SELECT {$calc_found_rows} " . implode(', ', $fields) . " FROM ?:products as products {$join} WHERE 1 {$condition} GROUP BY {$group_by} {$having} {$sorting} {$limit}");
    if (!empty($params['items_per_page'])) {
        $params['total_items'] = !empty($total) ? $total : db_get_found_rows();
    } else {
        $params['total_items'] = count($products);
    }
    // Post processing
    if (in_array('categories', $params['extend'])) {
        foreach ($products as $k => $v) {
            list($products[$k]['category_ids'], $products[$k]['main_category']) = fn_convert_categories($v['category_ids']);
        }
    }
    if (!empty($params['get_frontend_urls'])) {
        foreach ($products as &$product) {
            $product['url'] = fn_url('products.view?product_id=' . $product['product_id'], 'C');
        }
    }
    if (!empty($params['item_ids'])) {
        $products = fn_sort_by_ids($products, explode(',', $params['item_ids']));
    }
    if (!empty($params['pid']) && !empty($params['apply_limit']) && $params['apply_limit']) {
        $products = fn_sort_by_ids($products, $params['pid']);
    }
    foreach ($products as $keyProduct => $productItem) {
        $checkInventoryPrices = array();
        $inventory_product = array();
        $checkInventoryPrices = db_get_row("SELECT b.price FROM ?:products as a JOIN ?:product_options_inventory_prices as b ON a.product_id=b.product_id WHERE a.product_id = ?i ", $productItem['product_id']);
        if ($checkInventoryPrices && count($checkInventoryPrices) > 0) {
            $conditionExt = "";
            if (isset($params['price_from']) && fn_is_numeric($params['price_from'])) {
                $conditionExt .= db_quote(' AND b.price >= ?d', fn_convert_price(trim($params['price_from'])));
            }
            if (isset($params['price_to']) && fn_is_numeric($params['price_to'])) {
                $conditionExt .= db_quote(' AND b.price <= ?d', fn_convert_price(trim($params['price_to'])));
            }
            $inventory_product = db_get_row("SELECT MIN(b.price ) AS min_price, MAX(b.price ) AS max_price FROM ?:products as a JOIN ?:product_options_inventory_prices as b ON a.product_id=b.product_id WHERE a.product_id = ?i " . $conditionExt . "  GROUP BY a.product_id", $productItem['product_id']);
            if (!$inventory_product || count($inventory_product) < 1) {
                unset($products[$keyProduct]);
            } elseif ($inventory_product && count($inventory_product) > 0) {
                $products[$keyProduct]['price_range'] = $inventory_product;
            }
        }
        //fn_promotion_apply('catalog', $productItem, $auth);
    }
    /**
     * Changes selected products
     *
     * @param array  $products  Array of products
     * @param array  $params    Product search params
     * @param string $lang_code Language code
     */
    fn_set_hook('get_products_post', $products, $params, $lang_code);
    LastView::instance()->processResults('products', $products, $params);
    return array($products, $params);
}
    function content_55d3125033b7a9_87422872($_smarty_tpl)
    {
        if (!is_callable('smarty_block_hook')) {
            include '/home/coriolan/public_html/lead/app/functions/smarty_plugins/block.hook.php';
        }
        if (!is_callable('smarty_function_set_id')) {
            include '/home/coriolan/public_html/lead/app/functions/smarty_plugins/function.set_id.php';
        }
        fn_preload_lang_vars(array('calculate_shipping_cost', 'country', 'select_country', 'state', 'select_state', 'select_state', 'zip_postal_code', 'get_rates', 'select_shipping_method', 'vendor', 'none', 'free_shipping', 'no_shipping_required', 'free_shipping', 'text_no_shipping_methods', 'total', 'select', 'text_no_shipping_methods', 'recalculate_rates', 'select_shipping_method', 'get_rates', 'calculate_shipping_cost', 'country', 'select_country', 'state', 'select_state', 'select_state', 'zip_postal_code', 'get_rates', 'select_shipping_method', 'vendor', 'none', 'free_shipping', 'no_shipping_required', 'free_shipping', 'text_no_shipping_methods', 'total', 'select', 'text_no_shipping_methods', 'recalculate_rates', 'select_shipping_method', 'get_rates'));
        if ($_smarty_tpl->tpl_vars['runtime']->value['customization_mode']['design'] == "Y" && @constant('AREA') == "C") {
            $_smarty_tpl->_capture_stack[0][] = array("template_content", null, null);
            ob_start();
            ?>
<script type="text/javascript">
function fn_calculate_total_shipping() 
{
    var $ = Tygh.$;
    params = [];
    parents = $('#shipping_estimation');
    radio = $('input[type=radio]:checked', parents);

    $.each(radio, function(id, elm) {
        params.push({name: elm.name, value: elm.value});
    });

    params.push({name: $('#elm_zipcode').prop('name'), value: $('#elm_country').val()});
    params.push({name: $('#elm_state').prop('name'), value: $('#elm_state').val()});
    params.push({name: $('#elm_zipcode').prop('name'), value: $('#elm_zipcode').val()});

    url = fn_url('checkout.shipping_estimation');

    for (i in params) {
        url += '&' + params[i]['name'] + '=' + encodeURIComponent(params[i]['value']);
    }

    $.ceAjax('request', url, {
        result_ids: 'shipping_estimation',
        method: 'post'
    });
}
</script>


<?php 
            if ($_smarty_tpl->tpl_vars['location']->value == "sidebox") {
                ?>
    <?php 
                $_smarty_tpl->tpl_vars["prefix"] = new Smarty_variable("sidebox_", null, 0);
            }
            if ($_smarty_tpl->tpl_vars['location']->value == "popup") {
                ?>
    <?php 
                $_smarty_tpl->tpl_vars["buttons_class"] = new Smarty_variable("hidden", null, 0);
            } else {
                ?>
    <?php 
                $_smarty_tpl->tpl_vars["buttons_class"] = new Smarty_variable("buttons-container", null, 0);
            }
            if ($_smarty_tpl->tpl_vars['additional_id']->value) {
                ?>
    <?php 
                $_smarty_tpl->tpl_vars["class_suffix"] = new Smarty_variable("-" . (string) $_smarty_tpl->tpl_vars['additional_id']->value, null, 0);
                ?>
    <?php 
                $_smarty_tpl->tpl_vars["id_suffix"] = new Smarty_variable("_" . (string) $_smarty_tpl->tpl_vars['additional_id']->value, null, 0);
            }
            ?>

<?php 
            if ($_smarty_tpl->tpl_vars['location']->value != "sidebox" && $_smarty_tpl->tpl_vars['location']->value != "popup") {
                ?>

<div id="est_box<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
                ?>
">
    <div class="ty-estimation-box">
    <h3 class="ty-subheader"><?php 
                echo $_smarty_tpl->__("calculate_shipping_cost");
                ?>
</h3>
<?php 
            }
            ?>

        <div id="shipping_estimation<?php 
            if ($_smarty_tpl->tpl_vars['location']->value == "sidebox") {
                ?>
_sidebox<?php 
            }
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
">

            <?php 
            $_smarty_tpl->tpl_vars['states'] = new Smarty_variable(fn_get_all_states(1), null, 0);
            ?>
            <?php 
            if (!Smarty::$_smarty_vars['capture']['states_built']) {
                ?>
                <?php 
                echo $_smarty_tpl->getSubTemplate("views/profiles/components/profiles_scripts.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('states' => $_smarty_tpl->tpl_vars['states']->value), 0);
                ?>

                <?php 
                $_smarty_tpl->_capture_stack[0][] = array("states_built", null, null);
                ob_start();
                ?>
Y<?php 
                list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
                if (!empty($_capture_buffer)) {
                    if (isset($_capture_assign)) {
                        $_smarty_tpl->assign($_capture_assign, ob_get_contents());
                    }
                    if (isset($_capture_append)) {
                        $_smarty_tpl->append($_capture_append, ob_get_contents());
                    }
                    Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
                } else {
                    $_smarty_tpl->capture_error();
                }
                ?>
            <?php 
            }
            ?>

            <form class="cm-ajax" name="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
estimation_form<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
" action="<?php 
            echo htmlspecialchars(fn_url(''), ENT_QUOTES, 'UTF-8');
            ?>
" method="post">
                <?php 
            if ($_smarty_tpl->tpl_vars['location']->value == "sidebox") {
                ?>
<input type="hidden" name="location" value="sidebox" /><?php 
            }
            ?>
                <?php 
            if ($_smarty_tpl->tpl_vars['additional_id']->value) {
                ?>
<input type="hidden" name="additional_id" value="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['additional_id']->value, ENT_QUOTES, 'UTF-8');
                ?>
" /><?php 
            }
            ?>
                <input type="hidden" name="result_ids" value="shipping_estimation<?php 
            if ($_smarty_tpl->tpl_vars['location']->value == "sidebox") {
                ?>
_sidebox<?php 
            }
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
,shipping_estimation_buttons" />
                <div class="ty-control-group">
                    <label class="ty-control-group__label" for="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_country<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
"><?php 
            echo $_smarty_tpl->__("country");
            ?>
</label>
                    <select id="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_country<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
" class="cm-country cm-location-estimation<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['class_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
 ty-input-text-medium" name="customer_location[country]">
                        <option value="">- <?php 
            echo $_smarty_tpl->__("select_country");
            ?>
 -</option>
                        <?php 
            $_smarty_tpl->tpl_vars["countries"] = new Smarty_variable(fn_get_simple_countries(1), null, 0);
            ?>
                        <?php 
            $_smarty_tpl->tpl_vars["country"] = new Smarty_Variable();
            $_smarty_tpl->tpl_vars["country"]->_loop = false;
            $_smarty_tpl->tpl_vars["code"] = new Smarty_Variable();
            $_from = $_smarty_tpl->tpl_vars['countries']->value;
            if (!is_array($_from) && !is_object($_from)) {
                settype($_from, 'array');
            }
            foreach ($_from as $_smarty_tpl->tpl_vars["country"]->key => $_smarty_tpl->tpl_vars["country"]->value) {
                $_smarty_tpl->tpl_vars["country"]->_loop = true;
                $_smarty_tpl->tpl_vars["code"]->value = $_smarty_tpl->tpl_vars["country"]->key;
                ?>
                        <option value="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['code']->value, ENT_QUOTES, 'UTF-8');
                ?>
" <?php 
                if ($_smarty_tpl->tpl_vars['cart']->value['user_data']['s_country'] == $_smarty_tpl->tpl_vars['code']->value || !$_smarty_tpl->tpl_vars['cart']->value['user_data']['s_country'] && $_smarty_tpl->tpl_vars['code']->value == $_smarty_tpl->tpl_vars['settings']->value['General']['default_country']) {
                    ?>
selected="selected"<?php 
                }
                ?>
><?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['country']->value, ENT_QUOTES, 'UTF-8');
                ?>
</option>
                        <?php 
            }
            ?>
                    </select>
                </div>

                <?php 
            $_smarty_tpl->tpl_vars['_state'] = new Smarty_variable($_smarty_tpl->tpl_vars['cart']->value['user_data']['s_state'], null, 0);
            ?>

                <?php 
            if (fn_is_empty($_smarty_tpl->tpl_vars['_state']->value)) {
                ?>
                    <?php 
                $_smarty_tpl->tpl_vars['_state'] = new Smarty_variable($_smarty_tpl->tpl_vars['settings']->value['General']['default_state'], null, 0);
                ?>
                <?php 
            }
            ?>

                <div class="ty-control-group">
                    <label class="ty-control-group__label" for="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_state<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
"><?php 
            echo $_smarty_tpl->__("state");
            ?>
</label>
                    <select class="cm-state cm-location-estimation<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['class_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
 <?php 
            if (!$_smarty_tpl->tpl_vars['states']->value[$_smarty_tpl->tpl_vars['cart']->value['user_data']['s_country']]) {
                ?>
hidden<?php 
            }
            ?>
 ty-input-text-medium" id="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_state<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
" name="customer_location[state]">
                        <option value="">- <?php 
            echo $_smarty_tpl->__("select_state");
            ?>
 -</option>
                        <?php 
            $_smarty_tpl->tpl_vars['state'] = new Smarty_Variable();
            $_smarty_tpl->tpl_vars['state']->_loop = false;
            $_from = $_smarty_tpl->tpl_vars['states']->value[$_smarty_tpl->tpl_vars['cart']->value['user_data']['s_country']];
            if (!is_array($_from) && !is_object($_from)) {
                settype($_from, 'array');
            }
            foreach ($_from as $_smarty_tpl->tpl_vars['state']->key => $_smarty_tpl->tpl_vars['state']->value) {
                $_smarty_tpl->tpl_vars['state']->_loop = true;
                ?>
                            <option value="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['state']->value['code'], ENT_QUOTES, 'UTF-8');
                ?>
" <?php 
                if ($_smarty_tpl->tpl_vars['state']->value['code'] == $_smarty_tpl->tpl_vars['_state']->value) {
                    ?>
selected="selected"<?php 
                }
                ?>
><?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['state']->value['state'], ENT_QUOTES, 'UTF-8');
                ?>
</option>
                        <?php 
            }
            if (!$_smarty_tpl->tpl_vars['state']->_loop) {
                ?>
                            <option label="" value="">- <?php 
                echo $_smarty_tpl->__("select_state");
                ?>
 -</option>
                        <?php 
            }
            ?>
                    </select>
                    <input type="text" class="cm-state cm-location-estimation<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['class_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
 ty-input-text-medium <?php 
            if ($_smarty_tpl->tpl_vars['states']->value[$_smarty_tpl->tpl_vars['cart']->value['user_data']['s_country']]) {
                ?>
hidden<?php 
            }
            ?>
" id="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_state<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
_d" name="customer_location[state]" size="20" maxlength="64" value="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['_state']->value, ENT_QUOTES, 'UTF-8');
            ?>
" <?php 
            if ($_smarty_tpl->tpl_vars['states']->value[$_smarty_tpl->tpl_vars['cart']->value['user_data']['s_country']]) {
                ?>
disabled="disabled"<?php 
            }
            ?>
 />
                </div>

                <div class="ty-control-group">
                    <label class="ty-control-group__label" for="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_zipcode<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
"><?php 
            echo $_smarty_tpl->__("zip_postal_code");
            ?>
</label>
                    <input type="text" class="ty-input-text-medium" id="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_zipcode<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
" name="customer_location[zipcode]" size="20" value="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['cart']->value['user_data']['s_zipcode'], ENT_QUOTES, 'UTF-8');
            ?>
" />
                </div>

                <div class="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['buttons_class']->value, ENT_QUOTES, 'UTF-8');
            ?>
">
                    <?php 
            echo $_smarty_tpl->getSubTemplate("buttons/button.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('but_text' => __("get_rates"), 'but_name' => "dispatch[checkout.shipping_estimation]", 'but_role' => "text", 'but_id' => "but_get_rates"), 0);
            ?>

                </div>

            </form>

            <?php 
            if ($_smarty_tpl->tpl_vars['runtime']->value['mode'] == "shipping_estimation" || $_REQUEST['show_shippings'] == "Y") {
                ?>
                <?php 
                if (!$_smarty_tpl->tpl_vars['cart']->value['shipping_failed'] && !$_smarty_tpl->tpl_vars['cart']->value['company_shipping_failed']) {
                    ?>
                    <?php 
                    if ($_smarty_tpl->tpl_vars['location']->value == "popup") {
                        ?>
                        <div class="ty-estimation__title"><?php 
                        echo $_smarty_tpl->__("select_shipping_method");
                        ?>
</div>
                    <?php 
                    }
                    ?>
                    <form class="cm-ajax" name="<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
                    ?>
select_shipping_form<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
                    ?>
" action="<?php 
                    echo htmlspecialchars(fn_url(''), ENT_QUOTES, 'UTF-8');
                    ?>
" method="post">
                    <input type="hidden" name="redirect_mode" value="cart" />
                    <input type="hidden" name="result_ids" value="checkout_totals" />

                    <?php 
                    $_smarty_tpl->smarty->_tag_stack[] = array('hook', array('name' => "checkout:shipping_estimation"));
                    $_block_repeat = true;
                    echo smarty_block_hook(array('name' => "checkout:shipping_estimation"), null, $_smarty_tpl, $_block_repeat);
                    while ($_block_repeat) {
                        ob_start();
                        ?>


                    <?php 
                        $_smarty_tpl->tpl_vars['group'] = new Smarty_Variable();
                        $_smarty_tpl->tpl_vars['group']->_loop = false;
                        $_smarty_tpl->tpl_vars['group_key'] = new Smarty_Variable();
                        $_from = $_smarty_tpl->tpl_vars['product_groups']->value;
                        if (!is_array($_from) && !is_object($_from)) {
                            settype($_from, 'array');
                        }
                        foreach ($_from as $_smarty_tpl->tpl_vars['group']->key => $_smarty_tpl->tpl_vars['group']->value) {
                            $_smarty_tpl->tpl_vars['group']->_loop = true;
                            $_smarty_tpl->tpl_vars['group_key']->value = $_smarty_tpl->tpl_vars['group']->key;
                            ?>
                        <p>
                        <strong><?php 
                            echo $_smarty_tpl->__("vendor");
                            ?>
:&nbsp;</strong><?php 
                            echo htmlspecialchars(($tmp = @$_smarty_tpl->tpl_vars['group']->value['name']) === null || $tmp === '' ? $_smarty_tpl->__("none") : $tmp, ENT_QUOTES, 'UTF-8');
                            ?>

                        </p>
                        <?php 
                            if (!fn_allowed_for("ULTIMATE") || count($_smarty_tpl->tpl_vars['product_groups']->value) > 1) {
                                ?>
                            <ul>
                            <?php 
                                $_smarty_tpl->tpl_vars["product"] = new Smarty_Variable();
                                $_smarty_tpl->tpl_vars["product"]->_loop = false;
                                $_from = $_smarty_tpl->tpl_vars['group']->value['products'];
                                if (!is_array($_from) && !is_object($_from)) {
                                    settype($_from, 'array');
                                }
                                foreach ($_from as $_smarty_tpl->tpl_vars["product"]->key => $_smarty_tpl->tpl_vars["product"]->value) {
                                    $_smarty_tpl->tpl_vars["product"]->_loop = true;
                                    ?>
                                <li>
                                    <?php 
                                    if ($_smarty_tpl->tpl_vars['product']->value['product']) {
                                        ?>
                                        <?php 
                                        echo $_smarty_tpl->tpl_vars['product']->value['product'];
                                        ?>

                                    <?php 
                                    } else {
                                        ?>
                                        <?php 
                                        echo htmlspecialchars(fn_get_product_name($_smarty_tpl->tpl_vars['product']->value['product_id']), ENT_QUOTES, 'UTF-8');
                                        ?>

                                    <?php 
                                    }
                                    ?>
                                </li>
                            <?php 
                                }
                                ?>
                            </ul>
                        <?php 
                            }
                            ?>

                        <?php 
                            if ($_smarty_tpl->tpl_vars['group']->value['shippings'] && !$_smarty_tpl->tpl_vars['group']->value['all_edp_free_shipping'] && !$_smarty_tpl->tpl_vars['group']->value['all_free_shipping'] && !$_smarty_tpl->tpl_vars['group']->value['free_shipping'] && !$_smarty_tpl->tpl_vars['group']->value['shipping_no_required']) {
                                ?>
                            <?php 
                                $_smarty_tpl->tpl_vars["shipping"] = new Smarty_Variable();
                                $_smarty_tpl->tpl_vars["shipping"]->_loop = false;
                                $_from = $_smarty_tpl->tpl_vars['group']->value['shippings'];
                                if (!is_array($_from) && !is_object($_from)) {
                                    settype($_from, 'array');
                                }
                                foreach ($_from as $_smarty_tpl->tpl_vars["shipping"]->key => $_smarty_tpl->tpl_vars["shipping"]->value) {
                                    $_smarty_tpl->tpl_vars["shipping"]->_loop = true;
                                    ?>

                                <?php 
                                    if ($_smarty_tpl->tpl_vars['cart']->value['chosen_shipping'][$_smarty_tpl->tpl_vars['group_key']->value] == $_smarty_tpl->tpl_vars['shipping']->value['shipping_id']) {
                                        ?>
                                    <?php 
                                        $_smarty_tpl->tpl_vars["checked"] = new Smarty_variable("checked=\"checked\"", null, 0);
                                        ?>
                                <?php 
                                    } else {
                                        ?>
                                    <?php 
                                        $_smarty_tpl->tpl_vars["checked"] = new Smarty_variable('', null, 0);
                                        ?>
                                <?php 
                                    }
                                    ?>

                                <?php 
                                    if ($_smarty_tpl->tpl_vars['shipping']->value['delivery_time']) {
                                        ?>
                                    <?php 
                                        $_smarty_tpl->tpl_vars["delivery_time"] = new Smarty_variable("(" . (string) $_smarty_tpl->tpl_vars['shipping']->value['delivery_time'] . ")", null, 0);
                                        ?>
                                <?php 
                                    } else {
                                        ?>
                                    <?php 
                                        $_smarty_tpl->tpl_vars["delivery_time"] = new Smarty_variable('', null, 0);
                                        ?>
                                <?php 
                                    }
                                    ?>

                                <?php 
                                    $_smarty_tpl->smarty->_tag_stack[] = array('hook', array('name' => "checkout:shipping_estimation_method"));
                                    $_block_repeat = true;
                                    echo smarty_block_hook(array('name' => "checkout:shipping_estimation_method"), null, $_smarty_tpl, $_block_repeat);
                                    while ($_block_repeat) {
                                        ob_start();
                                        ?>

                                <?php 
                                        if ($_smarty_tpl->tpl_vars['shipping']->value['rate']) {
                                            ?>
                                    <?php 
                                            $_smarty_tpl->_capture_stack[0][] = array('default', "rate", null);
                                            ob_start();
                                            echo $_smarty_tpl->getSubTemplate("common/price.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('value' => $_smarty_tpl->tpl_vars['shipping']->value['rate']), 0);
                                            list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
                                            if (!empty($_capture_buffer)) {
                                                if (isset($_capture_assign)) {
                                                    $_smarty_tpl->assign($_capture_assign, ob_get_contents());
                                                }
                                                if (isset($_capture_append)) {
                                                    $_smarty_tpl->append($_capture_append, ob_get_contents());
                                                }
                                                Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
                                            } else {
                                                $_smarty_tpl->capture_error();
                                            }
                                            ?>
                                    <?php 
                                            if ($_smarty_tpl->tpl_vars['shipping']->value['inc_tax']) {
                                                ?>
                                        <?php 
                                                $_smarty_tpl->tpl_vars["rate"] = new Smarty_variable((string) $_smarty_tpl->tpl_vars['rate']->value . " (", null, 0);
                                                ?>
                                        <?php 
                                                if ($_smarty_tpl->tpl_vars['shipping']->value['taxed_price'] && $_smarty_tpl->tpl_vars['shipping']->value['taxed_price'] != $_smarty_tpl->tpl_vars['shipping']->value['rate']) {
                                                    ?>
                                            <?php 
                                                    $_smarty_tpl->_capture_stack[0][] = array('default', "tax", null);
                                                    ob_start();
                                                    echo $_smarty_tpl->getSubTemplate("common/price.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('value' => $_smarty_tpl->tpl_vars['shipping']->value['taxed_price'], 'class' => "ty-nowrap"), 0);
                                                    list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
                                                    if (!empty($_capture_buffer)) {
                                                        if (isset($_capture_assign)) {
                                                            $_smarty_tpl->assign($_capture_assign, ob_get_contents());
                                                        }
                                                        if (isset($_capture_append)) {
                                                            $_smarty_tpl->append($_capture_append, ob_get_contents());
                                                        }
                                                        Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
                                                    } else {
                                                        $_smarty_tpl->capture_error();
                                                    }
                                                    ?>
                                            <?php 
                                                    $_smarty_tpl->tpl_vars["rate"] = new Smarty_variable((string) $_smarty_tpl->tpl_vars['rate']->value . " (" . (string) $_smarty_tpl->tpl_vars['tax']->value . " ", null, 0);
                                                    ?>
                                        <?php 
                                                }
                                                ?>
                                        <?php 
                                                $_smarty_tpl->tpl_vars["inc_tax_lang"] = new Smarty_variable($_smarty_tpl->__('inc_tax'), null, 0);
                                                ?>
                                        <?php 
                                                $_smarty_tpl->tpl_vars["rate"] = new Smarty_variable((string) $_smarty_tpl->tpl_vars['rate']->value . (string) $_smarty_tpl->tpl_vars['inc_tax_lang']->value . ")", null, 0);
                                                ?>
                                    <?php 
                                            }
                                            ?>
                                <?php 
                                        } else {
                                            ?>
                                    <?php 
                                            $_smarty_tpl->tpl_vars["rate"] = new Smarty_variable($_smarty_tpl->__("free_shipping"), null, 0);
                                            ?>
                                <?php 
                                        }
                                        ?>

                                <p>
                                    <input type="radio" class="ty-valign" id="sh_<?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['group_key']->value, ENT_QUOTES, 'UTF-8');
                                        ?>
_<?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['shipping']->value['shipping_id'], ENT_QUOTES, 'UTF-8');
                                        ?>
" name="shipping_ids[<?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['group_key']->value, ENT_QUOTES, 'UTF-8');
                                        ?>
]" value="<?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['shipping']->value['shipping_id'], ENT_QUOTES, 'UTF-8');
                                        ?>
" onclick="fn_calculate_total_shipping();" <?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['checked']->value, ENT_QUOTES, 'UTF-8');
                                        ?>
 /><label for="sh_<?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['group_key']->value, ENT_QUOTES, 'UTF-8');
                                        ?>
_<?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['shipping']->value['shipping_id'], ENT_QUOTES, 'UTF-8');
                                        ?>
" class="ty-valign"><?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['shipping']->value['shipping'], ENT_QUOTES, 'UTF-8');
                                        ?>
 <?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['delivery_time']->value, ENT_QUOTES, 'UTF-8');
                                        ?>
 - <?php 
                                        echo $_smarty_tpl->tpl_vars['rate']->value;
                                        ?>
</label>
                                </p>
                                <?php 
                                        $_block_content = ob_get_clean();
                                        $_block_repeat = false;
                                        echo smarty_block_hook(array('name' => "checkout:shipping_estimation_method"), $_block_content, $_smarty_tpl, $_block_repeat);
                                    }
                                    array_pop($_smarty_tpl->smarty->_tag_stack);
                                    ?>

                            <?php 
                                }
                                ?>

                        <?php 
                            } else {
                                ?>
                            <?php 
                                if ($_smarty_tpl->tpl_vars['group']->value['all_edp_free_shipping'] || $_smarty_tpl->tpl_vars['group']->value['shipping_no_required']) {
                                    ?>
                                <p><?php 
                                    echo $_smarty_tpl->__("no_shipping_required");
                                    ?>
</p>
                            <?php 
                                } elseif ($_smarty_tpl->tpl_vars['group']->value['all_free_shipping'] || $_smarty_tpl->tpl_vars['group']->value['free_shipping']) {
                                    ?>
                                <p><?php 
                                    echo $_smarty_tpl->__("free_shipping");
                                    ?>
</p>
                            <?php 
                                } else {
                                    ?>
                                <p><?php 
                                    echo $_smarty_tpl->__("text_no_shipping_methods");
                                    ?>
</p>
                            <?php 
                                }
                                ?>
                        <?php 
                            }
                            ?>

                    <?php 
                        }
                        ?>

                    <p><strong><?php 
                        echo $_smarty_tpl->__("total");
                        ?>
:</strong>&nbsp;<?php 
                        echo $_smarty_tpl->getSubTemplate("common/price.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('value' => $_smarty_tpl->tpl_vars['cart']->value['display_shipping_cost'], 'class' => "ty-price"), 0);
                        ?>
</p>

                    <?php 
                        $_block_content = ob_get_clean();
                        $_block_repeat = false;
                        echo smarty_block_hook(array('name' => "checkout:shipping_estimation"), $_block_content, $_smarty_tpl, $_block_repeat);
                    }
                    array_pop($_smarty_tpl->smarty->_tag_stack);
                    ?>


                    <div class="<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['buttons_class']->value, ENT_QUOTES, 'UTF-8');
                    ?>
">
                        <?php 
                    echo $_smarty_tpl->getSubTemplate("buttons/button.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('but_text' => __("select"), 'but_role' => "text", 'but_name' => "dispatch[checkout.update_shipping]", 'but_id' => "but_select_shipping", 'but_meta' => "cm-dialog-closer"), 0);
                    ?>

                    </div>

                    </form>
                <?php 
                } else {
                    ?>
                    <p class="ty-error-text">
                        <?php 
                    echo $_smarty_tpl->__("text_no_shipping_methods");
                    ?>

                    </p>
                <?php 
                }
                ?>

            <?php 
            }
            ?>
        <!--shipping_estimation<?php 
            if ($_smarty_tpl->tpl_vars['location']->value == "sidebox") {
                ?>
_sidebox<?php 
            }
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
--></div>

<?php 
            if ($_smarty_tpl->tpl_vars['location']->value != "sidebox" && $_smarty_tpl->tpl_vars['location']->value != "popup") {
                ?>
    </div>
</div>
<?php 
            }
            ?>

<?php 
            if ($_smarty_tpl->tpl_vars['location']->value == "popup") {
                ?>
<div class="ty-estimation-buttons buttons-container" id="shipping_estimation_buttons">
    <?php 
                if ($_smarty_tpl->tpl_vars['runtime']->value['mode'] == "shipping_estimation" || $_REQUEST['show_shippings'] == "Y") {
                    ?>
        <?php 
                    echo $_smarty_tpl->getSubTemplate("buttons/button.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('but_text' => __("recalculate_rates"), 'but_external_click_id' => "but_get_rates", 'but_role' => "text", 'but_meta' => "ty-btn__secondary cm-external-click ty-float-right ty-estimation-buttons__rate"), 0);
                    ?>


        <?php 
                    echo $_smarty_tpl->getSubTemplate("buttons/button.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('but_text' => __("select_shipping_method"), 'but_external_click_id' => "but_select_shipping", 'but_meta' => "ty-btn__secondary cm-external-click cm-dialog-closer"), 0);
                    ?>

    <?php 
                } else {
                    ?>
        <?php 
                    echo $_smarty_tpl->getSubTemplate("buttons/button.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('but_text' => __("get_rates"), 'but_external_click_id' => "but_get_rates", 'but_meta' => "ty-btn__secondary cm-external-click"), 0);
                    ?>

    <?php 
                }
                ?>
<!--shipping_estimation_buttons--></div>
<?php 
            }
            list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
            if (!empty($_capture_buffer)) {
                if (isset($_capture_assign)) {
                    $_smarty_tpl->assign($_capture_assign, ob_get_contents());
                }
                if (isset($_capture_append)) {
                    $_smarty_tpl->append($_capture_append, ob_get_contents());
                }
                Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
            } else {
                $_smarty_tpl->capture_error();
            }
            if (trim(Smarty::$_smarty_vars['capture']['template_content'])) {
                if ($_smarty_tpl->tpl_vars['auth']->value['area'] == "A") {
                    ?>
<span class="cm-template-box template-box" data-ca-te-template="views/checkout/components/shipping_estimation.tpl" id="<?php 
                    echo smarty_function_set_id(array('name' => "views/checkout/components/shipping_estimation.tpl"), $_smarty_tpl);
                    ?>
"><div class="cm-template-icon icon-edit ty-icon-edit hidden"></div><?php 
                    echo Smarty::$_smarty_vars['capture']['template_content'];
                    ?>
<!--[/tpl_id]--></span><?php 
                } else {
                    echo Smarty::$_smarty_vars['capture']['template_content'];
                }
            }
        } else {
            ?>
<script type="text/javascript">
function fn_calculate_total_shipping() 
{
    var $ = Tygh.$;
    params = [];
    parents = $('#shipping_estimation');
    radio = $('input[type=radio]:checked', parents);

    $.each(radio, function(id, elm) {
        params.push({name: elm.name, value: elm.value});
    });

    params.push({name: $('#elm_zipcode').prop('name'), value: $('#elm_country').val()});
    params.push({name: $('#elm_state').prop('name'), value: $('#elm_state').val()});
    params.push({name: $('#elm_zipcode').prop('name'), value: $('#elm_zipcode').val()});

    url = fn_url('checkout.shipping_estimation');

    for (i in params) {
        url += '&' + params[i]['name'] + '=' + encodeURIComponent(params[i]['value']);
    }

    $.ceAjax('request', url, {
        result_ids: 'shipping_estimation',
        method: 'post'
    });
}
</script>


<?php 
            if ($_smarty_tpl->tpl_vars['location']->value == "sidebox") {
                ?>
    <?php 
                $_smarty_tpl->tpl_vars["prefix"] = new Smarty_variable("sidebox_", null, 0);
            }
            if ($_smarty_tpl->tpl_vars['location']->value == "popup") {
                ?>
    <?php 
                $_smarty_tpl->tpl_vars["buttons_class"] = new Smarty_variable("hidden", null, 0);
            } else {
                ?>
    <?php 
                $_smarty_tpl->tpl_vars["buttons_class"] = new Smarty_variable("buttons-container", null, 0);
            }
            if ($_smarty_tpl->tpl_vars['additional_id']->value) {
                ?>
    <?php 
                $_smarty_tpl->tpl_vars["class_suffix"] = new Smarty_variable("-" . (string) $_smarty_tpl->tpl_vars['additional_id']->value, null, 0);
                ?>
    <?php 
                $_smarty_tpl->tpl_vars["id_suffix"] = new Smarty_variable("_" . (string) $_smarty_tpl->tpl_vars['additional_id']->value, null, 0);
            }
            ?>

<?php 
            if ($_smarty_tpl->tpl_vars['location']->value != "sidebox" && $_smarty_tpl->tpl_vars['location']->value != "popup") {
                ?>

<div id="est_box<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
                ?>
">
    <div class="ty-estimation-box">
    <h3 class="ty-subheader"><?php 
                echo $_smarty_tpl->__("calculate_shipping_cost");
                ?>
</h3>
<?php 
            }
            ?>

        <div id="shipping_estimation<?php 
            if ($_smarty_tpl->tpl_vars['location']->value == "sidebox") {
                ?>
_sidebox<?php 
            }
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
">

            <?php 
            $_smarty_tpl->tpl_vars['states'] = new Smarty_variable(fn_get_all_states(1), null, 0);
            ?>
            <?php 
            if (!Smarty::$_smarty_vars['capture']['states_built']) {
                ?>
                <?php 
                echo $_smarty_tpl->getSubTemplate("views/profiles/components/profiles_scripts.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('states' => $_smarty_tpl->tpl_vars['states']->value), 0);
                ?>

                <?php 
                $_smarty_tpl->_capture_stack[0][] = array("states_built", null, null);
                ob_start();
                ?>
Y<?php 
                list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
                if (!empty($_capture_buffer)) {
                    if (isset($_capture_assign)) {
                        $_smarty_tpl->assign($_capture_assign, ob_get_contents());
                    }
                    if (isset($_capture_append)) {
                        $_smarty_tpl->append($_capture_append, ob_get_contents());
                    }
                    Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
                } else {
                    $_smarty_tpl->capture_error();
                }
                ?>
            <?php 
            }
            ?>

            <form class="cm-ajax" name="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
estimation_form<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
" action="<?php 
            echo htmlspecialchars(fn_url(''), ENT_QUOTES, 'UTF-8');
            ?>
" method="post">
                <?php 
            if ($_smarty_tpl->tpl_vars['location']->value == "sidebox") {
                ?>
<input type="hidden" name="location" value="sidebox" /><?php 
            }
            ?>
                <?php 
            if ($_smarty_tpl->tpl_vars['additional_id']->value) {
                ?>
<input type="hidden" name="additional_id" value="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['additional_id']->value, ENT_QUOTES, 'UTF-8');
                ?>
" /><?php 
            }
            ?>
                <input type="hidden" name="result_ids" value="shipping_estimation<?php 
            if ($_smarty_tpl->tpl_vars['location']->value == "sidebox") {
                ?>
_sidebox<?php 
            }
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
,shipping_estimation_buttons" />
                <div class="ty-control-group">
                    <label class="ty-control-group__label" for="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_country<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
"><?php 
            echo $_smarty_tpl->__("country");
            ?>
</label>
                    <select id="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_country<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
" class="cm-country cm-location-estimation<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['class_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
 ty-input-text-medium" name="customer_location[country]">
                        <option value="">- <?php 
            echo $_smarty_tpl->__("select_country");
            ?>
 -</option>
                        <?php 
            $_smarty_tpl->tpl_vars["countries"] = new Smarty_variable(fn_get_simple_countries(1), null, 0);
            ?>
                        <?php 
            $_smarty_tpl->tpl_vars["country"] = new Smarty_Variable();
            $_smarty_tpl->tpl_vars["country"]->_loop = false;
            $_smarty_tpl->tpl_vars["code"] = new Smarty_Variable();
            $_from = $_smarty_tpl->tpl_vars['countries']->value;
            if (!is_array($_from) && !is_object($_from)) {
                settype($_from, 'array');
            }
            foreach ($_from as $_smarty_tpl->tpl_vars["country"]->key => $_smarty_tpl->tpl_vars["country"]->value) {
                $_smarty_tpl->tpl_vars["country"]->_loop = true;
                $_smarty_tpl->tpl_vars["code"]->value = $_smarty_tpl->tpl_vars["country"]->key;
                ?>
                        <option value="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['code']->value, ENT_QUOTES, 'UTF-8');
                ?>
" <?php 
                if ($_smarty_tpl->tpl_vars['cart']->value['user_data']['s_country'] == $_smarty_tpl->tpl_vars['code']->value || !$_smarty_tpl->tpl_vars['cart']->value['user_data']['s_country'] && $_smarty_tpl->tpl_vars['code']->value == $_smarty_tpl->tpl_vars['settings']->value['General']['default_country']) {
                    ?>
selected="selected"<?php 
                }
                ?>
><?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['country']->value, ENT_QUOTES, 'UTF-8');
                ?>
</option>
                        <?php 
            }
            ?>
                    </select>
                </div>

                <?php 
            $_smarty_tpl->tpl_vars['_state'] = new Smarty_variable($_smarty_tpl->tpl_vars['cart']->value['user_data']['s_state'], null, 0);
            ?>

                <?php 
            if (fn_is_empty($_smarty_tpl->tpl_vars['_state']->value)) {
                ?>
                    <?php 
                $_smarty_tpl->tpl_vars['_state'] = new Smarty_variable($_smarty_tpl->tpl_vars['settings']->value['General']['default_state'], null, 0);
                ?>
                <?php 
            }
            ?>

                <div class="ty-control-group">
                    <label class="ty-control-group__label" for="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_state<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
"><?php 
            echo $_smarty_tpl->__("state");
            ?>
</label>
                    <select class="cm-state cm-location-estimation<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['class_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
 <?php 
            if (!$_smarty_tpl->tpl_vars['states']->value[$_smarty_tpl->tpl_vars['cart']->value['user_data']['s_country']]) {
                ?>
hidden<?php 
            }
            ?>
 ty-input-text-medium" id="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_state<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
" name="customer_location[state]">
                        <option value="">- <?php 
            echo $_smarty_tpl->__("select_state");
            ?>
 -</option>
                        <?php 
            $_smarty_tpl->tpl_vars['state'] = new Smarty_Variable();
            $_smarty_tpl->tpl_vars['state']->_loop = false;
            $_from = $_smarty_tpl->tpl_vars['states']->value[$_smarty_tpl->tpl_vars['cart']->value['user_data']['s_country']];
            if (!is_array($_from) && !is_object($_from)) {
                settype($_from, 'array');
            }
            foreach ($_from as $_smarty_tpl->tpl_vars['state']->key => $_smarty_tpl->tpl_vars['state']->value) {
                $_smarty_tpl->tpl_vars['state']->_loop = true;
                ?>
                            <option value="<?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['state']->value['code'], ENT_QUOTES, 'UTF-8');
                ?>
" <?php 
                if ($_smarty_tpl->tpl_vars['state']->value['code'] == $_smarty_tpl->tpl_vars['_state']->value) {
                    ?>
selected="selected"<?php 
                }
                ?>
><?php 
                echo htmlspecialchars($_smarty_tpl->tpl_vars['state']->value['state'], ENT_QUOTES, 'UTF-8');
                ?>
</option>
                        <?php 
            }
            if (!$_smarty_tpl->tpl_vars['state']->_loop) {
                ?>
                            <option label="" value="">- <?php 
                echo $_smarty_tpl->__("select_state");
                ?>
 -</option>
                        <?php 
            }
            ?>
                    </select>
                    <input type="text" class="cm-state cm-location-estimation<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['class_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
 ty-input-text-medium <?php 
            if ($_smarty_tpl->tpl_vars['states']->value[$_smarty_tpl->tpl_vars['cart']->value['user_data']['s_country']]) {
                ?>
hidden<?php 
            }
            ?>
" id="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_state<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
_d" name="customer_location[state]" size="20" maxlength="64" value="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['_state']->value, ENT_QUOTES, 'UTF-8');
            ?>
" <?php 
            if ($_smarty_tpl->tpl_vars['states']->value[$_smarty_tpl->tpl_vars['cart']->value['user_data']['s_country']]) {
                ?>
disabled="disabled"<?php 
            }
            ?>
 />
                </div>

                <div class="ty-control-group">
                    <label class="ty-control-group__label" for="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_zipcode<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
"><?php 
            echo $_smarty_tpl->__("zip_postal_code");
            ?>
</label>
                    <input type="text" class="ty-input-text-medium" id="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
            ?>
elm_zipcode<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
" name="customer_location[zipcode]" size="20" value="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['cart']->value['user_data']['s_zipcode'], ENT_QUOTES, 'UTF-8');
            ?>
" />
                </div>

                <div class="<?php 
            echo htmlspecialchars($_smarty_tpl->tpl_vars['buttons_class']->value, ENT_QUOTES, 'UTF-8');
            ?>
">
                    <?php 
            echo $_smarty_tpl->getSubTemplate("buttons/button.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('but_text' => __("get_rates"), 'but_name' => "dispatch[checkout.shipping_estimation]", 'but_role' => "text", 'but_id' => "but_get_rates"), 0);
            ?>

                </div>

            </form>

            <?php 
            if ($_smarty_tpl->tpl_vars['runtime']->value['mode'] == "shipping_estimation" || $_REQUEST['show_shippings'] == "Y") {
                ?>
                <?php 
                if (!$_smarty_tpl->tpl_vars['cart']->value['shipping_failed'] && !$_smarty_tpl->tpl_vars['cart']->value['company_shipping_failed']) {
                    ?>
                    <?php 
                    if ($_smarty_tpl->tpl_vars['location']->value == "popup") {
                        ?>
                        <div class="ty-estimation__title"><?php 
                        echo $_smarty_tpl->__("select_shipping_method");
                        ?>
</div>
                    <?php 
                    }
                    ?>
                    <form class="cm-ajax" name="<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['prefix']->value, ENT_QUOTES, 'UTF-8');
                    ?>
select_shipping_form<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
                    ?>
" action="<?php 
                    echo htmlspecialchars(fn_url(''), ENT_QUOTES, 'UTF-8');
                    ?>
" method="post">
                    <input type="hidden" name="redirect_mode" value="cart" />
                    <input type="hidden" name="result_ids" value="checkout_totals" />

                    <?php 
                    $_smarty_tpl->smarty->_tag_stack[] = array('hook', array('name' => "checkout:shipping_estimation"));
                    $_block_repeat = true;
                    echo smarty_block_hook(array('name' => "checkout:shipping_estimation"), null, $_smarty_tpl, $_block_repeat);
                    while ($_block_repeat) {
                        ob_start();
                        ?>


                    <?php 
                        $_smarty_tpl->tpl_vars['group'] = new Smarty_Variable();
                        $_smarty_tpl->tpl_vars['group']->_loop = false;
                        $_smarty_tpl->tpl_vars['group_key'] = new Smarty_Variable();
                        $_from = $_smarty_tpl->tpl_vars['product_groups']->value;
                        if (!is_array($_from) && !is_object($_from)) {
                            settype($_from, 'array');
                        }
                        foreach ($_from as $_smarty_tpl->tpl_vars['group']->key => $_smarty_tpl->tpl_vars['group']->value) {
                            $_smarty_tpl->tpl_vars['group']->_loop = true;
                            $_smarty_tpl->tpl_vars['group_key']->value = $_smarty_tpl->tpl_vars['group']->key;
                            ?>
                        <p>
                        <strong><?php 
                            echo $_smarty_tpl->__("vendor");
                            ?>
:&nbsp;</strong><?php 
                            echo htmlspecialchars(($tmp = @$_smarty_tpl->tpl_vars['group']->value['name']) === null || $tmp === '' ? $_smarty_tpl->__("none") : $tmp, ENT_QUOTES, 'UTF-8');
                            ?>

                        </p>
                        <?php 
                            if (!fn_allowed_for("ULTIMATE") || count($_smarty_tpl->tpl_vars['product_groups']->value) > 1) {
                                ?>
                            <ul>
                            <?php 
                                $_smarty_tpl->tpl_vars["product"] = new Smarty_Variable();
                                $_smarty_tpl->tpl_vars["product"]->_loop = false;
                                $_from = $_smarty_tpl->tpl_vars['group']->value['products'];
                                if (!is_array($_from) && !is_object($_from)) {
                                    settype($_from, 'array');
                                }
                                foreach ($_from as $_smarty_tpl->tpl_vars["product"]->key => $_smarty_tpl->tpl_vars["product"]->value) {
                                    $_smarty_tpl->tpl_vars["product"]->_loop = true;
                                    ?>
                                <li>
                                    <?php 
                                    if ($_smarty_tpl->tpl_vars['product']->value['product']) {
                                        ?>
                                        <?php 
                                        echo $_smarty_tpl->tpl_vars['product']->value['product'];
                                        ?>

                                    <?php 
                                    } else {
                                        ?>
                                        <?php 
                                        echo htmlspecialchars(fn_get_product_name($_smarty_tpl->tpl_vars['product']->value['product_id']), ENT_QUOTES, 'UTF-8');
                                        ?>

                                    <?php 
                                    }
                                    ?>
                                </li>
                            <?php 
                                }
                                ?>
                            </ul>
                        <?php 
                            }
                            ?>

                        <?php 
                            if ($_smarty_tpl->tpl_vars['group']->value['shippings'] && !$_smarty_tpl->tpl_vars['group']->value['all_edp_free_shipping'] && !$_smarty_tpl->tpl_vars['group']->value['all_free_shipping'] && !$_smarty_tpl->tpl_vars['group']->value['free_shipping'] && !$_smarty_tpl->tpl_vars['group']->value['shipping_no_required']) {
                                ?>
                            <?php 
                                $_smarty_tpl->tpl_vars["shipping"] = new Smarty_Variable();
                                $_smarty_tpl->tpl_vars["shipping"]->_loop = false;
                                $_from = $_smarty_tpl->tpl_vars['group']->value['shippings'];
                                if (!is_array($_from) && !is_object($_from)) {
                                    settype($_from, 'array');
                                }
                                foreach ($_from as $_smarty_tpl->tpl_vars["shipping"]->key => $_smarty_tpl->tpl_vars["shipping"]->value) {
                                    $_smarty_tpl->tpl_vars["shipping"]->_loop = true;
                                    ?>

                                <?php 
                                    if ($_smarty_tpl->tpl_vars['cart']->value['chosen_shipping'][$_smarty_tpl->tpl_vars['group_key']->value] == $_smarty_tpl->tpl_vars['shipping']->value['shipping_id']) {
                                        ?>
                                    <?php 
                                        $_smarty_tpl->tpl_vars["checked"] = new Smarty_variable("checked=\"checked\"", null, 0);
                                        ?>
                                <?php 
                                    } else {
                                        ?>
                                    <?php 
                                        $_smarty_tpl->tpl_vars["checked"] = new Smarty_variable('', null, 0);
                                        ?>
                                <?php 
                                    }
                                    ?>

                                <?php 
                                    if ($_smarty_tpl->tpl_vars['shipping']->value['delivery_time']) {
                                        ?>
                                    <?php 
                                        $_smarty_tpl->tpl_vars["delivery_time"] = new Smarty_variable("(" . (string) $_smarty_tpl->tpl_vars['shipping']->value['delivery_time'] . ")", null, 0);
                                        ?>
                                <?php 
                                    } else {
                                        ?>
                                    <?php 
                                        $_smarty_tpl->tpl_vars["delivery_time"] = new Smarty_variable('', null, 0);
                                        ?>
                                <?php 
                                    }
                                    ?>

                                <?php 
                                    $_smarty_tpl->smarty->_tag_stack[] = array('hook', array('name' => "checkout:shipping_estimation_method"));
                                    $_block_repeat = true;
                                    echo smarty_block_hook(array('name' => "checkout:shipping_estimation_method"), null, $_smarty_tpl, $_block_repeat);
                                    while ($_block_repeat) {
                                        ob_start();
                                        ?>

                                <?php 
                                        if ($_smarty_tpl->tpl_vars['shipping']->value['rate']) {
                                            ?>
                                    <?php 
                                            $_smarty_tpl->_capture_stack[0][] = array('default', "rate", null);
                                            ob_start();
                                            echo $_smarty_tpl->getSubTemplate("common/price.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('value' => $_smarty_tpl->tpl_vars['shipping']->value['rate']), 0);
                                            list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
                                            if (!empty($_capture_buffer)) {
                                                if (isset($_capture_assign)) {
                                                    $_smarty_tpl->assign($_capture_assign, ob_get_contents());
                                                }
                                                if (isset($_capture_append)) {
                                                    $_smarty_tpl->append($_capture_append, ob_get_contents());
                                                }
                                                Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
                                            } else {
                                                $_smarty_tpl->capture_error();
                                            }
                                            ?>
                                    <?php 
                                            if ($_smarty_tpl->tpl_vars['shipping']->value['inc_tax']) {
                                                ?>
                                        <?php 
                                                $_smarty_tpl->tpl_vars["rate"] = new Smarty_variable((string) $_smarty_tpl->tpl_vars['rate']->value . " (", null, 0);
                                                ?>
                                        <?php 
                                                if ($_smarty_tpl->tpl_vars['shipping']->value['taxed_price'] && $_smarty_tpl->tpl_vars['shipping']->value['taxed_price'] != $_smarty_tpl->tpl_vars['shipping']->value['rate']) {
                                                    ?>
                                            <?php 
                                                    $_smarty_tpl->_capture_stack[0][] = array('default', "tax", null);
                                                    ob_start();
                                                    echo $_smarty_tpl->getSubTemplate("common/price.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('value' => $_smarty_tpl->tpl_vars['shipping']->value['taxed_price'], 'class' => "ty-nowrap"), 0);
                                                    list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
                                                    if (!empty($_capture_buffer)) {
                                                        if (isset($_capture_assign)) {
                                                            $_smarty_tpl->assign($_capture_assign, ob_get_contents());
                                                        }
                                                        if (isset($_capture_append)) {
                                                            $_smarty_tpl->append($_capture_append, ob_get_contents());
                                                        }
                                                        Smarty::$_smarty_vars['capture'][$_capture_buffer] = ob_get_clean();
                                                    } else {
                                                        $_smarty_tpl->capture_error();
                                                    }
                                                    ?>
                                            <?php 
                                                    $_smarty_tpl->tpl_vars["rate"] = new Smarty_variable((string) $_smarty_tpl->tpl_vars['rate']->value . " (" . (string) $_smarty_tpl->tpl_vars['tax']->value . " ", null, 0);
                                                    ?>
                                        <?php 
                                                }
                                                ?>
                                        <?php 
                                                $_smarty_tpl->tpl_vars["inc_tax_lang"] = new Smarty_variable($_smarty_tpl->__('inc_tax'), null, 0);
                                                ?>
                                        <?php 
                                                $_smarty_tpl->tpl_vars["rate"] = new Smarty_variable((string) $_smarty_tpl->tpl_vars['rate']->value . (string) $_smarty_tpl->tpl_vars['inc_tax_lang']->value . ")", null, 0);
                                                ?>
                                    <?php 
                                            }
                                            ?>
                                <?php 
                                        } else {
                                            ?>
                                    <?php 
                                            $_smarty_tpl->tpl_vars["rate"] = new Smarty_variable($_smarty_tpl->__("free_shipping"), null, 0);
                                            ?>
                                <?php 
                                        }
                                        ?>

                                <p>
                                    <input type="radio" class="ty-valign" id="sh_<?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['group_key']->value, ENT_QUOTES, 'UTF-8');
                                        ?>
_<?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['shipping']->value['shipping_id'], ENT_QUOTES, 'UTF-8');
                                        ?>
" name="shipping_ids[<?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['group_key']->value, ENT_QUOTES, 'UTF-8');
                                        ?>
]" value="<?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['shipping']->value['shipping_id'], ENT_QUOTES, 'UTF-8');
                                        ?>
" onclick="fn_calculate_total_shipping();" <?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['checked']->value, ENT_QUOTES, 'UTF-8');
                                        ?>
 /><label for="sh_<?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['group_key']->value, ENT_QUOTES, 'UTF-8');
                                        ?>
_<?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['shipping']->value['shipping_id'], ENT_QUOTES, 'UTF-8');
                                        ?>
" class="ty-valign"><?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['shipping']->value['shipping'], ENT_QUOTES, 'UTF-8');
                                        ?>
 <?php 
                                        echo htmlspecialchars($_smarty_tpl->tpl_vars['delivery_time']->value, ENT_QUOTES, 'UTF-8');
                                        ?>
 - <?php 
                                        echo $_smarty_tpl->tpl_vars['rate']->value;
                                        ?>
</label>
                                </p>
                                <?php 
                                        $_block_content = ob_get_clean();
                                        $_block_repeat = false;
                                        echo smarty_block_hook(array('name' => "checkout:shipping_estimation_method"), $_block_content, $_smarty_tpl, $_block_repeat);
                                    }
                                    array_pop($_smarty_tpl->smarty->_tag_stack);
                                    ?>

                            <?php 
                                }
                                ?>

                        <?php 
                            } else {
                                ?>
                            <?php 
                                if ($_smarty_tpl->tpl_vars['group']->value['all_edp_free_shipping'] || $_smarty_tpl->tpl_vars['group']->value['shipping_no_required']) {
                                    ?>
                                <p><?php 
                                    echo $_smarty_tpl->__("no_shipping_required");
                                    ?>
</p>
                            <?php 
                                } elseif ($_smarty_tpl->tpl_vars['group']->value['all_free_shipping'] || $_smarty_tpl->tpl_vars['group']->value['free_shipping']) {
                                    ?>
                                <p><?php 
                                    echo $_smarty_tpl->__("free_shipping");
                                    ?>
</p>
                            <?php 
                                } else {
                                    ?>
                                <p><?php 
                                    echo $_smarty_tpl->__("text_no_shipping_methods");
                                    ?>
</p>
                            <?php 
                                }
                                ?>
                        <?php 
                            }
                            ?>

                    <?php 
                        }
                        ?>

                    <p><strong><?php 
                        echo $_smarty_tpl->__("total");
                        ?>
:</strong>&nbsp;<?php 
                        echo $_smarty_tpl->getSubTemplate("common/price.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('value' => $_smarty_tpl->tpl_vars['cart']->value['display_shipping_cost'], 'class' => "ty-price"), 0);
                        ?>
</p>

                    <?php 
                        $_block_content = ob_get_clean();
                        $_block_repeat = false;
                        echo smarty_block_hook(array('name' => "checkout:shipping_estimation"), $_block_content, $_smarty_tpl, $_block_repeat);
                    }
                    array_pop($_smarty_tpl->smarty->_tag_stack);
                    ?>


                    <div class="<?php 
                    echo htmlspecialchars($_smarty_tpl->tpl_vars['buttons_class']->value, ENT_QUOTES, 'UTF-8');
                    ?>
">
                        <?php 
                    echo $_smarty_tpl->getSubTemplate("buttons/button.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('but_text' => __("select"), 'but_role' => "text", 'but_name' => "dispatch[checkout.update_shipping]", 'but_id' => "but_select_shipping", 'but_meta' => "cm-dialog-closer"), 0);
                    ?>

                    </div>

                    </form>
                <?php 
                } else {
                    ?>
                    <p class="ty-error-text">
                        <?php 
                    echo $_smarty_tpl->__("text_no_shipping_methods");
                    ?>

                    </p>
                <?php 
                }
                ?>

            <?php 
            }
            ?>
        <!--shipping_estimation<?php 
            if ($_smarty_tpl->tpl_vars['location']->value == "sidebox") {
                ?>
_sidebox<?php 
            }
            echo htmlspecialchars($_smarty_tpl->tpl_vars['id_suffix']->value, ENT_QUOTES, 'UTF-8');
            ?>
--></div>

<?php 
            if ($_smarty_tpl->tpl_vars['location']->value != "sidebox" && $_smarty_tpl->tpl_vars['location']->value != "popup") {
                ?>
    </div>
</div>
<?php 
            }
            ?>

<?php 
            if ($_smarty_tpl->tpl_vars['location']->value == "popup") {
                ?>
<div class="ty-estimation-buttons buttons-container" id="shipping_estimation_buttons">
    <?php 
                if ($_smarty_tpl->tpl_vars['runtime']->value['mode'] == "shipping_estimation" || $_REQUEST['show_shippings'] == "Y") {
                    ?>
        <?php 
                    echo $_smarty_tpl->getSubTemplate("buttons/button.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('but_text' => __("recalculate_rates"), 'but_external_click_id' => "but_get_rates", 'but_role' => "text", 'but_meta' => "ty-btn__secondary cm-external-click ty-float-right ty-estimation-buttons__rate"), 0);
                    ?>


        <?php 
                    echo $_smarty_tpl->getSubTemplate("buttons/button.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('but_text' => __("select_shipping_method"), 'but_external_click_id' => "but_select_shipping", 'but_meta' => "ty-btn__secondary cm-external-click cm-dialog-closer"), 0);
                    ?>

    <?php 
                } else {
                    ?>
        <?php 
                    echo $_smarty_tpl->getSubTemplate("buttons/button.tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 0, null, array('but_text' => __("get_rates"), 'but_external_click_id' => "but_get_rates", 'but_meta' => "ty-btn__secondary cm-external-click"), 0);
                    ?>

    <?php 
                }
                ?>
<!--shipping_estimation_buttons--></div>
<?php 
            }
        }
    }
Esempio n. 30
0
function fn_twg_get_product_tabs($params)
{
    $allowed_page_types = array('T', 'L', 'F');
    $allowed_templates = array('blocks/product_tabs/features.tpl', 'blocks/product_tabs/description.tpl');
    $allowed_block_types = array('html_block', 'pages', 'products', 'categories', 'banners');
    $tabs = ProductTabs::instance()->getList('', $params['product_id'], $params['descr_sl']);
    foreach ($tabs as $k => $tab) {
        $isAllowedType = $tab['tab_type'] == 'B';
        $isAllowedType = ($isAllowedType or $tab['tab_type'] == 'T' and in_array($tab['template'], $allowed_templates));
        if (empty($params['all_tabs']) && $tab['status'] != 'A' || !$isAllowedType) {
            unset($tabs[$k]);
            continue;
        }
        if ($tab['tab_type'] == 'B') {
            $block = TwigmoBlock::getBlock(array('block_id' => $tab['block_id'], 'area' => 'C'));
            if (empty($block['type']) || !in_array($block['type'], $allowed_block_types)) {
                unset($tabs[$k]);
                continue;
            }
            $block_scheme = SchemesManager::getBlockScheme($block['type'], array());
            if ($block['type'] == 'html_block') {
                $tabs[$k]['html'] = $block['content']['content'];
            } elseif (!empty($block_scheme['content']) && !empty($block_scheme['content']['items'])) {
                // Products and categories: get items
                $template_variable = 'items';
                $field = $block_scheme['content']['items'];
                $items = RenderManager::getValue($template_variable, $field, $block_scheme, $block);
                // Filter pages - only texts, links and forms posible
                if ($block['type'] == 'pages') {
                    foreach ($items as $item_id => $item) {
                        if (!in_array($item['page_type'], $allowed_page_types)) {
                            unset($items[$item_id]);
                        }
                    }
                }
                if (fn_is_empty($items)) {
                    unset($tabs[$k]);
                    continue;
                }
                $block_data = array('total_items' => count($items));
                // Images
                $image_params = TwigmoSettings::get('images.cart');
                if ($block['type'] == 'products' or $block['type'] == 'categories') {
                    $object_type = $block['type'] == 'products' ? 'product' : 'category';
                    foreach ($items as $items_id => $item) {
                        $main_pair = fn_get_image_pairs($item[$object_type . '_id'], $object_type, 'M', true, true);
                        if (!empty($main_pair)) {
                            $items[$items_id]['icon'] = TwigmoImage::getApiImageData($main_pair, $object_type, 'icon', $image_params);
                        }
                    }
                }
                // Banners properties
                if ($block['type'] == 'banners') {
                    $rotation = $block['properties']['template'] == 'addons/banners/blocks/carousel.tpl' ? 'Y' : 'N';
                    $block_data['delay'] = $rotation == 'Y' ? $block['properties']['delay'] : 0;
                    $object_type = 'banner';
                }
                $block_data[$block['type']] = Api::getAsList($block['type'], $items);
                $tabs[$k] = array_merge($tab, $block_data);
            }
        } else {
            if ($tab['template'] == 'blocks/product_tabs/features.tpl') {
                $tabs[$k]['type'] = 'features';
            }
            if ($tab['template'] == 'blocks/product_tabs/description.tpl') {
                $tabs[$k]['type'] = 'description';
            }
        }
    }
    return array_values($tabs);
    // reindex
}