Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.61 KB | None | 0 0
  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.  
  11. function getId() {
  12. // return $this->usps_id;
  13. }
  14.  
  15. function setId($id) {
  16. // $usps_id = $id;
  17. // return true;
  18. }
  19.  
  20. function getName() {
  21. return $this->name;
  22. }
  23.  
  24. function getInternalName() {
  25. return $this->internal_name;
  26. }
  27.  
  28.  
  29. function getForm() {
  30. $shipping = get_option('flat_rates');
  31. $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>";
  32. $output .= "<tr><td colspan='2'>" . __('Note: If you apply $0 to any region the postage and packaging applied to products will still be added on at checkout.', 'wpsc') . "</td>";
  33. $output .= "<tr><td colspan='1'><strong>Base Local</strong></td>";
  34.  
  35. switch(get_option('base_country')) {
  36. case 'NZ':
  37. $output .= "<tr class='rate_row'><td>South Island</td><td>$<input type='text' size='4' name='shipping[southisland]' value='{$shipping['southisland']}'></td></tr>";
  38. $output .= "<tr class='rate_row'><td>North Island</td><td>$<input type='text' size='4' name='shipping[northisland]' value='{$shipping['northisland']}'></td></tr>";
  39. break;
  40.  
  41. case 'US':
  42. $output .= "<tr class='rate_row'><td>Continental 48 States</td><td>$<input type='text' size='4' name='shipping[continental]' value='{$shipping['continental']}'></td></tr>";
  43. $output .= "<tr class='rate_row'><td>All 50 States</td><td>$<input type='text' size='4' name='shipping[all]' value='{$shipping['all']}'></td></tr>";
  44. break;
  45.  
  46. default:
  47. $output .= "<td>$<input type='text' name='shipping[local]' size='4' value='{$shipping['local']}'></td></tr>";
  48. break;
  49. }
  50.  
  51. $output.= "<tr ><td colspan='2'><strong>Base International</strong></td></tr>";
  52. $output .= "<tr class='rate_row'><td>North America</td><td>$<input size='4' type='text' name='shipping[northamerica]' value='{$shipping['northamerica']}'></td></tr>";
  53. $output .= "<tr class='rate_row'><td>South America</td><td>$<input size='4' type='text' name='shipping[southamerica]' value='{$shipping['southamerica']}'></td></tr>";
  54. $output .= "<tr class='rate_row'><td>Asia and Pacific</td><td>$<input size='4' type='text' name='shipping[asiapacific]' value='{$shipping['asiapacific']}'></td></tr>";
  55. $output .= "<tr class='rate_row'><td>Europe</td><td>$<input type='text' size='4' name='shipping[europe]' value='{$shipping['europe']}'></td></tr>";
  56. $output .= "<tr class='rate_row'><td>Africa</td><td>$<input type='text' size='4' name='shipping[africa]' value='{$shipping['africa']}'></td></tr>";
  57. return $output;
  58. }
  59.  
  60. function submit_form() {
  61. if($_POST['shipping'] != null) {
  62. $shipping = (array)get_option('flat_rates');
  63. $submitted_shipping = (array)$_POST['shipping'];
  64. update_option('flat_rates',array_merge($shipping, $submitted_shipping));
  65. }
  66. return true;
  67. }
  68.  
  69. function getQuote($for_display = false) {
  70. global $wpdb, $wpsc_cart;
  71. if (isset($_POST['country'])) {
  72. $country = $_POST['country'];
  73. $_SESSION['wpsc_delivery_country'] = $country;
  74. } else {
  75. $country = $_SESSION['wpsc_delivery_country'];
  76. }
  77. $_SESSION['quote_shipping_option'] = null;
  78.  
  79. if (get_option('base_country') != $country) {
  80. $results = $wpdb->get_var("SELECT `continent` FROM `".WPSC_TABLE_CURRENCY_LIST."` WHERE `isocode` IN('{$country}') LIMIT 1");
  81. $flatrates = get_option('flat_rates');
  82. $_SESSION['quote_shipping_option'] = null;
  83.  
  84. if ($flatrates != '') {
  85.  
  86. if($_SESSION['quote_shipping_method'] == $this->internal_name) {
  87. if($_SESSION['quote_shipping_option'] != "Flat Rate") {
  88. $_SESSION['quote_shipping_option'] = null;
  89. }
  90. }
  91.  
  92. if (strlen($flatrates[$results]) > 0) return array("Flat Rate"=>(float)$flatrates[$results]);
  93. }
  94. } else {
  95. $flatrates = get_option('flat_rates');
  96. $shipping_quotes = array();
  97. switch($country) {
  98. case 'NZ':
  99. if (strlen($flatrates['northisland']) > 0) $shipping_quotes["North Island"] = (float)$flatrates['northisland'];
  100. if (strlen($flatrates['southisland']) > 0) $shipping_quotes["South Island"] = (float)$flatrates['southisland'];
  101. break;
  102.  
  103. case 'US':
  104. if (strlen($flatrates['continental']) > 0) $shipping_quotes["Continental 48 States"] = (float)$flatrates['continental'];
  105. if (strlen($flatrates['all']) > 0) $shipping_quotes["All 50 States"] = (float)$flatrates['all'];
  106. break;
  107.  
  108. default:
  109. if (strlen($flatrates['local']) > 0) $shipping_quotes["Local Shipping"] = (float)$flatrates['local'];
  110. break;
  111. }
  112. if($_SESSION['quote_shipping_method'] == $this->internal_name) {
  113. $shipping_options = array_keys($shipping_quotes);
  114. if(array_search($_SESSION['quote_shipping_option'], $shipping_options) === false) {
  115. $_SESSION['quote_shipping_option'] = null;
  116. }
  117. }
  118.  
  119. return $shipping_quotes;
  120. }
  121. }
  122.  
  123.  
  124. function get_item_shipping(&$cart_item) {
  125. global $wpdb, $wpsc_cart;
  126. $unit_price = $cart_item->unit_price;
  127. $quantity = $cart_item->quantity;
  128. $weight = $cart_item->weight;
  129. $product_id = $cart_item->product_id;
  130.  
  131.  
  132. $uses_billing_address = false;
  133. foreach((array)$cart_item->category_id_list as $category_id) {
  134. $uses_billing_address = (bool)wpsc_get_categorymeta($category_id, 'uses_billing_address');
  135. if($uses_billing_address === true) {
  136. break; /// just one true value is sufficient
  137. }
  138. }
  139.  
  140. if(is_numeric($product_id) && (get_option('do_not_use_shipping') != 1)) {
  141. if($uses_billing_address == true) {
  142. $country_code = $wpsc_cart->selected_country;
  143. } else {
  144. $country_code = $wpsc_cart->delivery_country;
  145. }
  146.  
  147. $product_list = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`='{$product_id}' LIMIT 1",ARRAY_A);
  148. if($product_list['no_shipping'] == 0) {
  149. //if the item has shipping
  150. if($country_code == get_option('base_country')) {
  151. $additional_shipping = $product_list['pnp'];
  152. } else {
  153. $additional_shipping = $product_list['international_pnp'];
  154. }
  155. $shipping = $quantity * $additional_shipping;
  156. } else {
  157. //if the item does not have shipping
  158. $shipping = 0;
  159. }
  160. } else {
  161. //if the item is invalid or all items do not have shipping
  162. $shipping = 0;
  163. }
  164. return $shipping;
  165. }
  166.  
  167. function get_cart_shipping($total_price, $weight) {
  168. return $output;
  169. }
  170. }
  171. $flatrate = new flatrate();
  172. $wpsc_shipping_modules[$flatrate->getInternalName()] = $flatrate;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement