PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wp-e-commerce/shipping/flatrate.php

https://gitlab.com/endomorphosis/reservationtelco
PHP | 171 lines | 139 code | 26 blank | 6 comment | 36 complexity | d6704900703188559bc10908a6e34c1f MD5 | raw file
  1. <?php
  2. class flatrate {
  3. var $internal_name, $name;
  4. function flatrate () {
  5. $this->internal_name = "flatrate";
  6. $this->name="Flat Rate";
  7. $this->is_external=false;
  8. return true;
  9. }
  10. function getId() {
  11. // return $this->usps_id;
  12. }
  13. function setId($id) {
  14. // $usps_id = $id;
  15. // return true;
  16. }
  17. function getName() {
  18. return $this->name;
  19. }
  20. function getInternalName() {
  21. return $this->internal_name;
  22. }
  23. function getForm() {
  24. $shipping = get_option('flat_rates');
  25. $output = "<tr><td colspan='2'>" . __('If you do not wish to ship to a particular region, leave the field blank. To offer free shipping to a region, enter 0.', 'wpsc') . "</td>";
  26. $output .= "<tr><td colspan='1'><strong>Base Local</strong></td>";
  27. switch(get_option('base_country')) {
  28. case 'NZ':
  29. $output .= "<tr class='rate_row'><td>South Island</td><td>$<input type='text' size='4' name='shipping[southisland]' value='{$shipping['southisland']}'></td></tr>";
  30. $output .= "<tr class='rate_row'><td>North Island</td><td>$<input type='text' size='4' name='shipping[northisland]' value='{$shipping['northisland']}'></td></tr>";
  31. break;
  32. case 'US':
  33. $output .= "<tr class='rate_row'><td>Continental 48 States</td><td>$<input type='text' size='4' name='shipping[continental]' value='{$shipping['continental']}'></td></tr>";
  34. $output .= "<tr class='rate_row'><td>All 50 States</td><td>$<input type='text' size='4' name='shipping[all]' value='{$shipping['all']}'></td></tr>";
  35. break;
  36. default:
  37. $output .= "<td>$<input type='text' name='shipping[local]' size='4' value='{$shipping['local']}'></td></tr>";
  38. break;
  39. }
  40. $output.= "<tr ><td colspan='2'><strong>Base International</strong></td></tr>";
  41. $output .= "<tr class='rate_row'><td>North America</td><td>$<input size='4' type='text' name='shipping[northamerica]' value='{$shipping['northamerica']}'></td></tr>";
  42. $output .= "<tr class='rate_row'><td>South America</td><td>$<input size='4' type='text' name='shipping[southamerica]' value='{$shipping['southamerica']}'></td></tr>";
  43. $output .= "<tr class='rate_row'><td>Asia and Pacific</td><td>$<input size='4' type='text' name='shipping[asiapacific]' value='{$shipping['asiapacific']}'></td></tr>";
  44. $output .= "<tr class='rate_row'><td>Europe</td><td>$<input type='text' size='4' name='shipping[europe]' value='{$shipping['europe']}'></td></tr>";
  45. $output .= "<tr class='rate_row'><td>Africa</td><td>$<input type='text' size='4' name='shipping[africa]' value='{$shipping['africa']}'></td></tr>";
  46. return $output;
  47. }
  48. function submit_form() {
  49. if($_POST['shipping'] != null) {
  50. $shipping = (array)get_option('flat_rates');
  51. $submitted_shipping = (array)$_POST['shipping'];
  52. update_option('flat_rates',array_merge($shipping, $submitted_shipping));
  53. }
  54. return true;
  55. }
  56. function getQuote($for_display = false) {
  57. global $wpdb, $wpsc_cart;
  58. if (isset($_POST['country'])) {
  59. $country = $_POST['country'];
  60. $_SESSION['wpsc_delivery_country'] = $country;
  61. } else {
  62. $country = $_SESSION['wpsc_delivery_country'];
  63. }
  64. $_SESSION['quote_shipping_option'] = null;
  65. if (get_option('base_country') != $country) {
  66. $results = $wpdb->get_var("SELECT `continent` FROM `".WPSC_TABLE_CURRENCY_LIST."` WHERE `isocode` IN('{$country}') LIMIT 1");
  67. $flatrates = get_option('flat_rates');
  68. $_SESSION['quote_shipping_option'] = null;
  69. if ($flatrates != '') {
  70. if($_SESSION['quote_shipping_method'] == $this->internal_name) {
  71. if($_SESSION['quote_shipping_option'] != "Flat Rate") {
  72. $_SESSION['quote_shipping_option'] = null;
  73. }
  74. }
  75. if (strlen($flatrates[$results]) > 0) return array("Flat Rate"=>(float)$flatrates[$results]);
  76. }
  77. } else {
  78. $flatrates = get_option('flat_rates');
  79. $shipping_quotes = array();
  80. switch($country) {
  81. case 'NZ':
  82. if (strlen($flatrates['northisland']) > 0) $shipping_quotes["North Island"] = (float)$flatrates['northisland'];
  83. if (strlen($flatrates['southisland']) > 0) $shipping_quotes["South Island"] = (float)$flatrates['southisland'];
  84. break;
  85. case 'US':
  86. if (strlen($flatrates['continental']) > 0) $shipping_quotes["Continental 48 States"] = (float)$flatrates['continental'];
  87. if (strlen($flatrates['all']) > 0) $shipping_quotes["All 50 States"] = (float)$flatrates['all'];
  88. break;
  89. default:
  90. if (strlen($flatrates['local']) > 0) $shipping_quotes["Local Shipping"] = (float)$flatrates['local'];
  91. break;
  92. }
  93. if($_SESSION['quote_shipping_method'] == $this->internal_name) {
  94. $shipping_options = array_keys($shipping_quotes);
  95. if(array_search($_SESSION['quote_shipping_option'], $shipping_options) === false) {
  96. $_SESSION['quote_shipping_option'] = null;
  97. }
  98. }
  99. return $shipping_quotes;
  100. }
  101. }
  102. function get_item_shipping(&$cart_item) {
  103. global $wpdb, $wpsc_cart;
  104. $unit_price = $cart_item->unit_price;
  105. $quantity = $cart_item->quantity;
  106. $weight = $cart_item->weight;
  107. $product_id = $cart_item->product_id;
  108. $uses_billing_address = false;
  109. foreach((array)$cart_item->category_id_list as $category_id) {
  110. $uses_billing_address = (bool)wpsc_get_categorymeta($category_id, 'uses_billing_address');
  111. if($uses_billing_address === true) {
  112. break; /// just one true value is sufficient
  113. }
  114. }
  115. if(is_numeric($product_id) && (get_option('do_not_use_shipping') != 1)) {
  116. if($uses_billing_address == true) {
  117. $country_code = $wpsc_cart->selected_country;
  118. } else {
  119. $country_code = $wpsc_cart->delivery_country;
  120. }
  121. $product_list = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='{$product_id}' LIMIT 1",ARRAY_A);
  122. if($product_list['no_shipping'] == 0) {
  123. //if the item has shipping
  124. if($country_code == get_option('base_country')) {
  125. $additional_shipping = $product_list['pnp'];
  126. } else {
  127. $additional_shipping = $product_list['international_pnp'];
  128. }
  129. $shipping = $quantity * $additional_shipping;
  130. } else {
  131. //if the item does not have shipping
  132. $shipping = 0;
  133. }
  134. } else {
  135. //if the item is invalid or all items do not have shipping
  136. $shipping = 0;
  137. }
  138. return $shipping;
  139. }
  140. function get_cart_shipping($total_price, $weight) {
  141. return $output;
  142. }
  143. }
  144. $flatrate = new flatrate();
  145. $wpsc_shipping_modules[$flatrate->getInternalName()] = $flatrate;