Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Multiple Individual Product Shipping Rate


oldschoo

Recommended Posts

I am trying to modify the Individual Product Shipping Rate to allow four different levels of Individual Product Shipping Rates.

 

I Think the files I need to change are:

 

catalog/admin/categories.php

catalog/includes/classes/shipping.php

catalog/includes/classes/shopping_cart.php

catalog/product_info.php

 

 

and update the database to include product_ship_price_three and product_ship_price_four

 

I am working on catalog/includes/classes/shipping.php

 

This part of the code I need help with please:

original code

	//start indvship
function get_shiptotal() {
  global $cart, $order;
  $this->shiptotal = '';
  $products = $cart->get_products();
  for ($i=0, $n=sizeof($products); $i<$n; $i++) {
	if (tep_not_null($products[$i]['products_ship_price'])) {
	  $products_ship_price = $products[$i]['products_ship_price'];
	  $products_ship_price_two = $products[$i]['products_ship_price_two'];
	  $products_ship_zip = $products[$i]['products_ship_zip'];
	  $qty = $products[$i]['quantity'];
	  if(tep_not_null($products_ship_price) ||tep_not_null($products_ship_price_two)){
		$this->shiptotal += ($products_ship_price);
		if ($qty > 1) {
		  if (tep_not_null($products_ship_price_two)) {
			$this->shiptotal += ($products_ship_price_two * ($qty-1));
		  } else {
			$this->shiptotal += ($products_ship_price * ($qty-1));
		  }
		}/////////////NOT HERE <<------------
	  }
	}
  }// CHECK TO SEE IF SHIPPING TO HOME COUNTRY, IF NOT INCREASE SHIPPING COSTS BY AMOUNT SET IN ADMIN/////////////move back here <<------------
  if (($order->delivery['country']['id']) != INDIVIDUAL_SHIP_HOME_COUNTRY) {
	if(INDIVIDUAL_SHIP_INCREASE > '0' || $this->shiptotal > '0') {
	  $this->shiptotal *= INDIVIDUAL_SHIP_INCREASE;
	} else {
	  $this->shiptotal += INDIVIDUAL_SHIP_INCREASE *  $this->get_indvcount();
	}
	return $this->shiptotal;
	// not sure why this is needed, but it now works correctly for home country - by Ed
  } else {
	   $this->shiptotal *= 1;
	 return $this->shiptotal;
  }
}

function get_indvcount() {
  global $cart;
  $this->indvcount = '';
  $products = $cart->get_products();
  for ($i=0, $n=sizeof($products); $i<$n; $i++) {
	if (tep_not_null($products[$i]['products_ship_price'])) {
	  $products_ship_price = $products[$i]['products_ship_price'];//}
	  $products_ship_price_two = $products[$i]['products_ship_price_two'];
	  if(is_numeric($products_ship_price)){
		$this->indvcount += '1';
	  }
	}
  }
  return $this->indvcount;
}

// end indvship

 

I have modified this muchc so far:

	//start indvship
