Exemplo n.º 1
0
            if ($weight > $z['max_weight']) {
                $weight_up = $weight - $z['max_weight'];
                $coef = (int) ($weight_up / $z['next_weight']);
                if ($weight_up % $z['next_weight'] > 0) {
                    $coef++;
                }
                $result = $result + $coef * $z['cost_weight'];
            }
            if ($weight > $z['next_weight_margin']) {
                $result = $result * $z['margin'];
            }
            $result = $result + $total * $z['tax'];
        } else {
            $result = $z['parcel_cost'];
            if ($weight > $z['parcel_max_weight']) {
                $weight_up = $weight - $z['parcel_max_weight'];
                $coef = (int) ($weight_up / $z['parcel_next_weight']);
                if ($weight_up % $z['parcel_next_weight'] > 0) {
                    $coef++;
                }
                $result = $result + $coef * $z['parcel_next_weight_cost'];
            }
            $result = $result + $total * $z['parcel_tax'];
        }
        $res = array('Prepaid' => $result + 30, 'Collect' => (int) ($result + 30 + 0.05 * $result + 0.2 * $total), 'Price' => $result, 'test' => $this->test($index, $weight, $total));
        return $res;
    }
}
$post = new RussianPost();
$price = $post->getPrice(367000, 700, 1500);
print_r($price);
Exemplo n.º 2
0
 function quote($method = '')
 {
     global $order, $shipping_weight, $shipping_num_boxes, $currencies, $currency;
     include __DIR__ . '/RussianPost.class.php';
     $RussianPost = new RussianPost();
     $postcode_check_query = tep_db_query("select count(*) as total from " . TABLE_CITIES . " where city_id = '" . tep_db_input($order->delivery['postcode']) . "'");
     $postcode_check = tep_db_fetch_array($postcode_check_query);
     $shipping_cost = 0;
     $default_shipping_cost = str_replace(',', '.', MODULE_SHIPPING_ZIPZONESNAL_COST);
     $additional_shipping_cost = str_replace(',', '.', MODULE_SHIPPING_ZIPZONESNAL_ADDITIONAL_COST);
     if ($shipping_weight == 0) {
         $this->quotes['error'] = MODULE_SHIPPING_ZIPZONESNAL_UNDEFINED_RATE;
     } elseif (empty($order->delivery['postcode']) || $postcode_check['total'] < 1) {
         $this->quotes['error'] = MODULE_SHIPPING_ZIPZONESNAL_NO_ZIPCODE_FOUND;
     } else {
         list($s, $m) = explode(' ', microtime());
         /*$link = 'http://www.russianpost.ru/autotarif/Autotarif.aspx?countryCode=643&typePost=1' . ($shipping_weight>2 ? '&viewPost=36&viewPostName=%D0%A6%D0%B5%D0%BD%D0%BD%D0%B0%D1%8F%20%D0%BF%D0%BE%D1%81%D1%8B%D0%BB%D0%BA%D0%B0' : '&viewPost=26&viewPostName=%D0%A6%D0%B5%D0%BD%D0%BD%D0%B0%D1%8F%20%D0%B1%D0%B0%D0%BD%D0%B4%D0%B5%D1%80%D0%BE%D0%BB%D1%8C') . '&countryCodeName=%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D0%B9%D1%81%D0%BA%D0%B0%D1%8F%20%D0%A4%D0%B5%D0%B4%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D1%8F&typePostName=%D0%9D%D0%90%D0%97%D0%95%D0%9C%D0%9D.&weight=' . ($shipping_weight*1000) . '&value1=' . round($order->info['subtotal']) . '&postOfficeId=' . $order->delivery['postcode'];
         		//echo $link;
         		$page_content = file_get_contents($link);
         		$page_content = '';
         		if ($fp = @fopen($link, 'r')) {
         		  stream_set_timeout($fp, 3);
         		  while (!feof($fp)) {
         			$page_content .= fgets($fp, 1024);
         		  }
         		  fclose($fp);
         		}*/
         $PostPrice = $RussianPost->getPrice($order->delivery['postcode'], $shipping_weight * 1000, round($order->info['subtotal']));
         if ($PostPrice != 0) {
             $shipping_cost = $PostPrice;
             //['Price'];
             $shipping_method = sprintf(MODULE_SHIPPING_ZIPZONESNAL_TEXT_WEIGHT, $shipping_weight);
         } elseif ($default_shipping_cost > 0) {
             $shipping_cost = $default_shipping_cost * $shipping_weight;
             $shipping_cost += $additional_shipping_cost;
             $shipping_method = sprintf(MODULE_SHIPPING_ZIPZONESNAL_TEXT_WEIGHT, $shipping_weight);
         } else {
             $this->quotes['error'] = MODULE_SHIPPING_ZIPZONESNAL_NO_ZIPCODE_FOUND;
         }
         if ($shipping_method == '') {
             $this->quotes['error'] = MODULE_SHIPPING_ZIPZONESNAL_UNDEFINED_RATE;
             //		  $shipping_method = MODULE_SHIPPING_ZIPZONESNAL_UNDEFINED_RATE;
         } else {
             if (MODULE_SHIPPING_ZIPZONESNAL_MAX_SUM > 0) {
                 if (MODULE_SHIPPING_ZIPZONESNAL_MAX_SUM == '1') {
                     $this->quotes['error'] = MODULE_SHIPPING_ZIPZONESNAL_DISABLED;
                 } else {
                     if ($order->info['subtotal'] / $currencies->currencies[$currency]['value'] > MODULE_SHIPPING_ZIPZONESNAL_MAX_SUM) {
                         $this->quotes['error'] = sprintf(MODULE_SHIPPING_ZIPZONESNAL_MAX_SUM_ERROR, $currencies->format(MODULE_SHIPPING_ZIPZONESNAL_MAX_SUM / $currencies->currencies[$currency]['value']));
                     }
                 }
             }
             if ($shipping_cost > 0) {
                 if (tep_not_null(MODULE_SHIPPING_ZIPZONESNAL_ADD)) {
                     if (substr(MODULE_SHIPPING_ZIPZONESNAL_ADD, -1) == '%') {
                         $add = substr(MODULE_SHIPPING_ZIPZONESNAL_ADD, 0, -1);
                         if ($add > 0) {
                             $shipping_cost += $shipping_cost * $add / 100;
                         }
                     } else {
                         $shipping_cost += MODULE_SHIPPING_ZIPZONESNAL_ADD;
                     }
                 }
                 if (tep_not_null(MODULE_SHIPPING_ZIPZONESNAL_ADD_1)) {
                     if (substr(MODULE_SHIPPING_ZIPZONESNAL_ADD_1, -1) == '%') {
                         $add = substr(MODULE_SHIPPING_ZIPZONESNAL_ADD_1, 0, -1);
                         if ($add > 0) {
                             $shipping_cost += $order->info['subtotal'] * $add / 100;
                         }
                     } else {
                         $shipping_cost += MODULE_SHIPPING_ZIPZONESNAL_ADD_1;
                     }
                 }
             }
             $shipping_cost = str_replace(',', '.', round($shipping_cost));
         }
     }
     $this->quotes['id'] = $this->code;
     $this->quotes['module'] = MODULE_SHIPPING_ZIPZONESNAL_TEXT_TITLE;
     $this->quotes['methods'] = array(array('id' => $this->code, 'title' => $shipping_method, 'cost' => $shipping_cost));
     $start = $m + $s;
     list($s, $m) = explode(' ', microtime());
     //echo Round(($m + $s)-$start, 5).", ";
     return $this->quotes;
 }
