ASHShipment

Object representation of a shipment of packages based on the contents of a shopping cart.

Defined (1)

The class is defined in the following location(s).

/wpsc-includes/shipping.helper.php  
  1. class ASHShipment{ 
  2. /** 
  3. * An array of ASHPackage objects 
  4. * @var array 
  5. */ 
  6. var $packages=array(); 
  7. /** 
  8. * Flag denotes if there are any hazardous packages in the shipment overall 
  9. * @var boolean 
  10. */ 
  11. var $hazard = FALSE; 
  12. /** 
  13. * The amount of packages in the shipment, automatically increments when 
  14. * you use the add_package() function 
  15. * @var int 
  16. */ 
  17. var $package_count=0; 
  18. /** 
  19. * An array that represents the destination, (State, Zipode, Country) 
  20. * @var array 
  21. */ 
  22. var $destination = array(); 
  23. /** 
  24. * The overall value of the contents of the shipment (all packages value summed together) 
  25. * Automatically calculated when you use add_package() 
  26. * @var decimal 
  27. */ 
  28. var $shipment_value = 0; 
  29. /** 
  30. * The overal weight of the contents of the shipment (all packages weight summed together) 
  31. * Automaticaly calculated when you use add_package() 
  32. * @var unknown_type 
  33. */ 
  34. var $total_weight = 0; 
  35. /** 
  36. * Sets a rate expire date 
  37. * @var string 
  38. */ 
  39. var $rates_expire = ''; 
  40.  
  41. /** 
  42. * Constructor for the ASHShipment class 
  43. * @since 0.0.1 
  44. */ 
  45. function ASHShipment() { 
  46.  
  47. /** 
  48. * Sets the destination array using either post, session or provided array 
  49. * @param string $internal_name internal name of shipping module 
  50. * @param array $dest optional array if you already know destination. 
  51. */ 
  52. function set_destination($internal_name, $dest=FALSE) { 
  53. if (!$dest) { 
  54. $tools = new ASHTools(); 
  55. $wpec_ash = wpsc_get_customer_meta( 'shipping_ash' ); 
  56. if ( ! $wpec_ash ) 
  57. $wpec_ash = array(); 
  58.  
  59. $session_destination = ( array_key_exists( $internal_name, $wpec_ash ) ? $wpec_ash[$internal_name]["shipment"]["destination"] : array() ); 
  60. $this->destination = $tools->get_destination($session_destination); 
  61. }else{ 
  62. $this->destination = $dest; 
  63.  
  64.  
  65. /** 
  66. * This is a magic function that controls access to protected items 
  67. * and allows you to retrieve their values (php5) 
  68. * @param string $item 
  69. * @return mixed 
  70. */ 
  71. function __get($item) { 
  72. return $this->$item; 
  73.  
  74. /** 
  75. * This function sets the hazard flag on the class 
  76. * while it seems inane, i am making sure that the values 
  77. * are truly boolean true or false 
  78. * @param boolean $flag 
  79. */ 
  80. function set_hazard($flag) { 
  81. if ($flag == TRUE) { 
  82. $this->hazard = TRUE; 
  83. }else{ 
  84. $this->hazard = FALSE; 
  85.  
  86. /** 
  87. * Use this function to add a package object to the shipment. 
  88. * it expects an object of class ASHPackage or throws an exception 
  89. * @since 0.0.1 
  90. * @param ASHPackage $package 
  91. * @throws ErrorException 
  92. */ 
  93. function add_package($package) { 
  94. if ($package instanceof ASHPackage) { 
  95. array_push($this->packages, $package); 
  96. $this->package_count++; 
  97. $this->total_weight += $package->weight; 
  98. $this->shipment_value += $package->value; 
  99. }else{ 
  100. $type = gettype($package); 
  101. throw new ErrorException("ASHSHipment expected object of class ASHPackage, got instance of {$type} instead"); 
  102.