function get_shiptotal() {
  global $cart, $order;
  $this->shiptotal = '';
  $products = $cart->get_products();
  for ($i=0, $n=sizeof($products); $i<$n; $i++) {
	if (tep_not_null($products[$i]['products_ship_price'])) {
	  $products_ship_price = $products[$i]['products_ship_price'];
	  $products_ship_price_two = $products[$i]['products_ship_price_two'];
	  $products_ship_price_three = $products[$i]['products_ship_price_three'];		  
	  $products_ship_price_four = $products[$i]['products_ship_price_four'];		  
	  $products_ship_zip = $products[$i]['products_ship_zip'];
	  $qty = $products[$i]['quantity'];
	  if(tep_not_null($products_ship_price) ||tep_not_null($products_ship_price_two) ||tep_not_null($products_ship_price_three)||tep_not_null($products_ship_price_four)){
		$this->shiptotal += ($products_ship_price);
		if ($qty = 2) {
		  if (tep_not_null($products_ship_price_two)) {
			$this->shiptotal += ($products_ship_price_two);
		} elseif ($qty = 3) {
		  if (tep_not_null($products_ship_price_three)) {
			$this->shiptotal += ($products_ship_price_two) += ($products_ship_price_three);
		} elseif ($qty > 3) {
		  if (tep_not_null($products_ship_price_four)) {
			$this->shiptotal += ($products_ship_price_two) += ($products_ship_price_three) += ($products_ship_price_four * ($qty-1));					
		  } else {
			$this->shiptotal += ($products_ship_price * ($qty-1));
		  }
		}/////////////NOT HERE <<------------
	  }
	}
  }// CHECK TO SEE IF SHIPPING TO HOME COUNTRY, IF NOT INCREASE SHIPPING COSTS BY AMOUNT SET IN ADMIN/////////////move back here <<------------
  if (($order->delivery['country']['id']) != INDIVIDUAL_SHIP_HOME_COUNTRY) {
	if(INDIVIDUAL_SHIP_INCREASE > '0' || $this->shiptotal > '0') {
	  $this->shiptotal *= INDIVIDUAL_SHIP_INCREASE;
	} else {
	  $this->shiptotal += INDIVIDUAL_SHIP_INCREASE *  $this->get_indvcount();
	}
	return $this->shiptotal;
	// not sure why this is needed, but it now works correctly for home country - by Ed
  } else {
	   $this->shiptotal *= 1;
	 return $this->shiptotal;
  }
}

function get_indvcount() {
  global $cart;
  $this->indvcount = '';
  $products = $cart->get_products();
  for ($i=0, $n=sizeof($products); $i<$n; $i++) {
	if (tep_not_null($products[$i]['products_ship_price'])) {
	  $products_ship_price = $products[$i]['products_ship_price'];//}
	  $products_ship_price_two = $products[$i]['products_ship_price_two'];
	  $products_ship_price_three = $products[$i]['products_ship_price_three'];
	  $products_ship_price_four = $products[$i]['products_ship_price_four'];					
	  if(is_numeric($products_ship_price)){
		$this->indvcount += '1';
	  }
	}
  }
  return $this->indvcount;
}

// end indvship

 

Does this look correct? I have a live shop and don't want to screw up a working shop.

Link to comment
Share on other sites

Now in this file:

 

catalog/product_info.php

 

I can't figure out this part of the code:

original code

	 // start indvship
$extra_shipping_query = tep_db_query("select products_ship_price, products_ship_price_two from " . TABLE_PRODUCTS_SHIPPING . " where products_id = '" . (int)$products_id . "'");
if (tep_db_num_rows($extra_shipping_query)) {
  $extra_shipping = tep_db_fetch_array($extra_shipping_query);
  if($extra_shipping['products_ship_price'] == '0.00'){
	echo '<i>(Free Shipping for this Item)</i>';
  } else {
	echo '<i>(This item requires additional shipping of $' . $extra_shipping['products_ship_price'];
	if (($extra_shipping['products_ship_price_two']) > 0) {
	  echo ' for the first item, and $' . $extra_shipping['products_ship_price_two'] . ' for each additional item + regular shipping costs.)</i>';
	} else {
	  echo ' + regular shipping costs.)</i>';
	}
  }
}
// end indvship

 

What I have figured out so far:

	 // start indvship
$extra_shipping_query = tep_db_query("select products_ship_price, products_ship_price_two, products_ship_price_three, products_ship_price_four from " . TABLE_PRODUCTS_SHIPPING . " where products_id = '" . (int)$products_id . "'");
if (tep_db_num_rows($extra_shipping_query)) {
  $extra_shipping = tep_db_fetch_array($extra_shipping_query);
  if($extra_shipping['products_ship_price'] == '0.00'){
	echo '<i>(Free Shipping for this Item)</i>';
  } else {
	echo '<i>(This item requires additional shipping of $' . $extra_shipping['products_ship_price'];
	if (($extra_shipping['products_ship_price_two']) > 0) {
	  echo ' for the first item, and $' . $extra_shipping['products_ship_price_two'] . ' for each additional item + regular shipping costs.)</i>';
	} else {
	  echo ' + regular shipping costs.)</i>';
	}
  }
}
// end indvship

 

Thank you to anyone that can help!

Link to comment
Share on other sites

For catalog/admin/categories

 

original code

		 // start indvship
	  $sql_shipping_array = array('products_ship_zip' => tep_db_prepare_input($_POST['products_ship_zip']),
'products_ship_methods_id' => tep_db_prepare_input($_POST['products_ship_methods_id']),
'products_ship_price' => round(tep_db_prepare_input($_POST['products_ship_price']),4),
'products_ship_price_two' => round(tep_db_prepare_input($_POST['products_ship_price_two']),4));
	  $sql_shipping_id_array = array('products_id' => (int)$products_id); 
	  $products_ship_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_SHIPPING . " WHERE products_id = " . (int)$products_id);
	  if(tep_db_num_rows($products_ship_query) >0) {
		if (($_POST['products_ship_zip'] == '')&&($_POST['products_ship_methods_id'] == '')&&($_POST['products_ship_price'] == '')&&($_POST['products_ship_price_two'] == '')){
		  tep_db_query("DELETE FROM " . TABLE_PRODUCTS_SHIPPING . " where products_id = '" . (int)$products_id . "'");
		} else {
		  tep_db_perform(TABLE_PRODUCTS_SHIPPING, $sql_shipping_array, 'update', "products_id = '" . (int)$products_id . "'");
		}
	  } else {
		if (($_POST['products_ship_zip'] != '')||($_POST['products_ship_methods_id'] != '')||($_POST['products_ship_price'] != '')||($_POST['products_ship_price_two'] != '')){
		  $sql_ship_array = array_merge($sql_shipping_array, $sql_shipping_id_array);
		  tep_db_perform(TABLE_PRODUCTS_SHIPPING, $sql_ship_array, 'insert');
		}
	  }
	  // end indvship

 

changed to this:

		   // start indvship
	  $sql_shipping_array = array('products_ship_zip' => tep_db_prepare_input($_POST['products_ship_zip']),
'products_ship_methods_id' => tep_db_prepare_input($_POST['products_ship_methods_id']),
'products_ship_price' => round(tep_db_prepare_input($_POST['products_ship_price']),4),
'products_ship_price_two' => round(tep_db_prepare_input($_POST['products_ship_price_two']),4),
'products_ship_price_three' => round(tep_db_prepare_input($_POST['products_ship_price_three']),4),
'products_ship_price_four' => round(tep_db_prepare_input($_POST['products_ship_price_four']),4));
	  $sql_shipping_id_array = array('products_id' => (int)$products_id); 
	  $products_ship_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_SHIPPING . " WHERE products_id = " . (int)$products_id);
	  if(tep_db_num_rows($products_ship_query) >0) {
		if (($_POST['products_ship_zip'] == '')&&($_POST['products_ship_methods_id'] == '')&&($_POST['products_ship_price'] == '')&&($_POST['products_ship_price_two'] == '')&&($_POST['products_ship_price_three'] == '')&&($_POST['products_ship_price_four'] == '')){
		  tep_db_query("DELETE FROM " . TABLE_PRODUCTS_SHIPPING . " where products_id = '" . (int)$products_id . "'");
		} else {
		  tep_db_perform(TABLE_PRODUCTS_SHIPPING, $sql_shipping_array, 'update', "products_id = '" . (int)$products_id . "'");
		}
	  } else {
		if (($_POST['products_ship_zip'] != '')||($_POST['products_ship_methods_id'] != '')||($_POST['products_ship_price'] != '')||($_POST['products_ship_price_two'] != '')||($_POST['products_ship_price_three'] != '')||($_POST['products_ship_price_four'] != '')){
		  $sql_ship_array = array_merge($sql_shipping_array, $sql_shipping_id_array);
		  tep_db_perform(TABLE_PRODUCTS_SHIPPING, $sql_ship_array, 'insert');
		}
	  }
	  // end indvship

 

