Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

PHP Help


taylorjes

Recommended Posts

I'm attempting to rework an old addon by tmanipulating the PHP. I was doing fine until I got stuck (don't you hate that).

 

If someone is so inclined to review this code and comment that would be appreciated

 

Code:

/** BOF Class Constructor **/
class dly3 {
var $code, $title, $description, $icon, $enabled, $shipping_costs, $postcode_descrption, $cost_description;

function dly3() {
	global $order;
	$this->code = 'dly3';
	$this->title = MODULE_SHIPPING_DLY3_TEXT_TITLE;
	$this->description = MODULE_SHIPPING_DLY3_TEXT_DESCRIPTION;
	$this->tax_class = MODULE_SHIPPING_DLY3_TAX_CLASS;
	$this->sort_order = MODULE_SHIPPING_DLY3_SORT_ORDER;
	$this->icon = DIR_WS_ICONS . 'shipping_dly.gif'; // To remove icon change to: $this->icon = 'pixel_trans.gif';
	$this->enabled = MODULE_SHIPPING_DLY3_STATUS;

	/** BOF Minimum Order Total required to activate module **/
	$this->min_order = MODULE_SHIPPING_DLY3_MINIMUM_ORDER_TOTAL;
	if (($order->info['total']) < ($this->min_order) ) {
		$this->enabled = false;
	}
	/** EOF Minimum Order Total required to activate module **/

	/** BOF Check Flag **/
	if ($this->enabled == true) {
		$check_flag = false;
		//$postzone_flag = false;

		/** BOF Limit Postcode **/
		$order->delivery['postcode'] = strtoupper($order->delivery['postcode']);
		$order->delivery['postcode'] = str_replace(' ', '', $order->delivery['postcode']);
		$order_postcode_2 = substr(str_replace(' ', '',strtoupper($order->delivery['postcode'])), 0, 3);//<--- strip postcode here 
		/** EOF Limit Postcode **/

		/** BOF Postcode Check **/
		$zip_up0 = MODULE_SHIPPING_DLY3_ZIPCODE0;
		$zip_up0 = strtoupper($zip_up0);
		$zip_up0 = str_replace (' ', '', $zip_up0);
		$zipcodes0 = explode(',', $zip_up0);		//<-- changes here

		$zip_up1 = MODULE_SHIPPING_DLY3_ZIPCODE1;
		$zip_up1 = strtoupper($zip_up1);
		$zip_up1 = str_replace (' ', '', $zip_up1);
		$zipcodes1 = explode(',', $zip_up1);		//<-- changes here

		$zip_up2 = MODULE_SHIPPING_DLY3_ZIPCODE2;
		$zip_up2 = strtoupper($zip_up2);
		$zip_up2 = str_replace (' ', '', $zip_up2);
		$zipcodes2 = explode(',', $zip_up2);		//<-- changes here

		$zip_up3 = MODULE_SHIPPING_DLY3_ZIPCODE3;
		$zip_up3 = strtoupper($zip_up3);
		$zip_up3 = str_replace (' ', '', $zip_up3);
		$zipcodes3 = split (',', $zip_up3);		

		$zip_up4 = MODULE_SHIPPING_DLY3_ZIPCODE4;
		$zip_up4 = strtoupper($zip_up4);
		$zip_up4 = str_replace (' ', '', $zip_up4);
		$zipcodes4 = split (',', $zip_up4);		

		$zip_up5 = MODULE_SHIPPING_DLY3_ZIPCODE5;
		$zip_up5 = strtoupper($zip_up5);
		$zip_up5 = str_replace (' ', '', $zip_up5);
		$zipcodes5 = split (',', $zip_up5);		

		$zip_up6 = MODULE_SHIPPING_DLY3_ZIPCODE6;
		$zip_up6 = strtoupper($zip_up6);
		$zip_up6 = str_replace (' ', '', $zip_up6);
		$zipcodes6 = split (',', $zip_up6);		

		$zip_up7 = MODULE_SHIPPING_DLY3_ZIPCODE7;
		$zip_up7 = strtoupper($zip_up7);
		$zip_up7 = str_replace (' ', '', $zip_up7);
		$zipcodes7 = split (',', $zip_up7);		

		$zip_up8 = MODULE_SHIPPING_DLY3_ZIPCODE8;
		$zip_up8 = strtoupper($zip_up8);
		$zip_up8 = str_replace (' ', '', $zip_up8);
		$zipcodes8 = split (',', $zip_up8);		

		$zip_up9 = MODULE_SHIPPING_DLY3_ZIPCODE9;
		$zip_up9 = strtoupper($zip_up9);
		$zip_up9 = str_replace (' ', '', $zip_up9);
		$zipcodes9 = split (',', $zip_up9);		

		/*** Insert New Zipcode HERE ***/

		if (in_array($order_postcode_2, $zipcodes0, true)){$check_flag = true;}   //<-- changes here
		elseif (in_array($order_postcode_2, $zipcodes1, true)){$check_flag = true;}   //<-- changes here
		elseif (in_array($order_postcode_2, $zipcodes2, true)){$check_flag = true;}   //<-- changes here
		elseif (in_array($order_postcode_2, $zipcodes3)){$check_flag = true;}
		elseif (in_array($order_postcode_2, $zipcodes4)){$check_flag = true;}
		elseif (in_array($order_postcode_2, $zipcodes5)){$check_flag = true;}
		elseif (in_array($order_postcode_2, $zipcodes6)){$check_flag = true;}
		elseif (in_array($order_postcode_2, $zipcodes7)){$check_flag = true;}
		elseif (in_array($order_postcode_2, $zipcodes8)){$check_flag = true;}
		elseif (in_array($order_postcode_2, $zipcodes9)){$check_flag = true;}
		/*** Add "elseif ($order_postcode_2 = $zipcodes##){$check_flag = true;}" HERE ***/
		if ($check_flag == false) {
			$this->enabled = false;
		}// EOF Postcode Check: true = activate during checkout_shipping
	}// EOF Check Flag
}//EOF Function dly3

/** BOF Class Method **/
function quote($method = '') {
	global $order, $cart, $shipping_weight, $shipping_num_boxes;
	if (MODULE_SHIPPING_DLY3_MODE == 'price') {
		$order_total = $cart->show_total();
	} else {
		$order_total = $shipping_weight;
	}
	$zip_up0 = MODULE_SHIPPING_DLY3_ZIPCODE0;
	$zip_up0 = strtoupper($zip_up0);
	$zip_up0 = str_replace (' ', '', $zip_up0);
	$zipcodes0 = explode(',', $zip_up0);		//<-- changes here

	$zip_up1 = MODULE_SHIPPING_DLY3_ZIPCODE1;
	$zip_up1 = strtoupper($zip_up1);
	$zip_up1 = str_replace (' ', '', $zip_up1);
	$zipcodes1 = explode(',', $zip_up1);		//<-- changes here

	$zip_up2 = MODULE_SHIPPING_DLY3_ZIPCODE2;
	$zip_up2 = strtoupper($zip_up2);
	$zip_up2 = str_replace (' ', '', $zip_up2);
	$zipcodes2 = explode(',', $zip_up2);		//<-- changes here

	$zip_up3 = MODULE_SHIPPING_DLY3_ZIPCODE3;
	$zip_up3 = strtoupper($zip_up3);
	$zip_up3 = str_replace (' ', '', $zip_up3);
	$zipcodes3 = split (',', $zip_up3);		

	$zip_up4 = MODULE_SHIPPING_DLY3_ZIPCODE4;
	$zip_up4 = strtoupper($zip_up4);
	$zip_up4 = str_replace (' ', '', $zip_up4);
	$zipcodes4 = split (',', $zip_up4);		

	$zip_up5 = MODULE_SHIPPING_DLY3_ZIPCODE5;
	$zip_up5 = strtoupper($zip_up5);
	$zip_up5 = str_replace (' ', '', $zip_up5);
	$zipcodes5 = split (',', $zip_up5);		

	$zip_up6 = MODULE_SHIPPING_DLY3_ZIPCODE6;
	$zip_up6 = strtoupper($zip_up6);
	$zip_up6 = str_replace (' ', '', $zip_up6);
	$zipcodes6 = split (',', $zip_up6);		

	$zip_up7 = MODULE_SHIPPING_DLY3_ZIPCODE7;
	$zip_up7 = strtoupper($zip_up7);
	$zip_up7 = str_replace (' ', '', $zip_up7);
	$zipcodes7 = split (',', $zip_up7);		

	$zip_up8 = MODULE_SHIPPING_DLY3_ZIPCODE8;
	$zip_up8 = strtoupper($zip_up8);
	$zip_up8 = str_replace (' ', '', $zip_up8);
	$zipcodes8 = split (',', $zip_up8);		

	$zip_up9 = MODULE_SHIPPING_DLY3_ZIPCODE9;
	$zip_up9 = strtoupper($zip_up9);
	$zip_up9 = str_replace (' ', '', $zip_up9);
	$zipcodes9 = split (',', $zip_up9);		

	/*** Insert New Zipcode HERE***/

	/** BOF Postcode Check **/
	if (in_array($order_postcode_2, $zipcodes0, true)){$shipping_costs = MODULE_SHIPPING_DLY3_COST0;}   //<-- changes here
	elseif (in_array($order_postcode_2, $zipcodes1, true)){$shipping_costs = MODULE_SHIPPING_DLY3_COST1;}   //<-- changes here
	elseif (in_array($order_postcode_2, $zipcodes2, true)){$shipping_costs = MODULE_SHIPPING_DLY3_COST2;}   //<-- changes here
	elseif (in_array($order_postcode_2, $zipcodes3)){$shipping_costs = MODULE_SHIPPING_DLY3_COST3;}
	elseif (in_array($order_postcode_2, $zipcodes4)){$shipping_costs = MODULE_SHIPPING_DLY3_COST4;}
	elseif (in_array($order_postcode_2, $zipcodes5)){$shipping_costs = MODULE_SHIPPING_DLY3_COST5;}
	elseif (in_array($order_postcode_2, $zipcodes6)){$shipping_costs = MODULE_SHIPPING_DLY3_COST6;}
	elseif (in_array($order_postcode_2, $zipcodes7)){$shipping_costs = MODULE_SHIPPING_DLY3_COST7;}
	elseif (in_array($order_postcode_2, $zipcodes8)){$shipping_costs = MODULE_SHIPPING_DLY3_COST8;}
	elseif (in_array($order_postcode_2, $zipcodes9)){$shipping_costs = MODULE_SHIPPING_DLY3_COST9;}
	/*** Insert New "elseif ($order_postcode_2 = $zipcodes##){$shipping_costs = MODULE_SHIPPING_DLY3_COST##;}" HERE ***/
	/** EOF Postcode Check**/
	$table_cost = split("[:,]" , $shipping_costs);
	$shipping_rate = 0;
	$size = sizeof($table_cost);
	for ($i=0, $n=$size; $i<$n; $i+=2) {
		if ($order_total <= $table_cost[$i]) {
			$shipping_rate = $table_cost[$i+1];
			break;
		}
	}
	if (MODULE_SHIPPING_DLY3_MODE == 'weight') {
		$shipping_rate = $shipping_rate * $shipping_num_boxes;
	}
	$this->quotes = array(	'id' => $this->code,
							'module' => MODULE_SHIPPING_DLY3_TEXT_TITLE,
							'methods' => array(array(	'id' => $this->code,
														'title' => MODULE_SHIPPING_DLY3_TEXT_WAY,
														'cost' =>  $shipping_rate)));
	if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title);
	if ($this->tax_class > 0) {
		$this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
	}
	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_DLY3_STATUS'");
		$this->_check = tep_db_num_rows($check_query);
	}
	return $this->_check;
}
  //<-- removed extra parts here
/** EOF Class**/

 

The goal of this code is to take a clients postal code say V5A4G8, strip it to V5A, and compare it to my shipping table.

However, for a reason I can't figure at :

if (in_array($order_postcode_2, $zipcodes0, true)){$shipping_costs = MODULE_SHIPPING_DLY3_COST0;}
elseif (in_array($order_postcode_2, $zipcodes1, true)){$shipping_costs = MODULE_SHIPPING_DLY3_COST1;}
elseif (in_array($order_postcode_2, $zipcodes2, true)){$shipping_costs = MODULE_SHIPPING_DLY3_COST2;}

 

the code returns: $shipping_costs = MODULE_SHIPPING_DLY3_COST2; every time.

 

For reference:

 

testing postcodes are: V5A2G2, V8A2G2, C1D2G2 and should return as follows: V5A = $50, V8A = $100, NOT V** = NULL(option not available)

 

thank you

 

taylorjes

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...