PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_virtuemart/classes/ps_shipping_method.php

http://vanphongphamdm.googlecode.com/
PHP | 285 lines | 195 code | 32 blank | 58 comment | 61 complexity | 15ec3e8d8470b451d3e787cadc0e55a0 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, Apache-2.0
  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. /**
  4. *
  5. * @version $Id: ps_shipping_method.php 2285 2010-02-01 10:57:18Z soeren_nb $
  6. * @package VirtueMart
  7. * @subpackage classes
  8. * @copyright Copyright (C) 2004-2009 soeren - All rights reserved.
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  10. * VirtueMart is free software. This version may have been modified pursuant
  11. * to the GNU General Public License, and as distributed it includes or
  12. * is derivative of works licensed under the GNU General Public License or
  13. * other free or open source software licenses.
  14. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
  15. *
  16. * http://virtuemart.net
  17. */
  18. class vm_ps_shipping_method {
  19. /**************************************************************************
  20. * name: save()
  21. * created by: soeren
  22. * description:
  23. * parameters:
  24. * returns:
  25. **************************************************************************/
  26. function save(&$d) {
  27. global $VM_LANG, $vmLogger;
  28. $ps_vendor_id = $_SESSION["ps_vendor_id"];
  29. $db = new ps_DB;
  30. $shipping_class = basename(vmGet($d,"shipping_class"));
  31. if( file_exists( CLASSPATH."shipping/".$shipping_class.".php" )) {
  32. include( CLASSPATH."shipping/".$shipping_class.".php" );
  33. $_SHIPPING = new $shipping_class();
  34. if( $_SHIPPING->configfile_writeable() ) {
  35. $_SHIPPING->write_configuration( $d );
  36. $vmLogger->info( $VM_LANG->_('VM_CONFIGURATION_CHANGE_SUCCESS',false) );
  37. return True;
  38. }
  39. else {
  40. $vmLogger->err( sprintf($VM_LANG->_('VM_CONFIGURATION_CHANGE_FAILURE',false) , CLASSPATH."payment/".$_SHIPPING->classname.".cfg.php" ) );
  41. return false;
  42. }
  43. }
  44. else {
  45. $vmLogger->err( 'The shipping class file '.CLASSPATH."shipping/".$d["shipping_class"].".php could not be found." );
  46. return false;
  47. }
  48. }
  49. /**************************************************************************
  50. ** name: method_list()
  51. ** created by: soeren
  52. ** description: list all available shipping methods
  53. ** parameters:
  54. ** returns:
  55. ***************************************************************************/
  56. function method_list( $payment_method_id="" ) {
  57. global $mosConfig_absolute_path;
  58. $ps_vendor_id = $_SESSION["ps_vendor_id"];
  59. $db = new ps_DB;
  60. $row = Array();
  61. $files = vmReadDirectory( CLASSPATH.'shipping/', '.ini$' );
  62. if( $files ) {
  63. require_once( CLASSPATH. 'ps_ini.php' );
  64. $ShippingModule = new mShop_ini();
  65. $i = 0;
  66. foreach( $files as $file ) {
  67. $i++;
  68. $ShippingModule->load( CLASSPATH.'shipping/'.$file );
  69. }
  70. return( $ShippingModule->_elements );
  71. }
  72. else
  73. return false;
  74. }
  75. function get_weight( $pid ) {
  76. global $vendor_country_2_code;
  77. if( empty($GLOBALS['product_info'][$pid]['weight'] )) {
  78. if( $vendor_country_2_code=="US"
  79. || $vendor_country_2_code=="PR"
  80. || $vendor_country_2_code=="DO"
  81. ) {
  82. defined( 'WEIGHT_UOM' ) or define('WEIGHT_UOM', "LB" );
  83. $GLOBALS['product_info'][$pid]['weight'] = ps_shipping_method::get_weight_LB( $pid );
  84. return $GLOBALS['product_info'][$pid]['weight'];
  85. }
  86. else {
  87. defined( 'WEIGHT_UOM' ) or define('WEIGHT_UOM', "KG" );
  88. $GLOBALS['product_info'][$pid]['weight'] = ps_shipping_method::get_weight_KG( $pid );
  89. return $GLOBALS['product_info'][$pid]['weight'];
  90. }
  91. }
  92. else
  93. return $GLOBALS['product_info'][$pid]['weight'];
  94. }
  95. /**************************************************************************
  96. ** name: get_weight_OZ()
  97. ** created by: Matt Oberpriller
  98. ** description: Calculate product weight in ounces
  99. ** parameters: product_id
  100. ** returns: weight in ounces
  101. ***************************************************************************/
  102. function get_weight_OZ($pid) {
  103. global $vars, $vmLogger;
  104. $ps_vendor_id = $_SESSION["ps_vendor_id"];
  105. $db = new ps_DB;
  106. $q = "SELECT product_sku,product_parent_id,product_weight,product_weight_uom FROM #__{vm}_product ";
  107. $q .= "WHERE product_id='$pid' ";
  108. $db->query($q);
  109. $db->next_record();
  110. if ($db->f("product_weight") == 0 && $db->f("product_parent_id")) {
  111. $q = "SELECT * from #__{vm}_product WHERE product_id='".$db->f("product_parent_id")."'";
  112. $db->query($q);
  113. $db->next_record();
  114. }
  115. if ($db->f("product_weight") > 0) {
  116. if (stristr($db->f("product_weight_uom"), "LB") || stristr($db->f("product_weight_uom"), "PO")) {
  117. $weight = $db->f("product_weight") * 16;
  118. }
  119. elseif (stristr($db->f("product_weight_uom"), "KG") || stristr($db->f("product_weight_uom"), "KILO")) {
  120. $weight = $db->f("product_weight") * 35.27396194958041;
  121. }
  122. elseif (stristr($db->f("product_weight_uom"), "G") || stristr($db->f("product_weight_uom"), "GRAM")) {
  123. $weight = $db->f("product_weight") * 0.035273961949580414;
  124. }
  125. elseif (stristr($db->f("product_weight_uom"), "OZ") || stristr($db->f("product_weight_uom"), "OU")) {
  126. $weight = $db->f("product_weight");
  127. }
  128. else {
  129. $vmLogger->debug( "Unknown weight UOM in product " . $db->f("product_sku") );
  130. }
  131. }
  132. else {
  133. $vmLogger->debug( "Weight not specified for product " . $db->f("product_sku"));
  134. }
  135. if (!empty($weight)) {
  136. return($weight);
  137. }
  138. else {
  139. return 0;
  140. }
  141. }
  142. /**************************************************************************
  143. ** name: get_weight_KG()
  144. ** created by: Matt Oberpriller
  145. ** modified by: Soeren
  146. ** description: Calculate product weight in Kilograms
  147. ** parameters: product_id
  148. ** returns: weight in KG
  149. ***************************************************************************/
  150. function get_weight_KG( $pid ) {
  151. global $vars, $vmLogger;
  152. $ps_vendor_id = $_SESSION["ps_vendor_id"];
  153. $db = new ps_DB;
  154. $q = "SELECT product_sku,product_parent_id,product_weight,product_weight_uom FROM #__{vm}_product ";
  155. $q .= "WHERE product_id='$pid' ";
  156. $db->query($q);
  157. $db->next_record();
  158. if ($db->f("product_weight") == 0 && $db->f("product_parent_id")) {
  159. $q = "SELECT * from #__{vm}_product WHERE product_id='".$db->f("product_parent_id")."'";
  160. $db->query($q);
  161. $db->next_record();
  162. }
  163. if ($db->f("product_weight") > 0) {
  164. if (stristr($db->f("product_weight_uom"), "LB") || stristr($db->f("product_weight_uom"), "PO")) {
  165. $weight = $db->f("product_weight") * 0.4536;
  166. }
  167. elseif (stristr($db->f("product_weight_uom"), "KG") || stristr($db->f("product_weight_uom"), "KILO")) {
  168. $weight = $db->f("product_weight");
  169. }
  170. elseif (stristr($db->f("product_weight_uom"), "G") || stristr($db->f("product_weight_uom"), "GRAM")) {
  171. $weight = $db->f("product_weight") * 0.001;
  172. }
  173. elseif (stristr($db->f("product_weight_uom"), "OZ") || stristr($db->f("product_weight_uom"), "OU")) {
  174. $weight = $db->f("product_weight") * 0.02835;
  175. }
  176. else {
  177. $vmLogger->debug( "Unknown weight UOM in product " . $db->f("product_sku"));
  178. }
  179. }
  180. else {
  181. $vmLogger->debug( "Weight not specified for product " . $db->f("product_sku"));
  182. }
  183. if (!empty($weight)) {
  184. return($weight);
  185. }
  186. else {
  187. return 0;
  188. }
  189. }
  190. /**************************************************************************
  191. ** name: get_weight_LB()
  192. ** created by: Matt Oberpriller
  193. ** modified by: Soeren
  194. ** description: Calculate product weight in Pounds
  195. ** parameters: product_id
  196. ** returns: weight in LB / PO
  197. ***************************************************************************/
  198. function get_weight_LB( $pid ) {
  199. global $vars, $vmLogger;
  200. $ps_vendor_id = $_SESSION["ps_vendor_id"];
  201. $db = new ps_DB;
  202. $q = "SELECT product_sku,product_parent_id,product_weight,product_weight_uom FROM #__{vm}_product ";
  203. $q .= "WHERE product_id='$pid' ";
  204. $db->query($q);
  205. $db->next_record();
  206. if ($db->f("product_weight") == 0 && $db->f("product_parent_id")) {
  207. $q = "SELECT * from #__{vm}_product WHERE product_id='".$db->f("product_parent_id")."'";
  208. $db->query($q);
  209. $db->next_record();
  210. }
  211. if ($db->f("product_weight") > 0) {
  212. if (stristr($db->f("product_weight_uom"), "LB") || stristr($db->f("product_weight_uom"), "PO")) {
  213. $weight = $db->f("product_weight");
  214. }
  215. elseif (stristr($db->f("product_weight_uom"), "KG") || stristr($db->f("product_weight_uom"), "KILO")) {
  216. $weight = $db->f("product_weight") * 2.20459;
  217. }
  218. elseif (stristr($db->f("product_weight_uom"), "G") || stristr($db->f("product_weight_uom"), "GRAM")) {
  219. $weight = $db->f("product_weight") * 0.00220459;
  220. }
  221. elseif (stristr($db->f("product_weight_uom"), "OZ") || stristr($db->f("product_weight_uom"), "OU")) {
  222. $weight = $db->f("product_weight") * 0.0625;
  223. }
  224. else {
  225. $vmLogger->debug( "Unknown weight UOM in product " . $db->f("product_sku"));
  226. }
  227. }
  228. else {
  229. $vmLogger->debug( "Weight not specified for product " . $db->f("product_sku"));
  230. }
  231. if (!empty($weight)) {
  232. return($weight);
  233. }
  234. else {
  235. return 0;
  236. }
  237. }
  238. }
  239. // Check if there is an extended class in the Themes and if it is allowed to use them
  240. // If the class is called outside Virtuemart, we have to make sure to load the settings
  241. // Thomas Kahl - Feb. 2009
  242. if (!defined('VM_ALLOW_EXTENDED_CLASSES') && file_exists(dirname(__FILE__).'/../virtuemart.cfg.php')) {
  243. include_once(dirname(__FILE__).'/../virtuemart.cfg.php');
  244. }
  245. // If settings are loaded, extended Classes are allowed and the class exisits...
  246. if (defined('VM_ALLOW_EXTENDED_CLASSES') && defined('VM_THEMEPATH') && VM_ALLOW_EXTENDED_CLASSES && file_exists(VM_THEMEPATH.'user_class/'.basename(__FILE__))) {
  247. // Load the theme-user_class as extended
  248. include_once(VM_THEMEPATH.'user_class/'.basename(__FILE__));
  249. } else {
  250. // Otherwise we have to use the original classname to extend the core-class
  251. class ps_shipping_method extends vm_ps_shipping_method {}
  252. }
  253. ?>