and then this part - original

	   // start indvship
  $products_shipping_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_SHIPPING . " WHERE products_id=" . (int)$_GET['pID']);
  while ($products_shipping = tep_db_fetch_array($products_shipping_query)) {
	$products_ship_zip = $products_shipping['products_ship_zip'];
	$products_ship_methods_id = $products_shipping['products_ship_methods_id'];
	$products_ship_price = $products_shipping['products_ship_price'];
	$products_ship_price_two = $products_shipping['products_ship_price_two'];
  }
  $shipping=array('products_ship_methods_id' => $products_ship_methods_id,
  'products_ship_zip' => $products_ship_zip,
  'products_ship_price' => $products_ship_price,
  'products_ship_price_two' => $products_ship_price_two);
  $pInfo->objectInfo($shipping);
  // end indvship

 

and changed to this

	  // start indvship
  $products_shipping_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_SHIPPING . " WHERE products_id=" . (int)$_GET['pID']);
  while ($products_shipping = tep_db_fetch_array($products_shipping_query)) {
	$products_ship_zip = $products_shipping['products_ship_zip'];
	$products_ship_methods_id = $products_shipping['products_ship_methods_id'];
	$products_ship_price = $products_shipping['products_ship_price'];
	$products_ship_price_two = $products_shipping['products_ship_price_two'];
	$products_ship_price_three = $products_shipping['products_ship_price_three'];		
	$products_ship_price_four = $products_shipping['products_ship_price_four'];		
  }
  $shipping=array('products_ship_methods_id' => $products_ship_methods_id,
  'products_ship_zip' => $products_ship_zip,
  'products_ship_price' => $products_ship_price,
  'products_ship_price_two' => $products_ship_price_two,	  
  'products_ship_price_three' => $products_ship_price_three,	  
  'products_ship_price_four' => $products_ship_price_four);
  $pInfo->objectInfo($shipping);
  // end indvship

 

