Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Custom Freight module issue Con - way


Guest

Recommended Posts

Hi all here is a description of the issue. I walked into this module after the fact but the problem is cart page ..

it will not show the subtotal if this shipping option is used in the admin product page.

 

the module is assigned on the product page by using any number over 0 example 2 and turns this shipping method on..

 

what I have found is that if it is on if I use a weight example 34.24 it doesn't show the subtotal in the cart. if I use example 00.34 (ounces) it does show the subtotal. this is the code that affects that ..

 

  function _setWeight($pounds, $ounces=0) {
     $this->pounds = $pounds;
     $this->ounces = $ounces;

 

This is a con-way module.. the bottom line if it is in affect the cart page does not show the subtotal correctly

 

<?php
/*
 $Id: 
*/

 class conway {
   var $code, $title, $description, $icon, $enabled, $countries;

// class constructor
   function conway() {
     global $order;

     $this->code = 'conway';
     $this->title = MODULE_SHIPPING_CONWAY_TEXT_TITLE;
     $this->description = MODULE_SHIPPING_CONWAY_TEXT_DESCRIPTION;
     $this->sort_order = MODULE_SHIPPING_CONWAY_SORT_ORDER;
     $this->icon = ''; // DIR_WS_ICONS . 'shipping_usps.gif';
     $this->tax_class = MODULE_SHIPPING_CONWAY_TAX_CLASS;
     $this->enabled = ((MODULE_SHIPPING_CONWAY_STATUS == 'True') ? true : false);

     if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_CONWAY_ZONE > 0) ) {
       $check_flag = false;
       $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_CONWAY_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
       while ($check = tep_db_fetch_array($check_query)) {
         if ($check['zone_id'] < 1) {
           $check_flag = true;
           break;
         } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
           $check_flag = true;
           break;
         }
       }

       if ($check_flag == false) {
         $this->enabled = false;
       }
     }
   }

