Jump to content
Sign in to follow this  
jbhz_finisher

If Item ID xxxxx Is In Cart Charge xx Amount For Shipping

Recommended Posts

Im looking for code that will help in a product campaign. Im offering a product free customers only pay shipping. I need this code to work for only 1 particular product and not affect the whole store.

 

So some thing like:

 

If product id xxxx is in cart show and allow "First class mail $4.95" as well as normal shipping options.

 

Else, do not show special shipping option above and resume normal shipping options.

 

Any ideas for how I could implement this function?

 

Thanks in advance.

Share this post


Link to post
Share on other sites

This is urgent, So $20 Via Paypal to first person that can code this simple function! Its needed function has changed see below.

 

Im looking for code that will help in a product campaign. Im offering a product free customers only pay shipping. I need this code to work for only 1 particular product and not affect the whole store.

 

So some thing like:

 

If product id xxxx is in cart by ITS SELF show and allow "First class mail $4.95" only.

 

If other products are added to cart along with special offer product show normal shipping options only.

 

Any Takers?

Edited by jbhz_finisher

Share this post


Link to post
Share on other sites

Michael,

 

If it was a simple function, you would have received an answer the first time you posted this request. What you ask would require the addition of either a new table or a new field within the product table, then you would require a new conditional query to compare the flagged product to the shipping data which would then have to be carried to the 4 checkout files. So, to recap what you want is NO simple code.

 

 

 

Chris

 

ps. Your monetary offer is not even 20 minutes of coding time.


:|: Was this post helpful ? Click the LIKE THIS button :|:

 

See my Profile to learn more about add ons, templates, support plans and custom coding (click here)

Share this post


Link to post
Share on other sites

Ok im thinking it would be easy to simply modify an existing shipping module. I will use the "Per Item" since im not using it right now and i can set a shipping amount in admin $4.95.

How can i tell this module to show its self when item number "21564" only is in shopping cart and hide when other products are in cart?

Here is code for shipping module.

 

<?php
/*
 $Id$

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2008 osCommerce

 Released under the GNU General Public License
*/

 class item {
var $code, $title, $description, $icon, $enabled;

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

 	$this->code = 'item';
 	$this->title = MODULE_SHIPPING_ITEM_TEXT_TITLE;
 	$this->description = MODULE_SHIPPING_ITEM_TEXT_DESCRIPTION;
 	$this->sort_order = MODULE_SHIPPING_ITEM_SORT_ORDER;
 	$this->icon = '';
 	$this->tax_class = MODULE_SHIPPING_ITEM_TAX_CLASS;
 	$this->enabled = ((MODULE_SHIPPING_ITEM_STATUS == 'True') ? true : false);

 	if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_ITEM_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_ITEM_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;

 	$number_of_items = $this->getNumberOfItems();

 	$this->quotes = array('id' => $this->code,
                       	'module' => MODULE_SHIPPING_ITEM_TEXT_TITLE,
                       	'methods' => array(array('id' => $this->code,
                                                	'title' => MODULE_SHIPPING_ITEM_TEXT_WAY,
                                                	'cost' => (MODULE_SHIPPING_ITEM_COST * $number_of_items) + MODULE_SHIPPING_ITEM_HANDLING)));

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

 	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_ITEM_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 Item Shipping', 'MODULE_SHIPPING_ITEM_STATUS', 'True', 'Do you want to offer per item rate 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 ('Shipping Cost', 'MODULE_SHIPPING_ITEM_COST', '2.50', 'The shipping cost will be multiplied by the number of items in an order that uses this shipping method.', '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 Fee', 'MODULE_SHIPPING_ITEM_HANDLING', '0', 'Handling fee for this shipping method.', '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_ITEM_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_ITEM_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_ITEM_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_ITEM_STATUS', 'MODULE_SHIPPING_ITEM_COST', 'MODULE_SHIPPING_ITEM_HANDLING', 'MODULE_SHIPPING_ITEM_TAX_CLASS', 'MODULE_SHIPPING_ITEM_ZONE', 'MODULE_SHIPPING_ITEM_SORT_ORDER');
}

function getNumberOfItems() {
 	global $order, $total_count;

 	$number_of_items = $total_count;

 	if ($order->content_type == 'mixed') {
   	$number_of_items = 0;

   	for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
     	$number_of_items += $order->products[$i]['qty'];

     	if (isset($order->products[$i]['attributes'])) {
       	reset($order->products[$i]['attributes']);
       	while (list($option, $value) = each($order->products[$i]['attributes'])) {
         	$virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$order->products[$i]['id'] . "' and pa.options_values_id = '" . (int)$value['value_id'] . "' and pa.products_attributes_id = pad.products_attributes_id");
         	$virtual_check = tep_db_fetch_array($virtual_check_query);

         	if ($virtual_check['total'] > 0) {
           	$number_of_items -= $order->products[$i]['qty'];
         	}
       	}
     	}
   	}
 	}

 	return $number_of_items;
}
 }
?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×