and then this part - original

		  <?php // start indvship ?> <!-- Zipcode -->
	  <tr bgcolor="#ebebff">
		<td class="main"><?php echo TEXT_PRODUCTS_ZIPCODE; ?></td>
		<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_ship_zip', $pInfo->products_ship_zip); if(tep_not_null($pInfo->products_ship_zip)) echo 'notnull'; else echo 'null'; ?></td>
	  </tr> <!-- end Zipcode --> <!-- Indvship -->
	  <tr bgcolor="#ebebff">
		<td class="main"><?php echo 'Indv. Shipping Price:'; ?></td>
		<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_ship_price', $pInfo->products_ship_price); if(tep_not_null($pInfo->products_ship_price)) echo 'notnull'; else echo 'null'; ?></td>
	  </tr>
	  <tr bgcolor="#ebebff">
		<td class="main"><?php echo 'Each Additional Price:'; ?></td>
		<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_ship_price_two', $pInfo->products_ship_price_two); if(tep_not_null($pInfo->products_ship_price_two)) echo 'notnull'; else echo 'null'; ?></td>
	  </tr> <!-- end Indvship -->
	  <tr>
		<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
	  </tr>
	  <?php // end indvship ?>

 

and changed to this

		  <?php // start indvship ?> <!-- Zipcode -->
	  <tr bgcolor="#ebebff">
		<td class="main"><?php echo TEXT_PRODUCTS_ZIPCODE; ?></td>
		<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_ship_zip', $pInfo->products_ship_zip); if(tep_not_null($pInfo->products_ship_zip)) echo 'notnull'; else echo 'null'; ?></td>
	  </tr> <!-- end Zipcode --> <!-- Indvship -->
	  <tr bgcolor="#ebebff">
		<td class="main"><?php echo 'Indv. Shipping Price 1:'; ?></td>
		<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_ship_price', $pInfo->products_ship_price); if(tep_not_null($pInfo->products_ship_price)) echo 'notnull'; else echo 'null'; ?></td>
	  </tr>
	  <tr bgcolor="#ebebff">
		<td class="main"><?php echo 'Indv. Shipping Price 2:'; ?></td>
		<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_ship_price_two', $pInfo->products_ship_price_two); if(tep_not_null($pInfo->products_ship_price_two)) echo 'notnull'; else echo 'null'; ?></td>
	  </tr>
	  <tr bgcolor="#ebebff">
		<td class="main"><?php echo 'Indv. Shipping Price 3:'; ?></td>
		<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_ship_price_three', $pInfo->products_ship_price_three); if(tep_not_null($pInfo->products_ship_price_three)) echo 'notnull'; else echo 'null'; ?></td>
	  </tr>					
	  <tr bgcolor="#ebebff">
		<td class="main"><?php echo 'Each Additional Price:'; ?></td>
		<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('products_ship_price_four', $pInfo->products_ship_price_four); if(tep_not_null($pInfo->products_ship_price_four)) echo 'notnull'; else echo 'null'; ?></td>
	  </tr> <!-- end Indvship -->
	  <tr>
		<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
	  </tr>
	  <?php // end indvship ?>

 

and then this original code

 	  // start indvship
  $products_shipping_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_SHIPPING . " WHERE products_id=" . (int)$_GET['pID']);
  while ($products_shipping = tep_db_fetch_array($products_shipping_query)) {
	$products_ship_methods_id = $products_shipping['products_ship_methods_id'];
	$products_ship_zip = $products_shipping['products_ship_zip'];
	$products_ship_price = $products_shipping['products_ship_price'];
	$products_ship_price_two = $products_shipping['products_ship_price_two'];
  }
  $shipping=array('products_ship_methods_id' => $products_ship_methods_id,
  'products_ship_zip' => $products_ship_zip,
  'products_ship_price' => $products_ship_price,
  'products_ship_price_two' => $products_ship_price_two);
  $pInfo->objectInfo($shipping);
  // end indvship

 

and chaned to this:

	  // start indvship
  $products_shipping_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_SHIPPING . " WHERE products_id=" . (int)$_GET['pID']);
  while ($products_shipping = tep_db_fetch_array($products_shipping_query)) {
	$products_ship_methods_id = $products_shipping['products_ship_methods_id'];
	$products_ship_zip = $products_shipping['products_ship_zip'];
	$products_ship_price = $products_shipping['products_ship_price'];
	$products_ship_price_two = $products_shipping['products_ship_price_two'];
	$products_ship_price_three = $products_shipping['products_ship_price_three'];
	$products_ship_price_four = $products_shipping['products_ship_price_four'];				
  }
  $shipping=array('products_ship_methods_id' => $products_ship_methods_id,
  'products_ship_zip' => $products_ship_zip,
  'products_ship_price' => $products_ship_price,
  'products_ship_price_two' => $products_ship_price_two,
  'products_ship_price_three' => $products_ship_price_three,			
  'products_ship_price_four' => $products_ship_price_four);
  $pInfo->objectInfo($shipping);
  // end indvship

 

