/** * calculate shipping fee * * @param int $countries_id * @param double $total_weight */ function calculate($countries_iso_code_2, $total_weight) { global $currencies; if ($this->dsf_account_info['status'] != "1" || $total_weight <= 0) { return array(); } $total_weight = $total_weight / 1000; //soap $client = new SoapClient($this->dsf_account_info['calculate_wsdl_url'], array('encoding' => 'utf-8')); //var_dump($client); //error to link if (!$client) { return array(); } //no shippings if (count($this->dsf_shipping) <= 0) { return array(); } //var_dump($client->__getFunctions()); //$params = array("in0" => "US", "in1" => "0.9", "in2" => "A0115", "in3" => "61030"); //$calculateResults = $client->MztExpressFeeService($params); $dsf_countries_tmp = $this->dsf_countries_map[$countries_iso_code_2]; $countries_iso_code_2 = $dsf_countries_tmp['countries_iso_code_2']; //var_dump($countries_iso_code_2,$dsf_countries_tmp); if (!$countries_iso_code_2) { return array(); } if (!defined("CONFIG_4PX_SHIPPING_EXCHANGE")) { die("CONFIG_4PX_SHIPPING_EXCHANGE"); } $cny_value = $currencies->get_value("CNY"); if (!$cny_value) { $cny_value = CONFIG_4PX_SHIPPING_EXCHANGE; } //Deal with result $packetCodesArrayAll = explode(",", $this->dsf_account_info['packet_codes']); $packetCodesArray = ""; $notPacketCodesArray = ""; $returnData = array(); foreach ($this->dsf_shipping as $shipping_info) { if (in_array($shipping_info['dsf_shipping_code'], $packetCodesArrayAll)) { $packetCodesArray[] = $shipping_info['dsf_shipping_code']; } else { $notPacketCodesArray[] = $shipping_info['dsf_shipping_code']; } } //var_dump($packetCodesArray); $packetCodes = @implode(",", $packetCodesArray); $notPacketCodes = @implode(",", $notPacketCodesArray); //var_dump($packetCodes); //get packet shipping if (strlen($packetCodes) > 3) { $params = array("in0" => $countries_iso_code_2, "in1" => $total_weight . "", "in2" => $packetCodes, "in3" => $this->dsf_account_info['company_id']); //var_dump($params); $calculateResult = $client->MztExpressFeeService($params); //var_dump($calculateResult->out->MztExpressFeeBean); } if (isset($calculateResult) && count($calculateResult->out->MztExpressFeeBean) > 0) { if (is_array($calculateResult->out->MztExpressFeeBean)) { foreach ($calculateResult->out->MztExpressFeeBean as $packet_shipping_info) { $shipping_displays_name = trim($this->dsf_shipping[$packet_shipping_info->pk_code]['shipping_displays_name']) ? $this->dsf_shipping[$packet_shipping_info->pk_code]['shipping_displays_name'] : $this->dsf_shipping[$packet_shipping_info->pk_code]['dsf_shipping_name']; $price_increase = $this->dsf_shipping[$packet_shipping_info->pk_code]['price_increase']; $calculate_total_price = $packet_shipping_info->total_price / $cny_value * $this->dsf_shipping[$packet_shipping_info->pk_code]['price_percentage'] / 100 + $this->getPrice($price_increase, $_SESSION['currency']); //return data $shipping_displays_note = $this->dsf_shipping[$packet_shipping_info->pk_code]['shipping_displays_note']; if (!trim($shipping_displays_note)) { $shipping_displays_note = $shipping_displays_name; } $returnData[] = array('id' => $packet_shipping_info->pk_code, 'module' => $shipping_displays_name, 'methods' => array(array('id' => $packet_shipping_info->pk_code, 'title' => $shipping_displays_note, 'cost' => $calculate_total_price))); } } else { $shipping_displays_name = trim($this->dsf_shipping[$calculateResult->out->MztExpressFeeBean->pk_code]['shipping_displays_name']) ? $this->dsf_shipping[$calculateResult->out->MztExpressFeeBean->pk_code]['shipping_displays_name'] : $this->dsf_shipping[$calculateResult->out->MztExpressFeeBean->pk_code]['dsf_shipping_name']; $price_increase = $this->dsf_shipping[$calculateResult->out->MztExpressFeeBean->pk_code]['price_increase']; $calculate_total_price = $calculateResult->out->MztExpressFeeBean->total_price / $cny_value * $this->dsf_shipping[$calculateResult->out->MztExpressFeeBean->pk_code]['price_percentage'] / 100 + $this->getPrice($price_increase, $_SESSION['currency']); //return data $shipping_displays_note = $this->dsf_shipping[$calculateResult->out->MztExpressFeeBean->pk_code]['shipping_displays_note']; if (!trim($shipping_displays_note)) { $shipping_displays_note = $shipping_displays_name; } $returnData[] = array('id' => $calculateResult->out->MztExpressFeeBean->pk_code, 'module' => $shipping_displays_name, 'methods' => array(array('id' => $calculateResult->out->MztExpressFeeBean->pk_code, 'title' => $shipping_displays_note, 'cost' => $calculate_total_price))); } } //get other shipping if (strlen($notPacketCodes) > 3) { $params = array("in0" => $countries_iso_code_2, "in1" => $total_weight . "", "in2" => $notPacketCodes, "in3" => $this->dsf_account_info['company_id']); //var_dump($params); $calculateResult2 = $client->internatExpressFeeService($params); } if (isset($calculateResult2) && count($calculateResult2->out->InternatExpressFeeBean) > 0) { if (is_array($calculateResult2->out->InternatExpressFeeBean)) { foreach ($calculateResult2->out->InternatExpressFeeBean as $packet_shipping_info) { $shipping_displays_name = trim($this->dsf_shipping[$packet_shipping_info->pk_code]['shipping_displays_name']) ? $this->dsf_shipping[$packet_shipping_info->pk_code]['shipping_displays_name'] : $this->dsf_shipping[$packet_shipping_info->pk_code]['dsf_shipping_name']; $price_increase = $this->dsf_shipping[$packet_shipping_info->pk_code]['price_increase']; $calculate_total_price = $packet_shipping_info->total_price / $cny_value * $this->dsf_shipping[$packet_shipping_info->pk_code]['price_percentage'] / 100 + $this->getPrice($price_increase, $_SESSION['currency']); //return data $shipping_displays_note = $this->dsf_shipping[$packet_shipping_info->pk_code]['shipping_displays_note']; if (!trim($shipping_displays_note)) { $shipping_displays_note = $shipping_displays_name; } $returnData[] = array('id' => $packet_shipping_info->pk_code, 'module' => $shipping_displays_name, 'methods' => array(array('id' => $packet_shipping_info->pk_code, 'title' => $shipping_displays_note, 'cost' => $calculate_total_price))); } } else { $shipping_displays_name = trim($this->dsf_shipping[$calculateResult2->out->InternatExpressFeeBean->pk_code]['shipping_displays_name']) ? $this->dsf_shipping[$calculateResult2->out->InternatExpressFeeBean->pk_code]['shipping_displays_name'] : $this->dsf_shipping[$calculateResult2->out->InternatExpressFeeBean->pk_code]['dsf_shipping_name']; $price_increase = $this->dsf_shipping[$calculateResult2->out->InternatExpressFeeBean->pk_code]['price_increase']; $calculate_total_price = $calculateResult2->out->InternatExpressFeeBean->total_price / $cny_value * $this->dsf_shipping[$calculateResult2->out->InternatExpressFeeBean->pk_code]['price_percentage'] / 100 + $this->getPrice($price_increase, $_SESSION['currency']); //return data $shipping_displays_note = $this->dsf_shipping[$calculateResult2->out->InternatExpressFeeBean->pk_code]['shipping_displays_note']; if (!trim($shipping_displays_note)) { $shipping_displays_note = $shipping_displays_name; } $returnData[] = array('id' => $calculateResult2->out->InternatExpressFeeBean->pk_code, 'module' => $shipping_displays_name, 'methods' => array(array('id' => $calculateResult2->out->InternatExpressFeeBean->pk_code, 'title' => $shipping_displays_note, 'cost' => $calculate_total_price))); } } return $returnData; }