Esempio n. 1
0
function fn_qwintry_create_shipment($order_info, $qwintry_data = array())
{
    $shipping = fn_qwintry_find_qwintry_shipping($order_info);
    if (empty($shipping)) {
        return false;
    }
    $shipping_settings = fn_get_shipping_params($shipping['shipping_id']);
    $package_info = fn_qwintry_get_package_from_order_info($order_info);
    $dimensions = fn_qwintry_get_biggest_package($package_info);
    $invoice = fn_qwintry_save_order_invoice($order_info['order_id']);
    if (!$dimensions) {
        $dimensions = $shipping_settings['dimensions'];
    }
    $weight_data = fn_expand_weight($package_info['W']);
    $pounds = $weight_data['pounds'];
    if (!empty($qwintry_data['box_length']) && !empty($qwintry_data['box_width']) && !empty($qwintry_data['box_height'])) {
        $dimensions = $qwintry_data;
    }
    if (!empty($qwintry_data['box_weight'])) {
        $pounds = $qwintry_data['box_weight'];
    }
    $data = array('Shipment' => array('first_name' => $order_info['s_firstname'], 'last_name' => $order_info['s_lastname'], 'phone' => empty($order_info['s_phone']) ? $order_info['phone'] : $order_info['s_phone'], 'email' => $order_info['email'], 'customer_notes' => $order_info['notes'], 'weight' => $pounds > 0.1 ? $pounds : (empty($shipping_settings['default_weight']) ? 4 : $shipping_settings['default_weight']), 'dimensions' => $dimensions['box_length'] . 'x' . $dimensions['box_width'] . 'x' . $dimensions['box_height'], 'insurance' => false, 'external_id' => $order_info['order_id'], 'hub_code' => empty($shipping_settings['hub']) ? 'DE1' : $shipping_settings['hub']), 'invoices' => array(0 => array('base64_data' => base64_encode(file_get_contents($invoice)), 'base64_extension' => 'pdf')));
    $data['Shipment']['addr_line1'] = $order_info['s_address'];
    $data['Shipment']['addr_line2'] = $order_info['s_address_2'];
    $data['Shipment']['addr_zip'] = $order_info['s_zipcode'];
    $data['Shipment']['addr_state'] = fn_get_state_name($order_info['s_state'], $order_info['s_country']);
    $data['Shipment']['addr_city'] = $order_info['s_city'];
    $data['Shipment']['addr_country'] = $order_info['s_country'];
    if (empty($shipping['extra']['type']) || $shipping['extra']['type'] == 'courier') {
        $data['Shipment']['delivery_type'] = 'courier';
    } elseif ($shipping['extra']['type'] == 'pickup' && !empty($shipping['extra']['point'])) {
        $data['Shipment']['delivery_type'] = 'pickup';
        $data['Shipment']['delivery_pickup'] = $shipping['extra']['point'];
    }
    if ($shipping_settings['mode'] == 'test') {
        $data['Shipment']['test'] = true;
    }
    $cart = fn_qwintry_fn_form_cart($order_info);
    foreach ($cart['products'] as $product) {
        $rus_name = fn_get_product_name($product['product_id'], 'RU');
        $data['items'][] = array('descr' => $product['product'], 'descr_ru' => empty($rus_name) ? $product['product'] : $rus_name, 'count' => $product['amount'], 'line_value' => fn_qwintry_get_price($product['price']), 'line_weight' => empty($product['weight']) ? 0.1 : $product['weight'], 'link' => fn_url('products.view&product_id=' . $product['product_id'], 'C'));
    }
    $result = fn_qwintry_send_api_request('package-create', $data, $shipping_settings);
    if (!$result || empty($result->success) || !$result->success || empty($result->result->tracking)) {
        if (empty($result->errorMessage)) {
            return false;
        }
        return array('[error]' => (string) $result->errorMessage);
    }
    $shipment_data = array('order_id' => $order_info['order_id'], 'shipping_id' => $shipping['shipping_id'], 'tracking_number' => $result->result->tracking);
    fn_qwintry_update_shipment($shipment_data, 0, 0, true);
    if (fn_qwintry_save_label($order_info['order_id'] . '.pdf', $result->result->tracking, $shipping_settings) !== false) {
        return true;
    }
    return false;
}
/**
 * Function returns address of company and emails of company' departments.
 *
 * @param integer $company_id ID of company
 * @param string $lang_code Language of retrieving data. If null, lang_code of company will be used.
 * @return array Company address, emails and lang_code.
 */
