Example #1
0
 /**
  * Process simple request to shipping service server
  *
  * @return string Server response
  */
 public function getSimpleRates()
 {
     $data = $this->getRequestData();
     // Russian post server works very unstably, that is why we cannot use multithreading.
     $key = md5(serialize($data['data']));
     $response = fn_get_session_data($key);
     if (empty($response)) {
         $response = Http::get($data['url'], $data['data']);
         fn_set_session_data($key, $response);
     }
     return $response;
 }
                $_suffix = '.complete?order_id=' . $_REQUEST['order_id'];
            }
        } else {
            return array(CONTROLLER_STATUS_DENIED);
        }
    }
    return array(CONTROLLER_STATUS_OK, "checkout{$_suffix}");
}
if ($mode == 'update_cart_shipping_estimations') {
    $user_id = $auth['user_id'];
    if (empty($user_id)) {
        if (fn_get_session_data('cu_id')) {
            $user_id = fn_get_session_data('cu_id');
        } else {
            $user_id = fn_crc32(uniqid(TIME));
            fn_set_session_data('cu_id', $user_id, COOKIE_ALIVE_TIME);
        }
    }
    list($cart_products1, $product_groups1) = fn_calculate_cart_content($cart, $auth, Registry::get('settings.General.estimate_shipping_cost') == 'Y' ? 'A' : 'S', true, 'F', true);
    $new_estimations = fn_ls_delivery_estimation_total($cart_products1);
    foreach ($cart['products'] as $combination_hash => $product) {
        db_query('UPDATE ?:user_session_products SET ls_shipping_estimation=?s WHERE user_id=?s AND item_id =?s AND type = ?s', $new_estimations['individual_estimations'][$combination_hash], $user_id, $combination_hash, 'C');
    }
    exit;
}
if ($mode == 'checkout_estimation') {
    list($cart_products, $product_groups) = fn_calculate_cart_content($cart, $auth, Registry::get('settings.General.estimate_shipping_cost') == 'Y' ? 'A' : 'S', true, 'F', true);
    //$cart_products = $_SESSION['cart']['products'];
    //$cart_products = $cart['products'];
    //echo json_encode($cart_products);
    $new_estimations = fn_ls_delivery_estimation_total($cart_products);
Example #3
0
// Generate dashboard
if ($mode == 'index') {
    // Check for feedback request
    if ((!Registry::get('runtime.company_id') || Registry::get('runtime.simple_ultimate')) && (Registry::get('settings.General.feedback_type') == 'auto' || fn_allowed_for('ULTIMATE:FREE')) && fn_is_expired_storage_data('send_feedback', SECONDS_IN_DAY * 30)) {
        $redirect_url = 'feedback.send?action=auto&redirect_url=' . urlencode(Registry::get('config.current_url'));
        return array(CONTROLLER_STATUS_REDIRECT, $redirect_url);
    }
    $time_periods = array(DateTimeHelper::PERIOD_TODAY, DateTimeHelper::PERIOD_YESTERDAY, DateTimeHelper::PERIOD_THIS_MONTH, DateTimeHelper::PERIOD_LAST_MONTH, DateTimeHelper::PERIOD_THIS_YEAR, DateTimeHelper::PERIOD_LAST_YEAR);
    $time_period = DateTimeHelper::getPeriod(DateTimeHelper::PERIOD_MONTH_AGO_TILL_NOW);
    // Predefined period selected
    if (isset($_REQUEST['time_period']) && in_array($_REQUEST['time_period'], $time_periods)) {
        $time_period = DateTimeHelper::getPeriod($_REQUEST['time_period']);
        fn_set_session_data('dashboard_selected_period', serialize(array('period' => $_REQUEST['time_period'])));
    } elseif (isset($_REQUEST['time_from'], $_REQUEST['time_to'])) {
        $time_period = DateTimeHelper::createCustomPeriod('@' . $_REQUEST['time_from'], '@' . $_REQUEST['time_to']);
        fn_set_session_data('dashboard_selected_period', serialize(array('from' => $time_period['from']->format(DateTime::ISO8601), 'to' => $time_period['to']->format(DateTime::ISO8601))));
    } elseif ($timeframe = fn_get_session_data('dashboard_selected_period')) {
        $timeframe = unserialize($timeframe);
        if (isset($timeframe['period']) && in_array($timeframe['period'], $time_periods)) {
            $time_period = DateTimeHelper::getPeriod($timeframe['period']);
        } elseif (isset($timeframe['from'], $timeframe['to'])) {
            $time_period = DateTimeHelper::createCustomPeriod($timeframe['from'], $timeframe['to']);
        }
    }
    $timestamp_from = $time_period['from']->getTimestamp();
    $timestamp_to = $time_period['to']->getTimestamp();
    $time_difference = $timestamp_to - $timestamp_from;
    $is_day = $timestamp_to - $timestamp_from <= SECONDS_IN_DAY ? true : false;
    $stats = '';
    if (!defined('HTTPS')) {
        $stats .= base64_decode('PGltZyBzcmM9Imh0dHA6Ly93d3cuY3MtY2FydC5jb20vaW1hZ2VzL2JhY2tncm91bmQuZ2lmIiBoZWlnaHQ9IjEiIHdpZHRoPSIxIiBhbHQ9IiIgLz4=');
Example #4
0
             // Insecure admin script
             if (!fn_is_development() && Registry::get('config.admin_index') == 'admin.php') {
                 fn_set_notification('E', __('warning'), __('warning_insecure_admin_script', array('[href]' => Registry::get('config.resources.admin_protection_url'))), 'S');
             }
             if (!fn_is_development() && is_file(Registry::get('config.dir.root') . '/install/index.php')) {
                 fn_set_notification('W', __('warning'), __('delete_install_folder'), 'S');
             }
             if (Development::isEnabled('compile_check')) {
                 fn_set_notification('W', __('warning'), __('warning_store_optimization_dev', array('[link]' => fn_url("themes.manage"))));
             }
             fn_set_hook('set_admin_notification', $user_data);
         }
     }
     if (!empty($_REQUEST['remember_me'])) {
         fn_set_session_data(AREA . '_user_id', $user_data['user_id'], COOKIE_ALIVE_TIME);
         fn_set_session_data(AREA . '_password', $user_data['password'], COOKIE_ALIVE_TIME);
     }
     if (!empty($_REQUEST['return_url'])) {
         $redirect_url = $_REQUEST['return_url'];
     }
     unset($_REQUEST['redirect_url']);
     if (AREA == 'C') {
         fn_set_notification('N', __('notice'), __('successful_login'));
     }
     if (AREA == 'A' && Registry::get('runtime.unsupported_browser')) {
         $redirect_url = "upgrade_center.ie7notify";
     }
     unset($_SESSION['cart']['edit_step']);
 } else {
     //
     // Login incorrect
Example #5
0
*                                                                          *
****************************************************************************
* PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
* "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
****************************************************************************/
// [norton] [add_bean_bag_filling]
use Tygh\Registry;
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
$cart =& $_SESSION['cart'];
//fn_set_notification('I', 'mode', print_r($mode,true));
if ($mode == 'cart') {
    $current_postcode = fn_get_session_data('postcode');
    if (!empty($_REQUEST['postcode']) && $_REQUEST['postcode'] == 'valid' && empty($current_postcode)) {
        fn_set_session_data('postcode', 'valid', SECONDS_IN_HOUR);
    }
}
// if($mode== 'add2')
// {
// 	fn_set_notification('I', 'mode', print_r($_REQUEST,true));
// }
// //
// Delete discount coupon
//
if ($mode == 'add_bean_bag_filling' or $mode == 'add') {
    // 	if (empty($auth['user_id']) && Registry::get('settings.General.allow_anonymous_shopping') != 'Y') {
    // 		return array(CONTROLLER_STATUS_REDIRECT, "auth.login_form?return_url=" . urlencode($_SERVER['HTTP_REFERER']));
    // 	}
    //fn_set_notification('I', 'product_data', print_r($_REQUEST['product_data'],true));
    //var_dump($_REQUEST['product_data']);
Example #6
0
function fn_save_cart_content(&$cart, $user_id, $type = 'C', $user_type = 'R')
{
    if (empty($user_id)) {
        if (fn_get_session_data('cu_id')) {
            $user_id = fn_get_session_data('cu_id');
        } else {
            $user_id = fn_crc32(uniqid(TIME));
            fn_set_session_data('cu_id', $user_id, COOKIE_ALIVE_TIME);
        }
        $user_type = 'U';
    }
    if (!empty($user_id)) {
        $condition = db_quote("user_id = ?i AND type = ?s AND user_type = ?s", $user_id, $type, $user_type);
        if (fn_allowed_for('ULTIMATE')) {
            $condition .= fn_get_company_condition('?:user_session_products.company_id');
        }
        db_query("DELETE FROM ?:user_session_products WHERE " . $condition);
        if (!empty($cart['products']) && is_array($cart['products'])) {
            $_cart_prods = $cart['products'];
            foreach ($_cart_prods as $_item_id => $_prod) {
                $_cart_prods[$_item_id]['user_id'] = $user_id;
                $_cart_prods[$_item_id]['timestamp'] = TIME;
                $_cart_prods[$_item_id]['type'] = $type;
                $_cart_prods[$_item_id]['user_type'] = $user_type;
                $_cart_prods[$_item_id]['item_id'] = $_item_id;
                $_cart_prods[$_item_id]['item_type'] = 'P';
                $_cart_prods[$_item_id]['extra'] = serialize($_prod);
                $_cart_prods[$_item_id]['amount'] = empty($_cart_prods[$_item_id]['amount']) ? 1 : $_cart_prods[$_item_id]['amount'];
                $_cart_prods[$_item_id]['session_id'] = Session::getId();
                $ip = fn_get_ip();
                $_cart_prods[$_item_id]['ip_address'] = fn_ip_to_db($ip['host']);
                if (fn_allowed_for('ULTIMATE')) {
                    $_cart_prods[$_item_id]['company_id'] = Registry::get('runtime.company_id');
                }
                if (!empty($_cart_prods[$_item_id])) {
                    db_query('REPLACE INTO ?:user_session_products ?e', $_cart_prods[$_item_id]);
                }
            }
        }
        fn_set_hook('save_cart', $cart, $user_id, $type);
    }
    return true;
}
            $pp_response['reason_text'] = 'Payment processed.';
            $pp_response["transaction_id"] = $response->transactionId;
            fn_finish_payment($merchant_order_id, $pp_response);
            fn_order_placement_routines('route', $merchant_order_id);
        } catch (HpsException $e) {
            fn_set_notification('E', __('error'), "Transaction Failed: " . $e->getMessage() . " With order id: " . $_REQUEST['merchant_order_id']);
            fn_order_placement_routines('checkout_redirect');
        }
    }
    exit;
} else {
    $url = fn_url("payment_notification.return?payment=heartland", AREA, 'current');
    $checkout_url = "js/securesubmit.js";
    $key = $processor_data['processor_params']['publickey'];
    fn_set_session_data('secretkey', $processor_data['processor_params']['secretkey']);
    fn_set_session_data('order_info', $order_info);
    $formhtml = '<form name="securesubmit-form" id="securesubmit-form" action="' . $url . '" target="_parent" method="POST">
                <input type="hidden" name="securesubmit_token" id="securesubmit_token" />
                <input type="hidden" name="merchant_order_id" id="order_id" value="' . $order_id . '"/>
            </form>';
    echo <<<EOT
    <script src="{$checkout_url}"></script>
    {$formhtml}


<style>
body, p, div, li {
    color: #333;
    font-family: Open Sans;
    font-size: 13px;
    font-style: normal;
Example #8
0
 /**
  * Process simple request to shipping service server
  *
  * @return string Server response
  */
 public function getSimpleRates()
 {
     $data = $this->getRequestData();
     $key = md5(serialize($data['data']));
     $edost_data = fn_get_session_data($key);
     if (empty($edost_data)) {
         $response = Http::post($data['url'], $data['data'], array('timeout' => $this->_timeout));
         fn_set_session_data($key, $response);
     } else {
         $response = $edost_data;
     }
     return $response;
 }
Example #9
0
function fn_sdek_calculate_cost_by_shipment($order_info, $shipping_info, $shipment_info, $rec_city_code)
{
    $total = $weight = 0;
    $goods = array();
    $length = $width = $height = 20;
    $sum_rate = 0;
    $packages = array();
    $shipping_info['module'] = $shipment_info['carrier'];
    foreach ($shipment_info['products'] as $item_id => $amount) {
        $product = $order_info['products'][$item_id];
        $total += $product['subtotal'];
        $product_extra = db_get_row("SELECT shipping_params, weight FROM ?:products WHERE product_id = ?i", $product['product_id']);
        if (!empty($product_extra['weight']) && $product_extra['weight'] != 0) {
            $product_weight = $product_extra['weight'];
        } else {
            $product_weight = 0.01;
        }
        $p_ship_params = unserialize($product_extra['shipping_params']);
        $package_length = empty($p_ship_params['box_length']) ? $length : $p_ship_params['box_length'];
        $package_width = empty($p_ship_params['box_width']) ? $width : $p_ship_params['box_width'];
        $package_height = empty($p_ship_params['box_height']) ? $height : $p_ship_params['box_height'];
        $weight_ar = fn_expand_weight($product_weight);
        $weight = round($weight_ar['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
        $good['weight'] = $weight;
        $good['length'] = $package_length;
        $good['width'] = $package_width;
        $good['height'] = $package_height;
        for ($x = 1; $x <= $amount; $x++) {
            $goods[] = $good;
        }
        foreach ($order_info['product_groups'] as $product_groups) {
            if (!empty($product_groups['products'][$item_id])) {
                $products[$item_id] = $product_groups['products'][$item_id];
                $products[$item_id] = array_merge($products[$item_id], $good);
                $products[$item_id]['amount'] = $amount;
            }
            $shipping_info['package_info'] = $product_groups['package_info'];
        }
    }
    $data_package = Shippings::groupProductsList($products, $shipping_info['package_info']['location']);
    $data_package = reset($data_package);
    $shipping_info['package_info_full'] = $data_package['package_info_full'];
    $shipping_info['package_info'] = $data_package['package_info_full'];
    $url = 'http://api.edostavka.ru/calculator/calculate_price_by_json.php';
    $r_url = 'http://lk.cdek.ru:8080/calculator/calculate_price_by_json.php';
    $post['version'] = '1.0';
    $post['dateExecute'] = date('Y-m-d');
    if (!empty($shipping_info['service_params']['dateexecute'])) {
        $timestamp = TIME + $shipping_info['service_params']['dateexecute'] * SECONDS_IN_DAY;
        $dateexecute = date('Y-m-d', $timestamp);
    } else {
        $dateexecute = date('Y-m-d');
    }
    $post['dateExecute'] = $dateexecute;
    if (!empty($shipping_settings['authlogin'])) {
        $post['authLogin'] = $shipping_info['service_params']['authlogin'];
        $post['secure'] = !empty($shipping_info['service_params']['authpassword']) ? md5($post['dateExecute'] . "&" . $shipping_info['service_params']['authpassword']) : '';
    }
    $post['authLogin'] = $shipping_info['service_params']['authlogin'];
    $post['secure'] = md5($post['dateExecute'] . "&" . $shipping_info['service_params']['authpassword']);
    $post['senderCityId'] = $shipping_info['service_params']['from_city_id'];
    $post['receiverCityId'] = $rec_city_code;
    $post['tariffId'] = $shipping_info['service_params']['tariffid'];
    $post['goods'] = $goods;
    $post = json_encode($post);
    $key = md5($post);
    $sdek_data = fn_get_session_data($key);
    $content = json_encode($post);
    if (empty($sdek_data)) {
        $response = Http::post($url, $post, array('Content-Type: application/json', 'Content-Length: ' . strlen($content)), array('timeout' => SDEK_TIMEOUT));
        if (empty($response)) {
            $response = Http::post($r_url, $post, array('Content-Type: application/json', 'Content-Length: ' . strlen($content)), array('timeout' => SDEK_TIMEOUT));
        }
        fn_set_session_data($key, $response);
    } else {
        $response = $sdek_data;
    }
    $result = json_decode($response, true);
    $sum_rate = Shippings::calculateRates(array($shipping_info));
    $sum_rate = reset($sum_rate);
    $result = $sum_rate['price'];
    return $result;
}
Example #10
0
/**
 * Init localizations
 *
 * @param array $params request parameters
 * @return boolean true if localizations exists, false otherwise
 */
function fn_init_localization($params)
{
    if (AREA != 'C') {
        return array(INIT_STATUS_OK);
    }
    $locs = db_get_hash_array("SELECT localization_id, custom_weight_settings, weight_symbol, weight_unit FROM ?:localizations WHERE status = 'A'", 'localization_id');
    if (!empty($locs)) {
        if (!empty($_REQUEST['lc']) && !empty($locs[$_REQUEST['lc']])) {
            $cart_localization = $_REQUEST['lc'];
        } elseif (($l = fn_get_session_data('cart_localization')) && !empty($locs[$l])) {
            $cart_localization = $l;
        } else {
            $_ip = fn_get_ip(true);
            $_country = fn_get_country_by_ip($_ip['host']);
            $_lngs = db_get_hash_single_array("SELECT lang_code, 1 as 'l' FROM ?:languages WHERE status = 'A'", array('lang_code', 'l'));
            $_language = fn_get_browser_language($_lngs);
            $cart_localization = db_get_field("SELECT localization_id, COUNT(localization_id) as c FROM ?:localization_elements WHERE (element = ?s AND element_type = 'C') OR (element = ?s AND element_type = 'L') GROUP BY localization_id ORDER BY c DESC LIMIT 1", $_country, $_language);
            if (empty($cart_localization) || empty($locs[$cart_localization])) {
                $cart_localization = db_get_field("SELECT localization_id FROM ?:localizations WHERE status = 'A' AND is_default = 'Y'");
            }
        }
        if (empty($cart_localization)) {
            reset($locs);
            $cart_localization = key($locs);
        }
        if ($cart_localization != fn_get_session_data('cart_localization')) {
            fn_set_session_data('cart_localization', $cart_localization, COOKIE_ALIVE_TIME);
        }
        if ($locs[$cart_localization]['custom_weight_settings'] == 'Y') {
            Registry::set('config.localization.weight_symbol', $locs[$cart_localization]['weight_symbol']);
            Registry::set('config.localization.weight_unit', $locs[$cart_localization]['weight_unit']);
        }
        fn_define('CART_LOCALIZATION', $cart_localization);
    }
    return array(INIT_STATUS_OK);
}
Example #11
0
function fn_save_cart_content(&$cart, $user_id, $type = 'C', $user_type = 'R')
{
    if (empty($user_id)) {
        if (fn_get_session_data('cu_id')) {
            $user_id = fn_get_session_data('cu_id');
        } else {
            $user_id = fn_crc32(uniqid(TIME));
            fn_set_session_data('cu_id', $user_id, COOKIE_ALIVE_TIME);
        }
        $user_type = 'U';
    }
    if (!empty($user_id)) {
        $condition = db_quote("user_id = ?i AND type = ?s AND user_type = ?s", $user_id, $type, $user_type);
        if (fn_allowed_for('ULTIMATE')) {
            $condition .= fn_get_company_condition('?:user_session_products.company_id');
        }
        //var_dump($ls_individual_estimations);die();
        db_query("DELETE FROM ?:user_session_products WHERE " . $condition);
        //        $cart_products = $_SESSION['cart']['products'];
        //        //get linked products and its details
        //        fn_ls_get_linked_products($cart_products);
        //        //get common linked products order total
        //        fn_ls_linked_products_order_total($cart_products); //pass here only linked products that are in cart
        //
        //        fn_linked_products_in_cart_amount($cart_products);
        //
        //        //$new_estimations = fn_ls_delivery_estimation_total($cart_products);
        //
        //        //var_dump($new_estimations);echo"<br/>________<br/>";die();
        //
        //        $ls_individual_estimations = array();
        //
        //        foreach ($cart_products as $combination_hash => $product) {
        //            //shipping estimation for individual products
        //            $ls_individual_estimations[$combination_hash] = fn_ls_delivery_estimation($product, $combination_hash, 0);
        //            //check if the estimation is Sunday
        //            if (date("D", $ls_individual_estimations[$combination_hash]) === 'Sun') {
        //            //add one more day to the estimation
        //                $ls_individual_estimations[$combination_hash] = $ls_individual_estimations[$combination_hash] + (24 * 60 * 60);
        //            }
        //        }
        //        var_dump($ls_individual_estimations);
        //        die();
        $ls_individual_estimations = array();
        foreach ($cart['products'] as $combination_hash => $product) {
            if ($cart['new_estimations']['individual_estimations'][$combination_hash]) {
                $ls_individual_estimations[$combination_hash] = $cart['new_estimations']['individual_estimations'][$combination_hash];
            }
        }
        if (!empty($cart['products']) && is_array($cart['products'])) {
            $_cart_prods = $cart['products'];
            foreach ($_cart_prods as $_item_id => $_prod) {
                $_cart_prods[$_item_id]['user_id'] = $user_id;
                $_cart_prods[$_item_id]['timestamp'] = TIME;
                $_cart_prods[$_item_id]['type'] = $type;
                $_cart_prods[$_item_id]['user_type'] = $user_type;
                $_cart_prods[$_item_id]['item_id'] = $_item_id;
                $_cart_prods[$_item_id]['item_type'] = 'P';
                $_cart_prods[$_item_id]['extra'] = serialize($_prod);
                //$_cart_prods[$_item_id]['price'] = $_prod['price'];
                $_cart_prods[$_item_id]['amount'] = empty($_cart_prods[$_item_id]['amount']) ? 1 : $_cart_prods[$_item_id]['amount'];
                $_cart_prods[$_item_id]['session_id'] = Session::getId();
                if ($ls_individual_estimations[$_item_id]) {
                    $_cart_prods[$_item_id]['ls_shipping_estimation'] = $ls_individual_estimations[$_item_id];
                }
                $ip = fn_get_ip();
                $_cart_prods[$_item_id]['ip_address'] = $ip['host'];
                if (fn_allowed_for('ULTIMATE')) {
                    $_cart_prods[$_item_id]['company_id'] = Registry::get('runtime.company_id');
                }
                if (!empty($_cart_prods[$_item_id])) {
                    db_query('REPLACE INTO ?:user_session_products ?e', $_cart_prods[$_item_id]);
                }
            }
        }
        fn_set_hook('save_cart', $cart, $user_id, $type);
    }
    return true;
}
Example #12
0
 /**
  * Process simple request to shipping service server
  *
  * @return string Server response
  */
 public function getSimpleRates()
 {
     $data = $this->getRequestData();
     $key = md5($data['data']);
     $sdek_data = fn_get_session_data($key);
     $data_string = json_encode($data['data']);
     if (empty($sdek_data)) {
         $response = Http::post($data['url'], $data['data'], array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string)));
         fn_set_session_data($key, $response);
     } else {
         $response = $sdek_data;
     }
     return $response;
 }
Example #13
0
 public function getIndex($address)
 {
     $address = preg_split('/[ ,-]+/', trim($address));
     $address = implode('+', $address);
     $key_address = md5($address);
     $response = fn_get_session_data($key_address);
     if (empty($response)) {
         $url = "https://geocode-maps.yandex.ru/1.x/";
         $data = array('geocode' => $address, 'format' => 'json', 'results' => 1);
         $response = Http::post($url, $data);
         fn_set_session_data($key_address, $response, YD_CACHE_DAY);
     }
     $response = json_decode($response, true);
     $address_line = $this->findElmArray($response, 'AddressLine');
     $address_line = reset($address_line);
     $result = '';
     $url = $this->url_api . 'getIndex';
     if (!empty($address_line) && !empty($this->client_ids)) {
         $data = array('client_id' => $this->client_ids['client_id'], 'sender_id' => $this->client_ids['sender_ids'], 'address' => $address_line);
         $data['secret_key'] = $this->generateSecretKey('getIndex', $data);
         $result = $this->getStatic($data['secret_key']);
         if (empty($result)) {
             $result = $this->request($url, $data);
             $this->setStatic($data['secret_key'], $result);
         }
     }
     return $result;
 }
Example #14
0
 /**
  * Process simple request to shipping service server
  *
  * @return string Server response
  */
 public function getSimpleRates()
 {
     $data = $this->getRequestData();
     $key = md5(serialize($data['data']));
     $pecom_data = fn_get_session_data($key);
     if (empty($pecom_data)) {
         $response = Http::get($data['url'], $data['data']);
         $response = json_decode($response, true);
         fn_set_session_data($key, $response);
     } else {
         $response = $pecom_data;
     }
     return $response;
 }
Example #15
0
 protected function getNearPickpoints($pickup_points)
 {
     $key = md5($this->_shipping_info['shipping_id'] . implode('_', $this->_shipping_info['service_params']['deliveries']) . trim($this->_shipping_info['package_info']['location']['address']) . trim($this->_shipping_info['package_info']['location']['city']));
     $near_pickoints = fn_get_session_data($key);
     if (empty($near_pickoints)) {
         $address = preg_split('/[ ,]+/', trim($this->_shipping_info['package_info']['location']['address']));
         $address[] = trim($this->_shipping_info['package_info']['location']['city']);
         $url = "https://geocode-maps.yandex.ru/1.x/";
         $data = array('geocode' => implode('+', $address), 'format' => 'json', 'results' => 2, 'sco' => 'longlat');
         $response = Http::post($url, $data);
         $response = json_decode($response, true);
         $response = $response['response']['GeoObjectCollection'];
         if ($response['metaDataProperty']['GeocoderResponseMetaData']['found'] > 0) {
             $object = reset($response['featureMember']);
             $object = $object['GeoObject'];
             $ll_address = explode(' ', $object['Point']['pos']);
         }
         $lat_pickoints = array();
         $lng_pickoints = array();
         $near_pickoints = array();
         foreach ($pickup_points as $point) {
             $lat_pickoints[$point['id']] = $point['lat'];
             $lng_pickoints[$point['id']] = $point['lng'];
             $near_pickoints[$point['id']] = sqrt(pow($lat_pickoints[$point['id']] - $ll_address[1], 2) + pow($lng_pickoints[$point['id']] - $ll_address[0], 2));
         }
         asort($near_pickoints);
         fn_set_session_data($key, $near_pickoints, YD_CACHE_SESSION);
     }
     return $near_pickoints;
 }
Example #16
0
/**
 * Stores cart content in the customer's profile
 *
 * @param array $cart Cart contents
 * @param int $user_id User identifier
 * @param string $type Cart type
 * @param string $user_type User type
 * @return bool True
 */
function fn_save_cart_content(&$cart, $user_id, $type = 'C', $user_type = 'R')
{
    /**
     * Actions before storing cart content in the customer's profile
     *
     * @param array $cart Cart contents
     * @param int $user_id User identifier
     * @param string $type Cart type
     * @param string $user_type User type
     */
    fn_set_hook('save_cart_content_pre', $cart, $user_id, $type, $user_type);
    if (empty($user_id)) {
        if (fn_get_session_data('cu_id')) {
            $user_id = fn_get_session_data('cu_id');
        } else {
            $user_id = fn_crc32(uniqid(TIME));
            fn_set_session_data('cu_id', $user_id, COOKIE_ALIVE_TIME);
        }
        $user_type = 'U';
    }
    if (!empty($user_id)) {
        $condition = fn_user_session_products_condition(array('user_id' => $user_id, 'type' => $type, 'user_type' => $user_type, 'get_session_user_id' => false));
        db_query("DELETE FROM ?:user_session_products WHERE " . $condition);
        if (!empty($cart['products']) && is_array($cart['products'])) {
            $_cart_prods = $cart['products'];
            foreach ($_cart_prods as $_item_id => $_prod) {
                $_cart_prods[$_item_id]['user_id'] = $user_id;
                $_cart_prods[$_item_id]['timestamp'] = TIME;
                $_cart_prods[$_item_id]['type'] = $type;
                $_cart_prods[$_item_id]['user_type'] = $user_type;
                $_cart_prods[$_item_id]['item_id'] = $_item_id;
                $_cart_prods[$_item_id]['item_type'] = 'P';
                $_cart_prods[$_item_id]['extra'] = serialize($_prod);
                $_cart_prods[$_item_id]['amount'] = empty($_cart_prods[$_item_id]['amount']) ? 1 : $_cart_prods[$_item_id]['amount'];
                $_cart_prods[$_item_id]['session_id'] = Tygh::$app['session']->getID();
                $ip = fn_get_ip();
                $_cart_prods[$_item_id]['ip_address'] = fn_ip_to_db($ip['host']);
                if (fn_allowed_for('ULTIMATE')) {
                    $_cart_prods[$_item_id]['company_id'] = Registry::get('runtime.company_id');
                }
                if (!empty($_cart_prods[$_item_id])) {
                    db_query('REPLACE INTO ?:user_session_products ?e', $_cart_prods[$_item_id]);
                }
            }
        }
        /**
         * Deprecated: This hook will be removed in version 5.x.x.. Use save_cart_content_post instead.
         */
        fn_set_hook('save_cart', $cart, $user_id, $type);
        /**
         * Actions after storing cart content in the customer's profile
         *
         * @param array $cart Cart contents
         * @param int $user_id User identifier
         * @param string $type Cart type
         * @param string $user_type User type
         */
        fn_set_hook('save_cart_content_post', $cart, $user_id, $type, $user_type);
    }
    return true;
}