示例#1
0
文件: Sdek.php 项目: askzap/ask-zap
 /**
  * Prepare request information
  *
  * @return array Prepared data
  */
 public function getRequestData()
 {
     static $request_data = NULL;
     $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'];
     $ruble = Registry::get('currencies.RUB');
     if ($origination['country'] != 'RU') {
         $this->_internalError(__('shippings.sdek.country_error'));
     }
     if (empty($ruble) || $ruble['is_primary'] == 'N') {
         $this->_internalError(__('shippings.sdek.activation_error'));
     }
     $this->city_id = $_code = RusSdek::cityId($location);
     $_code_sender = $shipping_settings['from_city_id'];
     $url = 'http://api.edostavka.ru/calculator/calculate_price_by_json.php';
     isset($this->version) ? $post['version'] = $this->version : '';
     if (!empty($shipping_settings['dateexecute'])) {
         $timestamp = TIME + $shipping_settings['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_settings['authlogin'];
         $post['secure'] = !empty($shipping_settings['authpassword']) ? md5($post['dateExecute'] . "&" . $shipping_settings['authpassword']) : '';
     }
     $post['senderCityId'] = (int) $_code_sender;
     $post['receiverCityId'] = (int) $_code;
     $post['tariffId'] = $shipping_settings['tariffid'];
     $weight = round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
     $length = !empty($shipping_settings['length']) ? $shipping_settings['length'] : 20;
     $width = !empty($shipping_settings['width']) ? $shipping_settings['width'] : 20;
     $height = !empty($shipping_settings['height']) ? $shipping_settings['height'] : 20;
     $goods = array();
     if (!empty($this->_shipping_info['package_info']['packages'])) {
         $packages = $this->_shipping_info['package_info']['packages'];
         $packages_count = count($packages);
         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']);
                 $weight = round($weight_ar['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
                 $goods[$id]['weight'] = $weight;
                 $goods[$id]['length'] = $package_length;
                 $goods[$id]['width'] = $package_width;
                 $goods[$id]['height'] = $package_height;
             }
         } else {
             $goods['weight'] = $weight;
             $goods['length'] = $length;
             $goods['width'] = $width;
             $goods['height'] = $height;
             $goods = array($goods);
         }
     } else {
         $weight = round($weight_data['plain'] * Registry::get('settings.General.weight_symbol_grams') / 1000, 3);
         $goods['weight'] = $weight;
         $goods['length'] = $length;
         $goods['width'] = $width;
         $goods['height'] = $height;
         $goods = array($goods);
     }
     $post['goods'] = $goods;
     $request_data = array('method' => 'post', 'url' => $url, 'data' => json_encode($post));
     return $request_data;
 }
示例#2
0
            }
        }
        $join = db_quote("LEFT JOIN ?:rus_cities_sdek as c ON c.city_id = d.city_id");
        $condition = db_quote(" AND c.status = ?s", 'A');
        if (!empty($params['check_country']) && $params['check_country'] != 'undefined') {
            $condition .= db_quote(" AND c.country_code = ?s", $params['check_country']);
            if (!empty($params['check_state']) && $params['check_state'] != 'undefined') {
                $condition .= db_quote(" AND c.state_code = ?s", $params['check_state']);
            }
        }
        $cities = db_get_array("SELECT d.city, c.city_code FROM ?:rus_city_sdek_descriptions as d ?p WHERE city LIKE ?l AND lang_code = ?s  ?p  LIMIT ?i", $join, $search, 'ru', $condition, 10);
        if (!empty($cities)) {
            foreach ($cities as $city) {
                $select[] = array('code' => $city['city_code'], 'value' => $city['city'], 'label' => $city['city']);
            }
        }
        Registry::get('ajax')->assign('autocomplete', $select);
        exit;
    }
} elseif ($mode == 'sdek_get_city_data') {
    $params = $_REQUEST;
    if (defined('AJAX_REQUEST')) {
        $location['country'] = 'RU';
        $location['city'] = $params['var_city'];
        $data = RusSdek::cityId($location);
        $city_data = array('from_city_id' => $data);
        Tygh::$app['view']->assign('sdek_new_city_data', $city_data);
        Tygh::$app['view']->display('addons/rus_sdek/views/shippings/components/services/sdek.tpl');
        exit;
    }
}