function fn_get_company_placement_info($company_id, $lang_code = null)
{
    $default_company_placement_info = Registry::get('settings.Company');
    if (empty($company_id)) {
        $company_placement_info = $default_company_placement_info;
        $company_placement_info['lang_code'] = !empty($lang_code) ? $lang_code : CART_LANGUAGE;
    } else {
        $company = fn_get_company_data($company_id, !empty($lang_code) ? $lang_code : CART_LANGUAGE);
        if (fn_allowed_for('ULTIMATE')) {
            $company_placement_info = Settings::instance()->getValues('Company', Settings::CORE_SECTION, true, $company_id);
            $default_company_placement_info = $company_placement_info;
            $company_placement_info['lang_code'] = $company['lang_code'];
        } else {
            $company_placement_info = array('company_name' => $company['company'], 'company_address' => $company['address'], 'company_city' => $company['city'], 'company_country' => $company['country'], 'company_state' => $company['state'], 'company_zipcode' => $company['zipcode'], 'company_phone' => $company['phone'], 'company_phone_2' => '', 'company_fax' => $company['fax'], 'company_website' => $company['url'], 'company_users_department' => $company['email'], 'company_site_administrator' => $company['email'], 'company_orders_department' => $company['email'], 'company_support_department' => $company['email'], 'company_newsletter_email' => $company['email'], 'lang_code' => $company['lang_code']);
        }
    }
    foreach ($default_company_placement_info as $k => $v) {
        $company_placement_info['default_' . $k] = $v;
    }
    $lang_code = !empty($lang_code) ? $lang_code : $company_placement_info['lang_code'];
    $company_placement_info['company_country_descr'] = fn_get_country_name($company_placement_info['company_country'], $lang_code);
    $company_placement_info['company_state_descr'] = fn_get_state_name($company_placement_info['company_state'], $company_placement_info['company_country'], $lang_code);
    return $company_placement_info;
}
Esempio n. 3
0
         $_ph_a = '61';
         $_ph_b = substr($_phone, 2);
     } else {
         $_ph_a = '61';
         $_ph_b = $_phone;
     }
 } else {
     $_ph_a = substr($_phone, 0, 3);
     $_ph_b = substr($_phone, 3);
 }
 // US states
 if ($order_info['b_country'] == 'US') {
     $_b_state = $order_info['b_state'];
     // all other states
 } else {
     $_b_state = fn_get_state_name($order_info['b_state'], $order_info['b_country']);
 }
 $return_url = fn_url("payment_notification.return?payment=paypal&order_id={$order_id}", AREA, 'current');
 $cancel_url = fn_url("payment_notification.cancel?payment=paypal&order_id={$order_id}", AREA, 'current');
 $notify_url = fn_url("payment_notification.notify?payment=paypal&order_id={$order_id}", AREA, 'current');
 $post_data = array('charset' => 'utf-8', 'cmd' => '_cart', 'custom' => $order_id, 'invoice' => $paypal_order_id, 'redirect_cmd' => '_xclick', 'rm' => 2, 'email' => $order_info['email'], 'first_name' => $order_info['b_firstname'], 'last_name' => $order_info['b_lastname'], 'address1' => $order_info['b_address'], 'address2' => $order_info['b_address_2'], 'country' => $order_info['b_country'], 'city' => $order_info['b_city'], 'state' => $_b_state, 'zip' => $order_info['b_zipcode'], 'day_phone_a' => $_ph_a, 'day_phone_b' => $_ph_b, 'day_phone_c' => $_ph_c, 'night_phone_a' => $_ph_a, 'night_phone_b' => $_ph_b, 'night_phone_c' => $_ph_c, 'business' => $paypal_account, 'item_name' => $paypal_item_name, 'amount' => $paypal_total, 'upload' => '1', 'handling_cart' => $paypal_shipping, 'currency_code' => $paypal_currency, 'return' => $return_url, 'cancel_return' => $cancel_url, 'notify_url' => $notify_url, 'bn' => 'ST_ShoppingCart_Upload_US');
 $i = 1;
 // Products
 if (empty($order_info['use_gift_certificates']) && !floatval($order_info['subtotal_discount']) && empty($order_info['points_info']['in_use']) && count($order_info['products']) < MAX_PAYPAL_PRODUCTS) {
     if (!empty($order_info['products'])) {
         foreach ($order_info['products'] as $k => $v) {
             $suffix = '_' . $i++;
             $v['product'] = htmlspecialchars(strip_tags($v['product']));
             $v['price'] = fn_format_price(($v['subtotal'] - fn_external_discounts($v)) / $v['amount'], $paypal_currency);
             $post_data["item_name{$suffix}"] = $v['product'];
             $post_data["amount{$suffix}"] = $v['price'];
Esempio n. 4
0
 /**
  * Gets numeric representation of Country/Region/City
  *
  * @param  array $destination Country, Region, City of geographic place
  * @return int   Numeric representation
  */
 private function _getDestinationCode($destination)
 {
     $cities = fn_get_schema('edost', 'cities');
     $regions = fn_get_schema('edost', 'regions');
     $countries = fn_get_schema('edost', 'countries');
     $origination = $this->_shipping_info['package_info']['origination']['country'];
     $result = '';
     if ($destination['country'] != 'RU' || $origination != 'RU') {
         $result = !empty($countries[$destination['country']]) ? $countries[$destination['country']] : '';
     } else {
         if (Registry::get('addons.rus_cities.status') == 'A') {
             if (preg_match('/^[a-zA-Z]+$/', $destination['city'])) {
                 $lang_code = 'en';
             } else {
                 $lang_code = 'ru';
             }
             $condition = db_quote(" d.lang_code = ?s AND d.city = ?s AND c.status = ?s", $lang_code, $destination['city'], 'A');
             if (!empty($destination['state'])) {
                 $condition .= db_quote(" AND c.state_code = ?s", $destination['state']);
             }
             if (!empty($destination['country'])) {
                 $condition .= db_quote(" AND c.country_code = ?s", $destination['country']);
             }
             $result = db_get_field("SELECT c.city_code FROM ?:rus_city_descriptions as d LEFT JOIN ?:rus_cities as c ON c.city_id = d.city_id WHERE ?p", $condition);
         }
         if (empty($result)) {
             $result = !empty($cities[$destination['city']]) ? $cities[$destination['city']] : '';
             if ($result == '') {
                 $alt_city = $destination['city'] . ' (' . fn_get_state_name($destination['state'], $destination['country'], 'RU') . ')';
                 if (!empty($cities[$alt_city])) {
                     $result = $cities[$alt_city];
                 }
             }
             if ($result == '') {
                 $result = !empty($regions[$destination['state']]) ? $regions[$destination['state']] : '';
             }
         }
     }
     return $result;
 }
Esempio n. 5
0
function fn_pickpoint_cost_by_shipment(&$cart, $shipping_info, $service_data, $city)
{
    if (!empty($service_data['module']) && $service_data['module'] == 'pickpoint') {
        $data = array();
        $pickpoint_info = Registry::get('addons.rus_pickpoint');
        $url = RusPickpoint::Url();
        $data_url = RusPickpoint::$data_url;
        $login = RusPickpoint::Login();
        $total = $weight = 0;
        $goods = array();
        $length = $width = $height = 20;
        if ($login) {
            $shipping_settings = $service_data['service_params'];
            $weight_data = fn_expand_weight($shipping_info['package_info']['W']);
            $weight = round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
            $packages = !empty($shipping_info['package_info']['packages']) ? $shipping_info['package_info']['packages'] : array();
            $origination = !empty($shipping_info['package_info']['origination']) ? $shipping_info['package_info']['origination'] : '';
            $from_state = fn_get_state_name($origination['state'], $origination['country'], 'RU');
            $length = !empty($shipping_settings['pickpoint_length']) ? $shipping_settings['pickpoint_length'] : 10;
            $width = !empty($shipping_settings['pickpoint_width']) ? $shipping_settings['pickpoint_width'] : 10;
            $height = !empty($shipping_settings['pickpoint_height']) ? $shipping_settings['pickpoint_height'] : 10;
            if (!empty($shipping_info['package_info']['packages'])) {
                $packages = $shipping_info['package_info']['packages'];
                $packages_count = count($packages);
                $pickpoint_weight = $pickpoint_length = $pickpoint_width = $pickpoint_height = 0;
                if ($packages_count > 0) {
                    foreach ($packages as $id => $package) {
                        $package_length = empty($package['shipping_params']['box_length']) ? $length : $package['shipping_params']['box_length'];
                        $package_width = empty($package['shipping_params']['box_width']) ? $width : $package['shipping_params']['box_width'];
                        $package_height = empty($package['shipping_params']['box_height']) ? $height : $package['shipping_params']['box_height'];
                        $weight_ar = fn_expand_weight($package['weight']);
                        $package_weight = round($weight_ar['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
                        $pickpoint_weight = $pickpoint_weight + $package_weight;
                        $pickpoint_length = $pickpoint_length + $package_length;
                        $pickpoint_width = $pickpoint_width + $package_width;
                        $pickpoint_height = $pickpoint_height + $package_height;
                    }
                    $length = $pickpoint_length;
                    $width = $pickpoint_width;
                    $height = $pickpoint_height;
                    $weight = $pickpoint_weight;
                }
            } else {
                $packages_count = 1;
                $weight = round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
            }
            $sid = RusPickpoint::$sid;
            $data_zone = array('SessionId' => $sid, 'FromCity' => $origination['city']);
            $url_zone = $url . 'getzone';
            $pickpoint_id = '';
            $address_pickpoint = RusPickpoint::findPostamatPickpoint($pickpoint_id, $city);
            $data_zone['ToPT'] = $pickpoint_id;
            $pickpoint_zone = RusPickpoint::zonesPickpoint($url_zone, $data_zone, $data_url);
            if (!empty($pickpoint_zone)) {
                $pickpoint_id = !empty($pickpoint_zone['to_pt']) ? $pickpoint_zone['to_pt'] : '';
                if ($pickpoint_zone['delivery_min'] == $pickpoint_zone['delivery_max']) {
                    $date_zone = $pickpoint_zone['delivery_max'] . ' ' . __('days');
                } else {
                    $date_zone = $pickpoint_zone['delivery_min'] . '-' . $pickpoint_zone['delivery_max'] . ' ' . __('days');
                }
            }
            if (!empty($pickpoint_id) && !empty($address_pickpoint)) {
                if (!empty($shipping_info['keys']['group_key']) && !empty($shipping_info['keys']['shipping_id'])) {
                    $group_key = $shipping_info['keys']['group_key'];
                    $shipping_id = $shipping_info['keys']['shipping_id'];
                    $cart['pickpoint_office'][$group_key][$shipping_id]['pickpoint_id'] = $pickpoint_id;
                    $cart['pickpoint_office'][$group_key][$shipping_id]['address_pickpoint'] = $address_pickpoint;
                } elseif (!empty($shipping_info['shippings'])) {
                    foreach ($shipping_info['shippings'] as $shipping) {
                        if ($shipping['module'] == 'pickpoint') {
                            $group_key = $shipping['group_key'];
                            $shipping_id = $shipping['shipping_id'];
                            $cart['pickpoint_office'][$group_key][$shipping_id]['pickpoint_id'] = $pickpoint_id;
                            $cart['pickpoint_office'][$group_key][$shipping_id]['address_pickpoint'] = $address_pickpoint;
                        }
                    }
                }
            }
            $data = array('SessionId' => $sid, 'IKN' => $pickpoint_info['ikn'], 'FromCity' => $origination['city'], 'FromRegion' => $from_state, 'PTNumber' => $pickpoint_id, 'EncloseCount' => $packages_count, 'Length' => $length, 'Depth' => $height, 'Width' => $width, 'Weight' => $weight);
            $response = Http::post($url . 'calctariff', json_encode($data), $data_url);
            $result = json_decode($response);
            $data_services = json_decode(json_encode($result), true);
            $cost = 0;
            if (isset($data_services['Error']) && $data_services['Error'] == 1 && !empty($data_services['ErrorMessage'])) {
                fn_set_notification('E', __('notice'), $data_services['ErrorMessage']);
            } elseif (isset($data_services['Error']) && !empty($data_services['Error'])) {
                fn_set_notification('E', __('notice'), $data_services['Error']);
            } elseif (isset($data_services['Services'])) {
                $shipment = array_shift($data_services['Services']);
                $cost = $shipment['Tariff'] + $shipment['NDS'];
            }
            foreach ($cart['shipping'] as &$shipping) {
                if ($shipping['module'] == 'pickpoint') {
                    $shipping['rate'] = $cost;
                    $shipping['delivery_time'] = $date_zone;
                }
            }
            RusPickpoint::Logout();
        } else {
            fn_set_notification('E', __('notice'), RusPickpoint::$last_error);
        }
    }
}
Esempio n. 6
0
function fn_add_user_data_descriptions(&$user_data, $lang_code = CART_LANGUAGE)
{
    fn_fill_user_fields($user_data);
    // Replace titles ids with their descriptions
    $_titles = fn_get_static_data_section('T', false);
    $titles = array();
    foreach ($_titles as $val) {
        $titles[$val['param']] = $val;
    }
    if (!empty($user_data['title'])) {
        $user_data['title_descr'] = !empty($titles[$user_data['title']]['descr']) ? $titles[$user_data['title']]['descr'] : $user_data['title'];
    }
    if (!empty($user_data['b_title'])) {
        $user_data['b_title_descr'] = !empty($titles[$user_data['b_title']]['descr']) ? $titles[$user_data['b_title']]['descr'] : $user_data['b_title'];
    }
    if (!empty($user_data['s_title'])) {
        $user_data['s_title_descr'] = !empty($titles[$user_data['s_title']]['descr']) ? $titles[$user_data['s_title']]['descr'] : $user_data['s_title'];
    }
    // Replace country and state values with their descriptions
    if (!empty($user_data['b_country'])) {
        $user_data['b_country_descr'] = fn_get_country_name($user_data['b_country'], $lang_code);
    }
    if (!empty($user_data['s_country'])) {
        $user_data['s_country_descr'] = fn_get_country_name($user_data['s_country'], $lang_code);
    }
    if (!empty($user_data['b_state'])) {
        $user_data['b_state_descr'] = fn_get_state_name($user_data['b_state'], $user_data['b_country'], $lang_code);
        if (empty($user_data['b_state_descr'])) {
            $user_data['b_state_descr'] = $user_data['b_state'];
        }
    }
    if (!empty($user_data['s_state'])) {
        $user_data['s_state_descr'] = fn_get_state_name($user_data['s_state'], $user_data['s_country'], $lang_code);
        if (empty($user_data['s_state_descr'])) {
            $user_data['s_state_descr'] = $user_data['s_state'];
        }
    }
}
Esempio n. 7
0
function fn_add_user_data_descriptions(&$user_data, $lang_code = CART_LANGUAGE)
{
    fn_fill_user_fields($user_data);
    // Replace country and state values with their descriptions
    if (!empty($user_data['b_country'])) {
        $user_data['b_country_descr'] = fn_get_country_name($user_data['b_country'], $lang_code);
    }
    if (!empty($user_data['s_country'])) {
        $user_data['s_country_descr'] = fn_get_country_name($user_data['s_country'], $lang_code);
    }
    if (!empty($user_data['b_state'])) {
        $user_data['b_state_descr'] = fn_get_state_name($user_data['b_state'], $user_data['b_country'], $lang_code);
        if (empty($user_data['b_state_descr'])) {
            $user_data['b_state_descr'] = $user_data['b_state'];
        }
    }
    if (!empty($user_data['s_state'])) {
        $user_data['s_state_descr'] = fn_get_state_name($user_data['s_state'], $user_data['s_country'], $lang_code);
        if (empty($user_data['s_state_descr'])) {
            $user_data['s_state_descr'] = $user_data['s_state'];
        }
    }
}
Esempio n. 8
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $data_url = array('headers' => array('Content-Type: application/json'), 'timeout' => $this->_timeout);
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $shipping_settings = $this->_shipping_info['service_params'];
     $origination = $this->_shipping_info['package_info']['origination'];
     $location = $this->_shipping_info['package_info']['location'];
     $origin['country'] = fn_get_country_name($origination['country'], 'ru');
     $origin['region'] = fn_get_state_name($origination['state'], $origination['country'], 'RU');
     $origin['city'] = $origination['city'];
     $destination['country'] = fn_get_country_name($location['country'], 'ru');
     $destination['region'] = fn_get_state_name($location['state'], $location['country'], 'RU');
     $destination['city'] = $location['city'];
     $international = false;
     if ($origination['country'] != 'RU' || $location['country'] != 'RU') {
         $international = true;
     }
     $country_code = db_get_field("SELECT code_N3 FROM ?:countries WHERE code = ?s", $location['country']);
     if (empty($location['zipcode'])) {
         $this->_internalError(__('russian_post_empty_zipcode'));
         $location['zipcode'] = false;
     }
     $ruble = Registry::get('currencies.RUB');
     if (empty($ruble) || $ruble['is_primary'] == 'N') {
         $this->_internalError(__('russian_post_activation_error'));
     }
     $weight = $weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams');
     $total_cost = $this->_shipping_info['package_info']['C'];
     if (CART_PRIMARY_CURRENCY != 'RUB') {
         $total_cost = fn_rus_russianpost_format_price($total_cost, 'RUB');
     }
     $insurance = $shipping_settings['insurance'];
     $cash_sum = 0;
     if (!empty($shipping_settings['cash_on_delivery'])) {
         $cash_sum = $total_cost * $shipping_settings['cash_on_delivery'] / 100;
     }
     $insurance_sum = 0;
     if (!empty($insurance) || !empty($cash_sum)) {
         if ($total_cost > $cash_sum) {
             $insurance_sum = $total_cost;
         } else {
             $insurance_sum = $cash_sum;
         }
     }
     $is_wayforward = false;
     if ($shipping_settings['shipping_option'] != 'AVIA') {
         $is_wayforward = true;
     }
     $mailing = array('postingType' => 'VPO', 'postingCategory' => 'SIMPLE', 'weight' => $weight, 'zipCodeFrom' => $origination['zipcode'], 'zipCodeTo' => $location['zipcode'], 'postingKind' => 'POST_CARD');
     if ($international) {
         $mailing['postingType'] = 'MPO';
     }
     if ($shipping_settings['delivery_notice']) {
         $mailing['notificationOfDeliveryRpo'] = $shipping_settings['delivery_notice'];
     }
     if ($shipping_settings['inventory']) {
         $mailing['inventory'] = true;
     }
     if ($shipping_settings['careful']) {
         $mailing['careful'] = true;
     }
     $main_type = 'banderol';
     if ($shipping_settings['shipping_option'] == 'EMS') {
         $main_type = 'ems';
     } elseif ($shipping_settings['sending_type'] != 'papers' || $weight > 2000) {
         if ($weight < 10000) {
             $main_type = 'standardParcel';
         } elseif ($weight >= 10000 && $weight < 20000) {
             $main_type = 'heavyParcel';
         } elseif ($weight >= 20000) {
             $main_type = 'bigHeavyParcel';
         }
     }
     if ($main_type == 'banderol') {
         $mailing['postingKind'] = "BANDEROLE";
         $mailing['postingCategory'] = "ORDERED";
         $mailing['wayForward'] = "EARTH";
     } elseif ($main_type == 'standardParcel' || $main_type == 'heavyParcel' || $main_type == 'bigHeavyParcel') {
         $mailing['postingKind'] = "PARCEL";
         $mailing['postingCategory'] = "ORDINARY";
         $mailing['wayForward'] = "EARTH";
         if (!$is_wayforward) {
             $mailing['wayForward'] = "AVIA";
         }
         if ($main_type == 'standardParcel') {
             $mailing['parcelKind'] = "STANDARD";
         }
         if ($main_type == 'heavyParcel') {
             $mailing['parcelKind'] = "HEAVY";
         }
         if ($main_type == 'bigHeavyParcel') {
             $mailing['parcelKind'] = "HEAVY_LARGE_SIZED";
         }
     } elseif ($main_type == 'ems') {
         $mailing['postingKind'] = "EMS";
         $mailing['postingCategory'] = "ORDINARY";
     }
     $sending_type = "LETTER_PARCEL";
     if ($weight > 2000 && $shipping_settings['sending_type'] != 'papers') {
         $sending_type = "PACKAGE";
     }
     $product_state = array('fromCity' => $origin['city'], 'fromCountry' => $origin['country'], 'fromRegion' => $destination['region'], 'insuranceSum' => $insurance_sum, 'mainType' => $main_type, 'toCity' => $destination['city'], 'toCountry' => $destination['country'], 'toCountryCode' => $country_code, 'toRegion' => $destination['region'], 'weight' => $weight);
     $data_post = array('calculationEntity' => array('origin' => $origin, 'destination' => $destination, 'sendingType' => $sending_type), 'costCalculationEntity' => $mailing, 'productPageState' => $product_state);
     $url = "https://www.pochta.ru/calculator/v1/api/delivery.time.cost.get";
     //$url = "https://www.pochta.ru/portal-portlet/delegate/calculator/v1/api/delivery.time.cost.get";
     $request_data = array('method' => 'post', 'url' => $url, 'data' => json_encode($data_post), 'data_url' => $data_url);
     return $request_data;
 }
Esempio n. 9
0
    if (!empty($order_info['lastname'])) {
        $lastname = $order_info['lastname'];
    } elseif (!empty($order_info['b_lastname'])) {
        $lastname = $order_info['b_lastname'];
    } elseif (!empty($order_info['s_lastname'])) {
        $lastname = $order_info['s_lastname'];
    }
    if (!empty($order_info['firstname'])) {
        $firstname = $order_info['firstname'];
    } elseif (!empty($order_info['b_firstname'])) {
        $firstname = $order_info['b_firstname'];
    } elseif (!empty($order_info['s_firstname'])) {
        $firstname = $order_info['s_firstname'];
    }
    $order_info['fio'] = $lastname . ' ' . $firstname;
    $order_info['state_name'] = fn_get_state_name($order_info['s_state'], $order_info['s_country'], DESCR_SL);
    $order_info['country_name'] = fn_get_country_name($order_info['s_country'], DESCR_SL);
    $order_info['address_line_2'] = $order_info['country_name'] . ', ' . $order_info['state_name'] . ', ' . $order_info['s_city'];
    if (!empty($order_info['phone'])) {
        $order_info['recipient_phone'] = fn_rus_russianpost_normalize_phone($order_info['phone']);
    } elseif (!empty($order_info['b_phone'])) {
        $order_info['recipient_phone'] = fn_rus_russianpost_normalize_phone($order_info['b_phone']);
    } elseif (!empty($order_info['s_phone'])) {
        $order_info['recipient_phone'] = fn_rus_russianpost_normalize_phone($order_info['s_phone']);
    }
    Tygh::$app['view']->assign('pre_total', $total);
    Tygh::$app['view']->assign('order_info', $order_info);
    $pre_data = Registry::get('addons.rus_russianpost');
    $pre_data['company_phone'] = fn_rus_russianpost_normalize_phone($pre_data['company_phone']);
    Tygh::$app['view']->assign('pre_data', $pre_data);
}
Esempio n. 10
0
    fn_init_revisions();
}
// select the skin to display
fn_init_skin($_REQUEST);
// initialize templater
fn_init_templater();
// Second-level (b) cache: different for dispatch-language-currency
define('CACHE_LEVEL_DISPATCH', AREA . '_' . $_SERVER['REQUEST_METHOD'] . '_' . str_replace('.', '_', $_REQUEST['dispatch']) . '_' . (defined('CART_LOCALIZATION') ? CART_LOCALIZATION . '_' : '') . CART_LANGUAGE . '_' . CART_SECONDARY_CURRENCY);
Registry::register_cache('lang_cache', array('language_values'), CACHE_LEVEL_DISPATCH, true);
if (!defined('NO_SESSION')) {
    // Get descriptions for company country and state
    if (Registry::get('settings.Company.company_country')) {
        Registry::set('settings.Company.company_country_descr', fn_get_country_name(Registry::get('settings.Company.company_country')));
    }
    if (Registry::get('settings.Company.company_state')) {
        Registry::set('settings.Company.company_state_descr', fn_get_state_name(Registry::get('settings.Company.company_state'), Registry::get('settings.Company.company_country')));
    }
    // Unset notification message by its id
    if (!empty($_REQUEST['close_notification'])) {
        unset($_SESSION['notifications'][$_REQUEST['close_notification']]);
        exit;
    }
}
// Include user information
fn_init_user();
// Third-level (a) cache: different for dispatch-user-language-currency
define('CACHE_LEVEL_USER', AREA . '_' . $_SERVER['REQUEST_METHOD'] . '_' . str_replace('.', '_', $_REQUEST['dispatch']) . '.' . (!empty($_SESSION['auth']['usergroup_ids']) ? implode('_', $_SESSION['auth']['usergroup_ids']) : '') . '.' . (defined('CART_LOCALIZATION') ? CART_LOCALIZATION . '_' : '') . CART_LANGUAGE . '.' . CART_SECONDARY_CURRENCY);
// Third-level (b) cache: different for user(logged in/not)-usergroup-language-currency
define('CACHE_LEVEL_LOCALE_AUTH', AREA . '_' . $_SERVER['REQUEST_METHOD'] . '_' . (!empty($_SESSION['auth']['user_id']) ? 1 : 0) . '.' . (!empty($_SESSION['auth']['usergroup_ids']) ? implode('_', $_SESSION['auth']['usergroup_ids']) : '') . (defined('CART_LOCALIZATION') ? CART_LOCALIZATION . '_' : '') . CART_LANGUAGE . '.' . CART_SECONDARY_CURRENCY);
// Set timezone
date_default_timezone_set(Registry::get('settings.Appearance.timezone'));
Esempio n. 11
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
     $package_cost = $this->_shipping_info['package_info']['C'];
     $shipping_settings = $this->_shipping_info['service_params'];
     $pounds = $weight_data['pounds'];
     $location = $this->_shipping_info['package_info']['location'];
     $type = $this->_get_type();
     $currencies = array_keys(fn_get_currencies());
     if (in_array('USD', $currencies)) {
         $package_cost = fn_format_price_by_currency($package_cost, CART_PRIMARY_CURRENCY, 'USD');
     } elseif (CART_PRIMARY_CURRENCY == 'EUR') {
         $package_cost = $package_cost * 1.097;
     } elseif (CART_PRIMARY_CURRENCY == 'RMB') {
         $package_cost = $package_cost * 1.157;
     }
     if ($type == 'courier') {
         $data = array('params' => array('method' => 'qwair', 'hub_code' => empty($shipping_settings['hub']) ? 'DE1' : $shipping_settings['hub'], 'insurance' => false, 'retail_pricing' => false, 'weight' => $pounds > 0.1 ? $pounds : (empty($shipping_settings['default_weight']) ? 4 : $shipping_settings['default_weight']), 'items_value' => $package_cost, 'addr_country' => $location['country'], 'addr_zip' => $location['zipcode'], 'addr_line1' => $location['address'], 'addr_line2' => empty($location['address_2']) ? '' : $location['address_2'], 'addr_city' => $location['city'], 'addr_state' => fn_get_state_name($location['state'], $location['country'])));
     } elseif ($type == 'pickup') {
         $data = array('params' => array('insurance' => false, 'retail_pricing' => false, 'weight' => $pounds > 0.1 ? $pounds : (empty($shipping_settings['default_weight']) ? 4 : $shipping_settings['default_weight']), 'items_value' => $package_cost, 'delivery_pickup' => $this->_get_pickup_point()));
     }
     $request_data = array('method' => 'get', 'url' => 'cost', 'data' => $data);
     return $request_data;
 }
Esempio n. 12
0
    $redirect_url = "cities.manage?country_code={$params['country_code']}";
    if (!empty($params['state_code'])) {
        $redirect_url .= "&state_code={$params['state_code']}";
    }
    return array(CONTROLLER_STATUS_OK, $redirect_url);
}
if ($mode == 'manage') {
    if (empty($_REQUEST['country_code'])) {
        $params['country_code'] = Registry::get('settings.General.default_country');
    }
    list($cities, $search) = fn_get_cities($params, Registry::get('settings.Appearance.admin_elements_per_page'), DESCR_SL);
    $states = fn_get_all_states();
    $countries = fn_get_simple_countries(false, DESCR_SL);
    if (!empty($cities)) {
        foreach ($cities as $key => $city) {
            $cities[$key]['state_name'] = fn_get_state_name($city['state_code'], $city['country_code'], DESCR_SL);
            $cities[$key]['country_name'] = $countries[$city['country_code']];
        }
    }
    Tygh::$app['view']->assign('countries', $countries);
    Tygh::$app['view']->assign('states', $states);
    Tygh::$app['view']->assign('cities', $cities);
    Tygh::$app['view']->assign('search', $search);
}
function fn_update_city($city_data, $city_id = 0, $lang_code = DESCR_SL)
{
    if (empty($city_id)) {
        if (!empty($city_data['city']) && !empty($city_data['city_code'])) {
            $city_data['city_id'] = $city_id = db_query("REPLACE INTO ?:rus_cities ?e", $city_data);
            foreach (fn_get_translation_languages() as $city_data['lang_code'] => $_v) {
                db_query('REPLACE INTO ?:rus_city_descriptions ?e', $city_data);
Esempio n. 13
0
 public function _getCityID($type)
 {
     if ($type == 'from') {
         $destination = $this->_shipping_info['package_info']['origination'];
     } elseif ($type == 'to') {
         $destination = $this->_shipping_info['package_info']['location'];
     }
     $cities_simple = fn_get_schema('pecom', 'cities_simple');
     if (!empty($cities_simple[$destination['city']])) {
         $city_code = $cities_simple[$destination['city']];
     }
     if (empty($city_code)) {
         $cities_full = fn_get_schema('pecom', 'cities_full');
         $alt_city = $destination['city'] . ' (' . fn_get_state_name($destination['state'], $destination['country'], 'RU') . ')';
         if (isset($cities_full[$alt_city])) {
             $city_code = $cities_full[$alt_city];
         } elseif (isset($cities_full[$destination['city']])) {
             $city_code = $cities_full[$destination['city']];
         } else {
             $city_code = false;
             $this->_internalError(__('rus_pecom.not_city_code'));
         }
     }
     return $city_code;
 }
Esempio n. 14
0
use Tygh\Registry;
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
$cart =& $_SESSION['cart'];
$params = $_REQUEST;
if ($mode == 'update_steps' || $mode == 'shipping_estimation') {
    $city = $fromcity = '';
    $shipping_ids = !empty($params['shipping_ids']) ? $params['shipping_ids'] : array();
    $cities = fn_get_schema('pickpoint', 'cities', 'php', true);
    if (!empty($params['to_state'])) {
        $fromcity = fn_get_state_name($params['to_state'], $params['country'], 'RU');
        $pickpoint_cities = $cities[$params['to_state']];
        $city = key($pickpoint_cities);
    } elseif (!empty($params['customer_location'])) {
        $fromcity = fn_get_state_name($params['customer_location']['state'], $params['customer_location']['country'], 'RU');
        if (!empty($params['customer_location']['city'])) {
            $city = $params['customer_location']['city'];
        } else {
            $pickpoint_cities = $cities[$params['customer_location']['state']];
            $city = key($pickpoint_cities);
        }
    }
    if (!empty($params['pickpoint_office'])) {
        foreach ($params['pickpoint_office'] as $g_id => $select) {
            foreach ($select as $s_id => $o_id) {
                $cart['pickpoint_office'][$g_id][$s_id] = $o_id;
            }
        }
    } elseif (!empty($params['pickpoint_id']) && !empty($params['address_pickpoint']) && !empty($shipping_ids)) {
        foreach ($shipping_ids as $group_key => $shipping_id) {
Esempio n. 15
0
function fn_get_gift_certificate_info($certificate, $type = 'B', $stored_products = array(), $lang_code = CART_LANGUAGE)
{
    if ($type == 'B' && is_numeric($certificate)) {
        $_certificate = db_get_row("SELECT * FROM ?:gift_certificates WHERE gift_cert_id = ?i", $certificate);
    } elseif ($type == 'C' && is_numeric($certificate)) {
        $_certificate = fn_array_merge($_SESSION['cart']['gift_certificates'][$certificate], array('gift_cert_cart_id' => $certificate));
    } elseif ($type == 'P' && is_array($certificate)) {
        $_certificate = $certificate;
        if (empty($_certificate['gift_cert_code'])) {
            $_certificate['gift_cert_code'] = preg_replace('/[0-9A-Z]/', 'X', fn_generate_gift_certificate_code());
        }
    }
    fn_set_hook('get_gift_certificate_info', $_certificate, $certificate, $type);
    if (!empty($_certificate)) {
        //Prepare descriptions
        if (!empty($_certificate['state'])) {
            $_descr_state = fn_get_state_name($_certificate['state'], $_certificate['country'], $lang_code);
            $_certificate['descr_state'] = empty($_descr_state) ? $_certificate['state'] : $_descr_state;
        }
        if (!empty($_certificate['country'])) {
            $_certificate['descr_country'] = fn_get_country_name($_certificate['country'], $lang_code);
        }
        if (!empty($_certificate['products'])) {
            if ($type == 'B') {
                $_certificate['products'] = @unserialize($_certificate['products']);
            }
            fn_fill_certificate_products($_certificate['products'], $stored_products, $lang_code);
        }
        if (!empty($_certificate['debit_products'])) {
            if ($type == 'B') {
                $_certificate['debit_products'] = @unserialize($_certificate['debit_products']);
            }
            fn_fill_certificate_products($_certificate['debit_products'], $stored_products, $lang_code);
        }
    }
    return $_certificate;
}
Esempio n. 16
0
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     $data = array();
     $pickpoint_info = Registry::get('addons.rus_pickpoint');
     $login = RusPickpoint::Login();
     $url = RusPickpoint::Url();
     $data_url = RusPickpoint::$data_url;
     $group_key = isset($this->_shipping_info['keys']['group_key']) ? $this->_shipping_info['keys']['group_key'] : 0;
     $shipping_id = isset($this->_shipping_info['keys']['shipping_id']) ? $this->_shipping_info['keys']['shipping_id'] : 0;
     if ($login) {
         $pickpoint_office = !empty($_SESSION['cart']['pickpoint_office']) ? $_SESSION['cart']['pickpoint_office'] : array();
         $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']);
         $shipping_settings = $this->_shipping_info['service_params'];
         $weight = round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
         $location = !empty($this->_shipping_info['package_info']['location']) ? $this->_shipping_info['package_info']['location'] : '';
         $packages = !empty($this->_shipping_info['package_info']['packages']) ? $this->_shipping_info['package_info']['packages'] : array();
         $origination = !empty($this->_shipping_info['package_info']['origination']) ? $this->_shipping_info['package_info']['origination'] : '';
         $from_state = fn_get_state_name($origination['state'], $origination['country'], 'RU');
         $length = !empty($shipping_settings['pickpoint_length']) ? $shipping_settings['pickpoint_length'] : 10;
         $width = !empty($shipping_settings['pickpoint_width']) ? $shipping_settings['pickpoint_width'] : 10;
         $height = !empty($shipping_settings['pickpoint_height']) ? $shipping_settings['pickpoint_height'] : 10;
         if (!empty($this->_shipping_info['package_info']['packages'])) {
             $packages = $this->_shipping_info['package_info']['packages'];
             $packages_count = count($packages);
             $pickpoint_weight = $pickpoint_length = $pickpoint_width = $pickpoint_height = 0;
             if ($packages_count > 0) {
                 foreach ($packages as $id => $package) {
                     $package_length = empty($package['shipping_params']['box_length']) ? $length : $package['shipping_params']['box_length'];
                     $package_width = empty($package['shipping_params']['box_width']) ? $width : $package['shipping_params']['box_width'];
                     $package_height = empty($package['shipping_params']['box_height']) ? $height : $package['shipping_params']['box_height'];
                     $weight_ar = fn_expand_weight($package['weight']);
                     $package_weight = round($weight_ar['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
                     $pickpoint_weight = $pickpoint_weight + $package_weight;
                     $pickpoint_length = $pickpoint_length + $package_length;
                     $pickpoint_width = $pickpoint_width + $package_width;
                     $pickpoint_height = $pickpoint_height + $package_height;
                 }
                 $length = $pickpoint_length;
                 $width = $pickpoint_width;
                 $height = $pickpoint_height;
                 $weight = $pickpoint_weight;
             }
         } else {
             $packages_count = 1;
             $weight = round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
         }
         $sid = RusPickpoint::$sid;
         $data_zone = array('SessionId' => $sid, 'FromCity' => $origination['city']);
         $url_zone = $url . 'getzone';
         $pickpoint_id = '';
         if (!empty($pickpoint_office[$group_key][$shipping_id]['pickpoint_id'])) {
             $pickpoint_id = $pickpoint_office[$group_key][$shipping_id]['pickpoint_id'];
             $this->address_pickpoint = $pickpoint_office[$group_key][$shipping_id]['address_pickpoint'];
             $data_zone['ToPT'] = $pickpoint_id;
             $pickpoint_zone = RusPickpoint::zonesPickpoint($url_zone, $data_zone, $data_url);
             if (!empty($pickpoint_zone)) {
                 if ($pickpoint_zone['delivery_min'] == $pickpoint_zone['delivery_max']) {
                     $this->date_zone = $pickpoint_zone['delivery_max'] . ' ' . __('days');
                 } else {
                     $this->date_zone = $pickpoint_zone['delivery_min'] . '-' . $pickpoint_zone['delivery_max'] . ' ' . __('days');
                 }
             }
         } else {
             $city = !empty($location['city']) ? $location['city'] : '';
             $this->address_pickpoint = RusPickpoint::findPostamatPickpoint($pickpoint_id, $city);
             $data_zone['ToPT'] = $pickpoint_id;
             $pickpoint_zone = RusPickpoint::zonesPickpoint($url_zone, $data_zone, $data_url);
             if (!empty($pickpoint_zone)) {
                 $pickpoint_id = !empty($pickpoint_zone['to_pt']) ? $pickpoint_zone['to_pt'] : '';
                 if ($pickpoint_zone['delivery_min'] == $pickpoint_zone['delivery_max']) {
                     $this->date_zone = $pickpoint_zone['delivery_max'] . ' ' . __('days');
                 } else {
                     $this->date_zone = $pickpoint_zone['delivery_min'] . '-' . $pickpoint_zone['delivery_max'] . ' ' . __('days');
                 }
             }
         }
         if (!empty($pickpoint_id) && !empty($this->address_pickpoint)) {
             $_SESSION['cart']['pickpoint_office'][$group_key][$shipping_id]['pickpoint_id'] = $pickpoint_id;
             $_SESSION['cart']['pickpoint_office'][$group_key][$shipping_id]['address_pickpoint'] = $this->address_pickpoint;
         }
         $data = array('SessionId' => $sid, 'IKN' => $pickpoint_info['ikn'], 'FromCity' => $origination['city'], 'FromRegion' => $from_state, 'PTNumber' => $pickpoint_id, 'EncloseCount' => $packages_count, 'Length' => $length, 'Depth' => $height, 'Width' => $width, 'Weight' => $weight);
     } else {
         fn_set_notification('E', __('notice'), RusPickpoint::$last_error);
     }
     $request_data = array('method' => 'post', 'url' => $url . 'calctariff', 'data' => json_encode($data), 'data_url' => $data_url);
     return $request_data;
 }
Esempio n. 17
0
         fn_set_notification('E', __('error'), __('text_unsupported_currency'));
         $url = fn_url("payment_notification.unsupported_currency?payment=skrill_ewallet&order_id={$order_id}", AREA, 'current');
         fn_create_payment_form($url, array());
     }
     exit;
 }
 // gateway_fast_registration
 $post_data['firstname'] = $order_info['b_firstname'];
 $post_data['lastname'] = $order_info['b_lastname'];
 $post_data['pay_from_email'] = $order_info['email'];
 //$post_data['pay_from_email'] = rand(). "@" . rand() . ".com"; // uncomment to test hide login feature
 $post_data['address'] = $order_info['b_address'];
 $post_data['address2'] = $order_info['b_address_2'];
 $post_data['postal_code'] = $order_info['b_zipcode'];
 $post_data['city'] = $order_info['b_city'];
 $post_data['state'] = fn_get_state_name($order_info['b_state'], $order_info['b_country']);
 if (empty($post_data['state'])) {
     $post_data['state'] = $order_info['b_state'];
 }
 if (fn_strlen($post_data['state']) > 50) {
     $post_data['state'] = fn_substr($post_data['state'], 0, 47) . '...';
 }
 $post_data['country'] = db_get_field('SELECT code_A3 FROM ?:countries WHERE code=?s', $order_info['b_country']);
 $post_data['phone_number'] = $order_info['phone'];
 if ($processor_data['processor_params']['quick_checkout'] == 'Y') {
     $post_data['payment_methods'] = !empty($processor_data['processor_params']['payment_methods']) ? '' : 'ACC';
     $post_data['hide_login'] = '******';
 } else {
     $post_data['payment_methods'] = 'WLT';
     $post_data['hide_login'] = !empty($suffix) ? '1' : '0';
 }
Esempio n. 18
0
 public static function getAddressByType($profile_fields, $type, $lang_code = CART_LANGUAGE)
 {
     $prefix = self::getAddressPrefixByType($type);
     $address = array();
     foreach ($profile_fields as $k => $v) {
         if (preg_match('/^' . $prefix . '([a-z]+)$/', $k, $matches)) {
             $address[$matches[1]] = $v;
         }
     }
     if (!empty($address['country'])) {
         $address['country_description'] = fn_get_country_name($address['country'], $lang_code);
         $address['states_count'] = self::getStatesCount($address['country']);
         if (!empty($address['state'])) {
             $address['state_description'] = fn_get_state_name($address['state'], $address['country'], $lang_code);
         }
     }
     return $address;
 }