/**
  * Builds a shipment object representing the cart contents from WPEC
  * @author Greg Gullett (greg@ecsquest.com)
  * @return ASHShipment
  */
 function get_shipment()
 {
     global $wpdb, $wpsc_cart;
     $shipment = new ASHShipment();
     if (!$wpsc_cart) {
         return $shipment;
     }
     foreach ($wpsc_cart->cart_items as $cart_item) {
         $package = new ASHPackage();
         //*** Set package dimensions ***\\
         $dimensions = get_product_meta($cart_item->product_id, 'dimensions');
         $dim_array = array();
         $dim_array["weight"] = $cart_item->weight;
         $dim_array["height"] = !empty($dimensions["height"]) && is_numeric($dimensions["height"]) ? $dimensions["height"] : 1;
         $dim_array["width"] = !empty($dimensions["width"]) && is_numeric($dimensions["width"]) ? $dimensions["width"] : 1;
         $dim_array["length"] = !empty($dimensions["length"]) && is_numeric($dimensions["length"]) ? $dimensions["length"] : 1;
         $package->set_dimensions($dim_array);
         //*** Set other meta ***\\
         $package->hazard = get_product_meta($cart_item->product_id, "ship_hazard") === FALSE ? FALSE : TRUE;
         $package->insurance = get_product_meta($cart_item->product_id, "ship_insurance");
         $package->insured_amount = get_product_meta($cart_item->product_id, "ship_insured_amount");
         $package->value = $cart_item->unit_price;
         $package->contents = $cart_item->product_name;
         if ($shipment->hazard === FALSE and $package->hazard === TRUE) {
             $shipment->set_hazard(TRUE);
         }
         $quantity = (int) $cart_item->quantity;
         for ($i = 1; $i <= $quantity; $i++) {
             $shipment->add_package($package);
         }
     }
     return $shipment;
 }
 /**
  * Builds a shipment object representing the cart contents from WPEC
  *
  * @return ASHShipment
  */
 function get_shipment()
 {
     global $wpdb, $wpsc_cart;
     $shipment = new ASHShipment();
     if (!$wpsc_cart) {
         return $shipment;
     }
     foreach ($wpsc_cart->cart_items as $cart_item) {
         $package = new ASHPackage();
         //*** Set package dimensions ***\\
         $dimensions = get_product_meta($cart_item->product_id, 'product_metadata');
         //The 'dimensions' meta doesn't exist.
         if (isset($dimensions[0]['dimensions'])) {
             $dimensions = $dimensions[0]['dimensions'];
         }
         $dim_array = array();
         $dim_array["weight"] = $cart_item->weight;
         $dim_array["height"] = !empty($dimensions["height"]) && is_numeric($dimensions["height"]) ? $dimensions["height"] : 1;
         $dim_array["width"] = !empty($dimensions["width"]) && is_numeric($dimensions["width"]) ? $dimensions["width"] : 1;
         $dim_array["length"] = !empty($dimensions["length"]) && is_numeric($dimensions["length"]) ? $dimensions["length"] : 1;
         $package->set_dimensions($dim_array);
         /* Set other meta */
         $package->hazard = get_product_meta($cart_item->product_id, "ship_hazard", TRUE) === TRUE ? TRUE : FALSE;
         //Fixed ternary evaluation.
         $package->insurance = get_product_meta($cart_item->product_id, "ship_insurance", TRUE) === TRUE ? TRUE : FALSE;
         //Fixed ternary evaluation.
         $package->insured_amount = get_product_meta($cart_item->product_id, "ship_insured_amount", TRUE);
         //Fixed ternary evaluation.
         $package->value = $cart_item->unit_price;
         $package->contents = $cart_item->product_name;
         $package->this_side_up = get_post_meta($cart_item->product_id, "h:this_side_up", TRUE) === TRUE ? TRUE : FALSE;
         //Prod. page hide, prod. UI display
         if ($shipment->hazard === FALSE and $package->hazard === TRUE) {
             $shipment->set_hazard(TRUE);
         }
         $quantity = (int) $cart_item->quantity;
         $package->product_id[$cart_item->product_id] = 1;
         // The product in this package.
         for ($i = 1; $i <= $quantity; $i++) {
             $shipment->add_package($package);
         }
     }
     return $shipment;
 }