How do these chanes look?

Link to comment
Share on other sites

For file: catalog/includes/classes/shopping_cart.php

 

original code

		  // start indvship
	  $products_shipping_query = tep_db_query("select products_ship_price, products_ship_price_two, products_ship_zip, products_ship_methods_id from " . TABLE_PRODUCTS_SHIPPING . " where products_id = '" . $products['products_id'] . "'");
	  $products_shipping = tep_db_fetch_array($products_shipping_query);
	  // end indvship

 

and changed to:

		  // start indvship
	  $products_shipping_query = tep_db_query("select products_ship_price, products_ship_price_two, products_ship_price_three, products_ship_price_four, products_ship_zip, products_ship_methods_id from " . TABLE_PRODUCTS_SHIPPING . " where products_id = '" . $products['products_id'] . "'");
	  $products_shipping = tep_db_fetch_array($products_shipping_query);
	  // end indvship

 

and this original ccode

// start indvship

'products_ship_price' => $products_shipping['products_ship_price'],

'products_ship_price_two' => $products_shipping['products_ship_price_two'],

'products_ship_zip' => $products_shipping['products_ship_zip'],

// end indvship

[/code]

 

and changed to:

// start indvship
'products_ship_price' => $products_shipping['products_ship_price'],
'products_ship_price_two' => $products_shipping['products_ship_price_two'],
'products_ship_price_three' => $products_shipping['products_ship_price_three'],									
'products_ship_price_four' => $products_shipping['products_ship_price_four'],									
'products_ship_zip' => $products_shipping['products_ship_zip'],
// end  indvship

 

How do these changes look?

Link to comment
Share on other sites

  • 5 weeks later...

I have almost got this working, thanks to steve_s for all his help.

 

I am stuck on the includes/classes/shipping.php file. I show the four levels in admin, products, the four different shipping prices are stored in the database, so the admin part is working correctly.

 

I need the shipping charges to be:

1st item: $ x.xx (charge for first item)

2nd item: $ x.xx (charge for second item)

3rd item: $ x.xx (charge for third item)

4th item: $x.xx (charge for the fourth item and beyond)

 

So, If someone purchased 5 items, they would pay: 1st item ship + 2nd item ship + 3rd item ship + 4th item ship + 4th item ship.

 

This is the part I am having problems with:

//start indvship

function get_shiptotal() {

global $cart, $order;

$this->shiptotal = '';

$products = $cart->get_products();

for ($i=0, $n=sizeof($products); $i<$n; $i++) {

if (tep_not_null($products[$i]['products_ship_price'])) {

$products_ship_price = $products[$i]['products_ship_price'];

$products_ship_price_two = $products[$i]['products_ship_price_two'];

$products_ship_price_three = $products[$i]['products_ship_price_three'];

$products_ship_price_four = $products[$i]['products_ship_price_four'];

$products_ship_zip = $products[$i]['products_ship_zip'];

$qty = $products[$i]['quantity'];

if(tep_not_null($products_ship_price) ||tep_not_null($products_ship_price_two)){

$this->shiptotal += ($products_ship_price);

if ($qty > 1) {

if (tep_not_null($products_ship_price_two)) {

$this->shiptotal += ($products_ship_price_two * ($qty-1));

} else {

if(tep_not_null($products_ship_price) ||tep_not_null($products_ship_price_three)){

$this->shiptotal += ($products_ship_price);

if ($qty > 2) {

if (tep_not_null($products_ship_price_three)) {

$this->shiptotal += ($products_ship_price_three * ($qty-1));

} else {

if(tep_not_null($products_ship_price) ||tep_not_null($products_ship_price_four)){

$this->shiptotal += ($products_ship_price);

if ($qty > 3) {

if (tep_not_null($products_ship_price_four)) {

$this->shiptotal += ($products_ship_price_four * ($qty-1));

} else {

$this->shiptotal += ($products_ship_price * ($qty-1));

}

}/////////////NOT HERE <<------------

}

}

}

}

}

}

}

}

[\code]

 

The above code is figuring the shipping for each item over 1 at the 2nd item ship.

 

Thank you for any help

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.

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...