// class methods
   function quote($method = '') {
     global $order, $shipping_weight, $shipping_num_boxes, $lift_gate;

     $conwayQuote = $this->_getQuote();
//print_r($conwayQuote); exit;
     if (is_array($conwayQuote)) {
       if (isset($conwayQuote['error'])) {
         $this->quotes = array('module' => $this->title,
                               'error' => $conwayQuote['error']);
       } else {
         $this->quotes = array('id' => $this->code,
                               'module' => $this->title);

         $methods = array();
         $size = sizeof($conwayQuote);
	  $acc_string = (!isset($order->delivery['company'])||$order->delivery['company']==''?' Residential':'');
	  $acc_string .= ($lift_gate?($acc_string?' &':'').' Lift Gate':'');
         for ($i=0; $i<$size; $i++) {
           list($type, $cost) = $conwayQuote[$i];
		//print_r($cost); exit;
           $methods[] = array('id' => $type,
                              'title' => 'Conway'. $acc_string.' Shipping',
                              'cost' => ($cost + MODULE_SHIPPING_CONWAY_HANDLING));
         }

         $this->quotes['methods'] = $methods;

         if ($this->tax_class > 0) {
           $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
         }
       }
     } else {
       $this->quotes = array('module' => $this->title,
                             'error' => MODULE_SHIPPING_CONWAY_TEXT_ERROR);
     }

     if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);

     return $this->quotes;
   }

   function check() {
     if (!isset($this->_check)) {
       $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_CONWAY_STATUS'");
       $this->_check = tep_db_num_rows($check_query);
     }
     return $this->_check;
   }

   function install() {
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable CONWAY Shipping', 'MODULE_SHIPPING_CONWAY_STATUS', 'True', 'Do you want to offer Con-way shipping?', '6', '0', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the CONWAY User ID', 'MODULE_SHIPPING_CONWAY_USERID', 'NONE', 'Enter the USERID assigned to you.', '6', '0', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the CONWAY Password', 'MODULE_SHIPPING_CONWAY_PASSWORD', 'NONE', 'See USERID, above.', '6', '0', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Enter the CONWAY Customer #', 'MODULE_SHIPPING_CONWAY_ACCOUNT', 'NONE', 'Con-Way Customer #', '6', '0', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Origin ZipCode', 'MODULE_SHIPPING_CONWAY_ORIGIN_ZIP', 'NONE', 'Company Send From Zip', '6', '0', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fees', 'MODULE_SHIPPING_CONWAY_HANDLING', 'NONE', 'Pads Con-Way Shipping Cost', '6', '0', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_CONWAY_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_CONWAY_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
     tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_CONWAY_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
   }

   function remove() {
     tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
   }

   function keys() {
     return array('MODULE_SHIPPING_CONWAY_STATUS', 'MODULE_SHIPPING_CONWAY_USERID', 'MODULE_SHIPPING_CONWAY_PASSWORD','MODULE_SHIPPING_CONWAY_ACCOUNT','MODULE_SHIPPING_CONWAY_ORIGIN_ZIP', 'MODULE_SHIPPING_CONWAY_HANDLING', 'MODULE_SHIPPING_CONWAY_TAX_CLASS', 'MODULE_SHIPPING_CONWAY_ZONE', 'MODULE_SHIPPING_CONWAY_SORT_ORDER');
   }

   function _setService($service) {
     $this->service = $service;
   }

   function _setWeight($pounds, $ounces=0) {
     $this->pounds = $pounds;
     $this->ounces = $ounces;
   }

   function _setContainer($container) {
     $this->container = $container;
   }

   function _setSize($size) {
     $this->size = $size;
   }

   function _setMachinable($machinable) {
     $this->machinable = $machinable;
   }

   function _getQuote() {
     global $order; global $cart; global $lift_gate;

     if ($order->delivery['country']['id'] == SHIPPING_ORIGIN_COUNTRY) {
     	$request  = '<RateRequest USERID="' . MODULE_SHIPPING_CONWAY_USERID . '" PASSWORD="' . MODULE_SHIPPING_CONWAY_PASSWORD . '">';
       $services_count = 0;

       $dest_zip = str_replace(' ', '', $order->delivery['postcode']);
       if ($order->delivery['country']['iso_code_2'] == 'US') $dest_zip = substr($dest_zip, 0, 5);

	$title = "Rating"; 
	$requestType = "RateRequest"; 
	$requestUrl = "https://www.Con-way.com/XMLj/X-Rate";; 

	// replace the USERNAME and PASSWORD String values below with your Con-way username and password 
	$username = MODULE_SHIPPING_CONWAY_USERID; 
	$password = MODULE_SHIPPING_CONWAY_PASSWORD; 
	// to get a customer-specific discount, replace the CUSTNMBR string below with your Con-way customer number, then uncomment the <CustNmbr> line below. 
	$custNmbr = MODULE_SHIPPING_CONWAY_ACCOUNT; 

	$today = date("m/d/y"); 

	// array of input data 
	//$myInput = $_GET; // If you don't pass data in as a GET variables, hard code them here: 
	if(MODULE_SHIPPING_CONWAY_ORIGIN_ZIP=='') return array('error' => 'Please set Con-way Orign Zipcode.');
	$myInput['origZip'] = MODULE_SHIPPING_CONWAY_ORIGIN_ZIP; 

	$dest_zip = str_replace(' ', '', $order->delivery['postcode']);
	if ($order->delivery['country']['iso_code_2'] == 'US') $myInput['destZip'] = substr($dest_zip, 0, 5);
	else return array('error' => 'Destination is not contenental US.');

	// array of elements you want to query from the XML Response 
	$myElements = array('TotalCharge', 'Discount', 'TotalAccessorialCharges', 'NetCharge', 'TransitTime'); 

	/* Build XML Request In actual use, you would probably populate the XML Request parameters (Weights, Classes, Zip Codes, etc.) 
	from data submitted via an on-line order form or database. For this sample we will just hard code some dummy data. */ 
	//$itemArray = array(); //Your commodity items, maximum of 4 - add as needed 
	//$itemArray[] = array('class'=>'775', 'weight'=>'667'); 
	//$itemArray[] = array('class'=>'100', 'weight'=>'555'); 

	$accArray = array(); // Your accessorial services - add as needed 
	//$accArray[] = "SSC";  // Sorting and Segregating
	//$accArray[] = "DNC";  // Order Notify Shipments
	//$accArray[] = "GUR";  // Guarantee of Delivery

	if(!isset($order->delivery['company'])||$order->delivery['company']=='')
		$accArray[] = "RSD";  // Destination Residential Delivery

	if($lift_gate)
		$accArray[] = "DLG";  // Lift Gate Service Delivery

	extract($myInput); 
	$xmlPreItemRequest = 	"<RateRequest>" . 
						"<OriginZip country=\"us\">$origZip</OriginZip>" . 
						"<DestinationZip country=\"us\">$destZip</DestinationZip>"; 

	// To get customer specific discount, uncomment this line: 
	if($custNmbr)
		$xmlPreItemRequest .= "<CustNmbr shipcode=\"S\">$custNmbr</CustNmbr>"; 

	$xmlPreItemRequest .=	"<ChargeCode>P</ChargeCode>" . 
						"<DiscountRate>82</DiscountRate>" . 
						"<EffectiveDate>$today</EffectiveDate>"; 

	$xmlPostItemRequest = '';
	foreach ($accArray as $acc) { // Add accessorials to the XML Request 
		$xmlPostItemRequest .= "<Accessorial>$acc</Accessorial>"; 
	} 
	$xmlPostItemRequest .= "</RateRequest>";

	$total_shipping_price = 0;
	$products = $cart->get_products(); 
	$xmlRequest = $xmlPreItemRequest;
	$item_count = 0; // You can't have more then 4 items quoted else it's more then a truck?
	$improperly_setup_product = false;
	$conway_product = false; // check if conway product exists
	foreach ($products as $p) { // Add commodity items to the XML Request 
		$product_query = tep_db_query("SELECT products_weight, products_class FROM ".TABLE_PRODUCTS." WHERE products_id='".(int)$p['id']."'");
		$product = tep_db_fetch_array($product_query);
		$class = $product['products_class'];
		// only check add products that have classes else it's not a Conway freight product!
		// also has to have a weight otherwise class is incorrect
		$weight = number_format($product['products_weight'], 0);
		if((int)$class>0 && $weight>0) { // indicates conway product
			$conway_product = true;
			$weight = str_replace(array('$',','),'',$weight);
			//$xmlRequest = $xmlPreItemRequest;
			for($z = 0; $z < $p['quantity']; $z++) {
				$xmlRequest .=	"<Item>" . 
								"<CmdtyClass>$class</CmdtyClass>" . 
								"<Weight unit=\"lbs\">$weight</Weight>" . 
								"</Item>";
				$item_count++;
			}
		}
		// An incorrectly configured product with a class but no weight!!!! OMG!  Bad admin, BAD!
		if((int)$class>0 && $weight==0) {
			mail(WEBSITE_DEVELOPER_EMAIL,'Improperly set Conway product #'.(int)$p['id'],"An imporperly priced item was found in the system while a customer was trying to order.\n\nProduct#".(int)$p['id'],'[email protected]'); 
			$improperly_setup_product = true;
		}
	}
	if(!$conway_product) return array(array('conway', 0));;
	if($item_count >4) return array('error' => '<span style="color:#fd0000">Error!</span> You will have to split up your order as we cannot have more then 4 products shipped via Conway per order.');
	$xmlRequest .= $xmlPostItemRequest;
	//echo htmlentities($xmlRequest); echo '<br><br>';
	 //Convert characters to proper format for HTTP POST 
	$xmlRequest = urlencode($xmlRequest);
	$shipping_result = $this->getCNWQuote($xmlRequest);
	//echo htmlentities($shipping_result); exit;
	if($improperly_setup_product || round($shipping_result)<5) return array('error' => '<span style="color:#fd0000">Error!</span> Issue with Con-way shipping cost results.<br>This issue is with a product in your cart and has been reported.  <br />Please <a href="contact_us.php">Contact Us</a> in regards to delivering the product to your above address.');
	//echo $shipping_result; exit;
	if($shipping_result) $total_shipping_price += $shipping_result*$p['quantity'];
	else return array('error' => '<span style="color:#fd0000">Error!</span> Issue with Con-way shipping cost results.');

	return array(array('conway', $total_shipping_price));
     } else {
       return array('error' => '<span style="color:#fd0000">Error!</span> International Shipping Not Implemented in this Custom Module.');
     }

     return ((sizeof($rates) > 0) ? $rates : false);
   }

