Advertisement
SRD75

auspost.php

Oct 19th, 2012
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. <?php
  2. class ModelShippingAusPost extends Model {
  3. public function getQuote($address) {
  4. $this->load->language('shipping/auspost');
  5.  
  6. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('auspost_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
  7.  
  8. if (!$this->config->get('auspost_geo_zone_id')) {
  9. $status = true;
  10. } elseif ($query->num_rows) {
  11. $status = true;
  12. } else {
  13. $status = false;
  14. }
  15.  
  16. $error = '';
  17.  
  18. $quote_data = array();
  19.  
  20. if ($status) {
  21. $weight = $this->weight->convert($this->cart->getWeight(), $this->config->get('config_weight_class_id'), $this->config->get('auspost_weight_class_id'));
  22.  
  23. if ($this->config->get('auspost_standard') && $address['iso_code_2'] == 'AU') {
  24. $curl = curl_init();
  25.  
  26. curl_setopt($curl, CURLOPT_URL, 'http://drc.edeliver.com.au/ratecalc.asp?pickup_postcode=' . urlencode($this->config->get('auspost_postcode')) . '&destination_postcode=' . urlencode($address['postcode']) . '&height=70&width=70&length=70&country=AU&service_type=standard&quantity=1&weight=' . urlencode($weight));
  27. curl_setopt($curl, CURLOPT_HEADER, 0);
  28. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  29.  
  30. $response = curl_exec($curl);
  31.  
  32. curl_close($curl);
  33.  
  34. $response_info = array();
  35.  
  36. $parts = explode("\n", $response);
  37.  
  38. foreach ($parts as $part) {
  39. list($key, $value) = explode('=', $part);
  40.  
  41. $response_info[$key] = $value;
  42. }
  43.  
  44. if ($response_info['err_msg'] != 'OK') {
  45. $error = $response_info['err_msg'];
  46. } else {
  47. $title = $this->language->get('text_standard');
  48.  
  49. if ($this->config->get('auspost_display_time')) {
  50. $title .= ' (' . $response_info['days'] . ' ' . $this->language->get('text_eta') . ')';
  51. }
  52.  
  53. $quote_data['auspost_standard'] = array(
  54. 'code' => 'auspost.standard',
  55. 'title' => $title,
  56. 'cost' => $this->currency->convert($response_info['charge'], 'AUD', $this->config->get('config_currency')),
  57. 'tax_class_id' => $this->config->get('auspost_tax_class_id'),
  58. 'text' => $this->currency->format($this->tax->calculate($this->currency->convert($response_info['charge'], 'AUD', $this->currency->getCode()), $this->config->get('auspost_tax_class_id'), $this->config->get('config_tax')), $this->currency->getCode(), 1.0000000)
  59. );
  60. }
  61. }
  62.  
  63. if ($this->config->get('auspost_express') && $address['iso_code_2'] == 'AU') {
  64. $curl = curl_init();
  65.  
  66. curl_setopt($curl, CURLOPT_URL, 'http://drc.edeliver.com.au/ratecalc.asp?pickup_postcode=' . urlencode($this->config->get('auspost_postcode')) . '&destination_postcode=' . urlencode($address['postcode']) . '&height=70&width=70&length=70&country=AU&service_type=express&quantity=1&weight=' . urlencode($weight));
  67. curl_setopt($curl, CURLOPT_HEADER, 0);
  68. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  69.  
  70. $response = curl_exec($curl);
  71.  
  72. curl_close($curl);
  73.  
  74. $response_info = array();
  75.  
  76. $parts = explode("\n", $response);
  77.  
  78. foreach ($parts as $part) {
  79. list($key, $value) = explode('=', $part);
  80.  
  81. $response_info[$key] = $value;
  82. }
  83.  
  84. if ($response_info['err_msg'] != 'OK') {
  85. $error = $response_info['err_msg'];
  86. } else {
  87. $title = $this->language->get('text_express');
  88.  
  89. if ($this->config->get('auspost_display_time')) {
  90. $title .= ' (' . $response_info['days'] . ' ' . $this->language->get('text_eta') . ')';
  91. }
  92.  
  93. $quote_data['auspost_express'] = array(
  94. 'code' => 'auspost.express',
  95. 'title' => $title,
  96. 'cost' => $this->currency->convert($response_info['charge'], 'AUD', $this->config->get('config_currency')),
  97. 'tax_class_id' => $this->config->get('auspost_tax_class_id'),
  98. 'text' => $this->currency->format($this->tax->calculate($this->currency->convert($response_info['charge'], 'AUD', $this->currency->getCode()), $this->config->get('auspost_tax_class_id'), $this->config->get('config_tax')), $this->currency->getCode(), 1.0000000)
  99. );
  100. }
  101. }
  102. }
  103.  
  104. $method_data = array();
  105.  
  106. if ($quote_data) {
  107. $method_data = array(
  108. 'code' => 'auspost',
  109. 'title' => $this->language->get('text_title'),
  110. 'quote' => $quote_data,
  111. 'sort_order' => $this->config->get('auspost_sort_order'),
  112. 'error' => $error
  113. );
  114. }
  115.  
  116. return $method_data;
  117. }
  118. }
  119. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement