/** * 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; }
/** * Prepare request information * * @return array Prepared data */ public function getRequestData() { $weight_data = fn_expand_weight($this->_shipping_info['package_info']['W']); $origination = $this->_shipping_info['package_info']['origination']; $location = $this->_shipping_info['package_info']['location']; $cost = $this->_shipping_info['package_info']['C']; if (CART_PRIMARY_CURRENCY != 'RUB') { $cost = fn_rus_russianpost_format_price($cost, 'RUB'); } $weight_data['plain'] = $weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000; $url = 'http://russianpostcalc.ru/api_v1.php'; $request = array('apikey' => !empty($this->_shipping_info['service_params']['user_key']) ? $this->_shipping_info['service_params']['user_key'] : '', 'method' => 'calc', 'from_index' => !empty($origination['zipcode']) ? $origination['zipcode'] : '', 'to_index' => !empty($location['zipcode']) ? $location['zipcode'] : '', 'weight' => $weight_data['plain'], 'ob_cennost_rub' => $cost); $all_to_md5 = $request; $all_to_md5[] = !empty($this->_shipping_info['service_params']['user_key_password']) ? $this->_shipping_info['service_params']['user_key_password'] : ''; $request['hash'] = md5(implode("|", $all_to_md5)); $request_data = array('method' => 'post', 'url' => $url, 'data' => $request); return $request_data; }
/** * Prepare request information * * @return array Prepared data */ public function getRequestData() { $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']; $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')); } $russian_post_request_settings = array('package_type' => array('zak_band' => 23, 'zak_pis' => 13, 'cen_band' => 26, 'cen_pos' => 36, 'cen_pis' => 16, 'zak_kart' => 18, 'ob_pos' => 33), 'shipping_type' => array('ground' => 1, 'air' => 2)); $shipping_settings['shipping_type'] = !empty($shipping_settings['shipping_type']) ? $shipping_settings['shipping_type'] : 'ground'; $shipping_settings['package_type'] = !empty($shipping_settings['package_type']) ? $shipping_settings['package_type'] : 'zak_band'; if ($shipping_settings['shipping_type'] == 'air' && ($shipping_settings['package_type'] == 'cen_band' || $shipping_settings['package_type'] == 'cen_pos')) { $this->_internalError(__('service_not_available')); } $shipping_type = $russian_post_request_settings['shipping_type'][$shipping_settings['shipping_type']]; $package_type = $russian_post_request_settings['package_type'][$shipping_settings['package_type']]; $weight = (int) round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams')); // in grams $total_cost = $this->_shipping_info['package_info']['C']; if (CART_PRIMARY_CURRENCY != 'RUB') { $total_cost = fn_rus_russianpost_format_price($total_cost, 'RUB'); } $url = 'http://www.russianpost.ru/autotarif/Autotarif.aspx'; $request = array('viewPost' => $package_type, 'countryCode' => $country_code, 'typePost' => $shipping_type, 'weight' => $weight, 'value1' => ceil($total_cost), 'postOfficeId' => $location['zipcode']); $request_data = array('method' => 'get', 'url' => $url, 'data' => $request); return $request_data; }