function getCNWQuote($url) {
	$requestUrl = "https://www.Con-way.com/XMLj/X-Rate";
	$requestType = "RateRequest";
	$username = "";
	$password = "";
	$urlConn = curl_init ($requestUrl);
	curl_setopt ($urlConn, CURLOPT_POST, 1);
	curl_setopt ($urlConn, CURLOPT_SSL_VERIFYPEER, false); // May be needed for SSL behind a firewall
	curl_setopt ($urlConn, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
	curl_setopt ($urlConn, CURLOPT_USERPWD, $username.":".$password);
	curl_setopt ($urlConn, CURLOPT_POSTFIELDS, "$requestType=$url");

	// Get the XML Response
	// prevent the buffer from being displayed
	ob_start();
	curl_exec($urlConn);
	$url = ob_get_contents();
	ob_end_clean();

	curl_close($urlConn); // close the connection

	$xmlResponse = $url; 
	if (strpos($xmlResponse, 'RATINGERROR') === true || strpos($xmlResponse, '<NetCharge currency="USD">') === false) {
		return true;
	} else {

		$start_pos = strpos($xmlResponse, '<NetCharge currency=') + 26;
		$string_len = strpos($xmlResponse, '</NetCharge>') - $start_pos;
		$shipping_price = str_replace(',', '', substr($xmlResponse, $start_pos, $string_len));
		if (is_numeric($shipping_price)) {
			return $shipping_price;
		} else {
			return false;
		}
	}
}
 }
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...