Exemplo n.º 3
0
 function quote($method = '')
 {
     global $order, $shipping_weight, $currencies, $currency;
     include __DIR__ . '/RussianPost.class.php';
     $RussianPost = new RussianPost();
     $postcode_check_query = tep_db_query("select count(*) as total from " . TABLE_CITIES . " where city_id = '" . tep_db_input($order->delivery['postcode']) . "'");
     $postcode_check = tep_db_fetch_array($postcode_check_query);
     $shipping_1 = 0;
     $shipping_2 = 0;
     $default_shipping_cost = str_replace(',', '.', MODULE_SHIPPING_ZIPZONES_COST);
     $additional_shipping_cost = str_replace(',', '.', MODULE_SHIPPING_ZIPZONES_ADDITIONAL_COST);
     $shipping_weight = 0;
     $total_weight = 0;
     $common_qty = 0;
     $periodicals_qty = 0;
     $periodicals_array = array();
     $total_sum = 0;
     if (is_object($order)) {
         reset($order->products);
         while (list(, $order_product) = each($order->products)) {
             if ($order_product['periodicity'] > 0) {
                 $periodicals_qty += $order_product['qty'];
                 $periodicals_weights[] = $order_product['weight'];
                 if (!in_array($order_product['id'], array_keys($periodicals_array))) {
                     $periodicals_array[$order_product['id']] = array('weight' => $order_product['weight'], 'price' => round($order_product['final_price'], $currencies->get_decimal_places($currency)), 'qty' => $order_product['qty']);
                 } else {
                     $periodicals_array[$order_product['id']]['qty'] += $order_product['qty'];
                 }
             } else {
                 $common_qty += $order_product['qty'];
                 $total_weight += $order_product['weight'] * $order_product['qty'];
                 $total_sum += $order_product['final_price'] * $order_product['qty'];
             }
             $shipping_weight += $order_product['weight'] * $order_product['qty'];
         }
     }
     $total_sum = round($total_sum, $currencies->get_decimal_places($currency));
     if ($shipping_weight == 0) {
         $this->quotes['error'] = MODULE_SHIPPING_ZIPZONES_UNDEFINED_RATE;
     } elseif (empty($order->delivery['postcode']) || $postcode_check['total'] < 1) {
         $this->quotes['error'] = MODULE_SHIPPING_ZIPZONES_NO_ZIPCODE_FOUND;
     } else {
         if ($common_qty > 0) {
             /*$link = 'http://www.russianpost.ru/autotarif/Autotarif.aspx?countryCode=643&typePost=1' . 
             	  ($total_weight>2 ? '
             	  &viewPost=36
             	  &viewPostName=%D0%A6%D0%B5%D0%BD%D0%BD%D0%B0%D1%8F%20%D0%BF%D0%BE%D1%81%D1%8B%D0%BB%D0%BA%D0%B0' : '
             	  &viewPost=26
             	  &viewPostName=%D0%A6%D0%B5%D0%BD%D0%BD%D0%B0%D1%8F%20%D0%B1%D0%B0%D0%BD%D0%B4%D0%B5%D1%80%D0%BE%D0%BB%D1%8C') . '
             	  &countryCodeName=%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D0%B9%D1%81%D0%BA%D0%B0%D1%8F%20%D0%A4%D0%B5%D0%B4%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D1%8F
             	  &typePostName=%D0%9D%D0%90%D0%97%D0%95%D0%9C%D0%9D.
             	  &weight=' . ($total_weight*1000) . '
             	  &value1=' . $total_sum . '
             	  &postOfficeId=' . $order->delivery['postcode'];
             	  $page_content = '';
             	  if ($fp = @fopen($link, 'r')) {
             		stream_set_timeout($fp, 3);
             		while (!feof($fp)) {
             		  $page_content .= fgets($fp, 1024);
             		}
             		fclose($fp);
             	  }*/
             $PostPrice = $RussianPost->getPrice($order->delivery['postcode'], $total_weight * 1000, $total_sum);
             //print_r('$PostPrice = '.$PostPrice);
             if ($PostPrice != 0) {
                 $shipping_1 = $PostPrice;
                 //$PostPrice['Price'];
                 $shipping_method = sprintf(MODULE_SHIPPING_ZIPZONES_TEXT_WEIGHT, $total_weight);
             } elseif ($default_shipping_cost > 0) {
                 $shipping_1 = $default_shipping_cost * $total_weight;
                 if ($shipping_1 > 0) {
                     $shipping_1 += $additional_shipping_cost;
                 }
                 $shipping_method = sprintf(MODULE_SHIPPING_ZIPZONES_TEXT_WEIGHT, $total_weight);
             } else {
                 $this->quotes['error'] = MODULE_SHIPPING_ZIPZONES_NO_ZIPCODE_FOUND;
             }
             if (MODULE_SHIPPING_ZIPZONES_FREE > 0 && $this->is_avia == false && $shipping_1 <= 250) {
                 $this->icon = ' (<span class="errorText">' . sprintf(MODULE_SHIPPING_ZIPZONES_TEXT_FREE_SHIPPING, $currencies->format(MODULE_SHIPPING_ZIPZONES_FREE)) . '</span>)';
                 if ($total_sum > MODULE_SHIPPING_ZIPZONES_FREE) {
                     $shipping_1 = 0;
                 }
             }
         }
         if ($periodicals_qty > 0) {
             reset($periodicals_array);
             while (list(, $periodicals_row) = each($periodicals_array)) {
                 $shipping_2_temp = 0;
                 if ($periodicals_row['weight'] > 0) {
                     /*$link = 'http://www.russianpost.ru/autotarif/Autotarif.aspx?countryCode=643&typePost=1' 
                     	  . ($periodicals_row['weight']>2 ? 
                     	  '&viewPost=36
                     	  &viewPostName=%D0%A6%D0%B5%D0%BD%D0%BD%D0%B0%D1%8F%20%D0%BF%D0%BE%D1%81%D1%8B%D0%BB%D0%BA%D0%B0' : '
                     	  &viewPost=26
                     	  &viewPostName=%D0%A6%D0%B5%D0%BD%D0%BD%D0%B0%D1%8F%20%D0%B1%D0%B0%D0%BD%D0%B4%D0%B5%D1%80%D0%BE%D0%BB%D1%8C') . '
                     	  &countryCodeName=%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D0%B9%D1%81%D0%BA%D0%B0%D1%8F%20%D0%A4%D0%B5%D0%B4%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D1%8F
                     	  &typePostName=%D0%9D%D0%90%D0%97%D0%95%D0%9C%D0%9D.
                     	  &weight=' . ($periodicals_row['weight']*1000) . '
                     	  &value1=' . $periodicals_row['price'] . '
                     	  &postOfficeId=' . $order->delivery['postcode'];
                     	  $page_content = '';
                     	  if ($fp = @fopen($link, 'r')) {
                     		stream_set_timeout($fp, 3);
                     		while (!feof($fp)) {
                     		  $page_content .= fgets($fp, 1024);
                     		}
                     		fclose($fp);
                     	  }*/
                     $PostPrice = $RussianPost->getPrice($order->delivery['postcode'], $periodicals_row['weight'] * 1000, $periodicals_row['price']);
                     if ($PostPrice != 0) {
                         $shipping_2_temp += round($PostPrice, $currencies->get_decimal_places($currency)) + $additional_shipping_cost;
                         if (empty($shipping_method)) {
                             $shipping_method = sprintf(MODULE_SHIPPING_ZIPZONES_TEXT_WEIGHT_1, $periodicals_qty);
                         }
                     } elseif ($default_shipping_cost > 0) {
                         $shipping_2_temp += $default_shipping_cost * $periodicals_row['weight'] + $additional_shipping_cost;
                     } else {
                         $this->quotes['error'] = MODULE_SHIPPING_ZIPZONES_NO_ZIPCODE_FOUND;
                         break;
                     }
                 }
                 $shipping_2 += $shipping_2_temp * $periodicals_row['qty'];
             }
         }
     }
     $shipping_cost = str_replace(',', '.', round($shipping_1 + $shipping_2));
     if ($shipping_method == '') {
         $this->quotes['error'] = MODULE_SHIPPING_ZIPZONES_UNDEFINED_RATE;
         //		$shipping_method = MODULE_SHIPPING_ZIPZONES_UNDEFINED_RATE;
     }
     $this->quotes['id'] = $this->code;
     $this->quotes['module'] = MODULE_SHIPPING_ZIPZONES_TEXT_TITLE;
     $this->quotes['methods'] = array(array('id' => $this->code, 'title' => $shipping_method, 'cost' => $shipping_cost));
     if (tep_not_null($this->icon)) {
         $this->quotes['icon'] = $this->icon;
     }
     return $this->quotes;
 }