Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Free Shipping by Categories


Guest

Recommended Posts

This contribution works excellently, but there is a change I'd like to make & I'm not sure how to do it or if it's too complicated. In the shopping cart, when you've purchased an item with free shipping the text shows Free Shipping and then gives an extensive laundry list of all the categories & sub-categories which qualify for free shipping. What I'd like is for it to just show the products in the cart that qualify for free shipping (in case of a mixed cart).

 

I think the code is in store/includes/modules/shipping/freecats.php which I'm pasting below but I could be looking in the wrong place. Can someone PLEASE look at the code & help me make this change if it's possible?

 

TIA

 

 

 

<?php
/*
 $Id$ freeamount.php 2

 The Exchange Project - Community Made Shopping!
 [url="http://www.theexchangeproject.org"]http://www.theexchangeproject.org[/url]

 Copyright © 2003

 Released under the GNU General Public License

 ----------------------------------------------
 ane - 06/02/02 - modified freecount.php to
 allow for freeshipping on minimum order amount
 originally written by dwatkins 1/24/02
 Modified BearHappy 09/04/04
 Modified by Red Earth Design 01-22-2008
 Modified by Sethman to allow for minimum amount
 before customer qualifies for free shipping 08/11/2008
 ----------------------------------------------
*/

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

// class constructor
   function freecats() {
     global $order, $customer;

     $this->code = 'freecats';
     $this->title = MODULE_SHIPPING_FREECATS_TEXT_TITLE;
     $this->description = MODULE_SHIPPING_FREECATS_TEXT_DESCRIPTION;
     $this->sort_order = MODULE_SHIPPING_FREECATS_SORT_ORDER;
     $this->icon ='';
     $this->tax_class = MODULE_SHIPPING_FREECATS_TAX_CLASS;
     $this->enabled = ((MODULE_SHIPPING_FREECATS_STATUS == 'True') ? true : false);

		if (!tep_not_null(MODULE_SHIPPING_FREECATS_CATEGORIES))
		      $this->enabled = false;

     if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREECATS_ZONE > 0) ) {

       $check_flag = false;
       $check_query = tep_db_query("select zone_id, zone_country_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FREECATS_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
       $order_shipping_country = $order->delivery['country']['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']) {
//          } elseif ($check['zone_country_id'] == $order->delivery['country']['id']) {
           $check_flag = true;
           break;
         }
       }
       if ($check_flag == false) {
         $this->enabled = false;
       }
    }
}

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

		$get_total = false;
		$is_free = false;
		$get_weight = false;

		$cart_total = $cart->show_total();

		$cats_array = explode(',',MODULE_SHIPPING_FREECATS_CATEGORIES);
		$cat_names = '';


		for($i=0, $x=sizeof($cats_array); $i<$x; $i++){
		    $cats_array[$i] = (int)$cats_array[$i];
       		$cat_names .= tep_get_categories_name($cats_array[$i]).', ';
		}

		$cat_names = substr($cat_names, 0,-2);

		$pID_list = $cart->get_product_id_list();

		$pID_list = explode(',',$pID_list);
		for($i=0, $x=sizeof($pID_list); $i<$x; $i++){
	     	$pID_list[$i] = (int)$pID_list[$i];
		}
		$pID_list = implode(',',$pID_list);

		if(MODULE_SHIPPING_FREECATS_MIXEDCART=='Yes'){
			$free_count = 0;
			$free_weight = 0;
			$products = $cart->get_products();

			for($i=0, $x=sizeof($products); $i<$x; $i++){
				$check_query = tep_db_query('select * from '.TABLE_PRODUCTS_TO_CATEGORIES.' where categories_id in ('.implode(',',$cats_array).') and products_id="'.(int)$products[$i]['id'].'"');

				if (tep_db_num_rows($check_query)){
				  	$free_count++;
				  	$weight_query = tep_db_query('SELECT products_weight from '.TABLE_PRODUCTS.' WHERE products_id="'.(int)$products[$i]['id'].'"');
				  	$weight_result = tep_db_fetch_array($weight_query);

				  	$free_weight = $free_weight + ($weight_result['products_weight']*$products[$i]['quantity']);
				}
			}

			// If everything in the cart gets free shipping
			if($free_count==$x){
				$is_free = true;
			} else { // don't offer free shipping but subtract the weight of the item that gets free shipping
				$is_free = false;
				$cart->weight = $cart->weight-$free_weight; 
				$shipping_weight = $cart->weight;
			}
		} else {		
			if (MODULE_SHIPPING_FREECATS_ALL_OR_ONE == 'One'){
		      $products = $cart->get_products();
					for($i=0, $x=sizeof($products); $i<$x; $i++){
									$check_query = tep_db_query('select * from '.TABLE_PRODUCTS_TO_CATEGORIES.' where categories_id in ('.implode(',',$cats_array).') and products_id="'.(int)$products[$i]['id'].'"');
									$cart_total = $cart->show_total();
									if (tep_db_num_rows($check_query))
									  $is_free = true;
					}
		 	} elseif (MODULE_SHIPPING_FREECATS_ALL_OR_ONE == 'All'){
				$count = 0;
				for($i=0, $x=sizeof($cats_array); $i<$x; $i++){
									$check_query = tep_db_query('select * from '.TABLE_PRODUCTS_TO_CATEGORIES.' where categories_id="'.$cats_array[$i].'" and products_id in ('.$pID_list.')');
									if (tep_db_num_rows($check_query))
											$count++;
				}
				if ($count == sizeof($cats_array))
									  $is_free = true;
		 	} else {
		   		$this->enabled = false;
		   		return false;
		 	}

		 	if ( MODULE_SHIPPING_FREECATS_ONLY_OR_ANY == 'Only' ){
				$check_query = tep_db_query('select * from '.TABLE_PRODUCTS_TO_CATEGORIES.' where categories_id not in ('.MODULE_SHIPPING_FREECATS_CATEGORIES.') and products_id in ('.$pID_list.')');
			    if (tep_db_num_rows($check_query))
						  $is_free = false;
		 	}
		}

	  if (!$is_free) {
			if (MODULE_SHIPPING_FREECATS_DISPLAY == 'True'){
				 if (MODULE_SHIPPING_FREECATS_ALL_OR_ONE == 'One') {
				    if ( MODULE_SHIPPING_FREECATS_ONLY_OR_ANY == 'Only' )
							$this->quotes['error'] = '<b>'.MODULE_SHIPPING_FREECATS_TEXT_TITLE.'</b><br />'.sprintf(MODULE_SHIPPING_FREECATS_TEXT_ERROR_ONE_ONLY, $cat_names);
						else
							$this->quotes['error'] = '<b>'.MODULE_SHIPPING_FREECATS_TEXT_TITLE.'</b><br />'.sprintf(MODULE_SHIPPING_FREECATS_TEXT_ERROR_ONE_ANY, $cat_names);
				 } elseif (MODULE_SHIPPING_FREECATS_ALL_OR_ONE == 'All') {
				    if ( MODULE_SHIPPING_FREECATS_ONLY_OR_ANY == 'Only' )
							$this->quotes['error'] = '<b>'.MODULE_SHIPPING_FREECATS_TEXT_TITLE.'</b><br />'.sprintf(MODULE_SHIPPING_FREECATS_TEXT_ERROR_ALL_ONLY, $cat_names);
						else
							$this->quotes['error'] = '<b>'.MODULE_SHIPPING_FREECATS_TEXT_TITLE.'</b><br />'.sprintf(MODULE_SHIPPING_FREECATS_TEXT_ERROR_ONE_ANY, $cat_names);
				 }
		   }
    }

     	if ($shipping_weight > MODULE_SHIPPING_FREECATS_WEIGHT_MAX && MODULE_SHIPPING_FREECATS_WEIGHT_MAX > 0) {
		if (MODULE_SHIPPING_FREECATS_DISPLAY == 'True'){
		   	$this->quotes['error'] = '<b>'.MODULE_SHIPPING_FREECATS_TEXT_TITLE.'</b><br />
		   	  		'.sprintf(MODULE_SHIPPING_FREECATS_TEXT_TO_WEIGHT, $cat_names);

		}
		$get_weight = false;
	} else {
		$get_weight = true;
	}

	if ($cart_total < MODULE_SHIPPING_FREECATS_FREEAMOUNT && MODULE_SHIPPING_FREECATS_FREEAMOUNT > 0)
  {
	if (MODULE_SHIPPING_FREECATS_DISPLAY == 'True')
	   {
		$this->quotes['error'] = '<b>'.MODULE_SHIPPING_FREECATS_TEXT_TITLE.'</b><br />
		   	  		'.sprintf(MODULE_SHIPPING_FREECATS_FREEAMOUNT_TEXT_ERROR, MODULE_SHIPPING_FREECATS_FREEAMOUNT);
	   }
	$get_total = false;
   } else {
    $get_total = true;
   }		


	if (($is_free && $get_weight && $get_total)){

		$this->quotes = array('id' => $this->code,
											'module' => MODULE_SHIPPING_FREECATS_TEXT_TITLE,
											'methods' => array(array('id' => $this->code,
											'title' => sprintf(MODULE_SHIPPING_FREECATS_TEXT_WAY, $cat_names),
											'cost' => MODULE_SHIPPING_FREECATS_COST)));
		$title = '';
	}


     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_FREECATS_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 Free Shipping for certain categories', 'MODULE_SHIPPING_FREECATS_STATUS', 'False', 'Do you want to offer free shipping for certain categories?', '667', '7', '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 ('Maximum Weight', 'MODULE_SHIPPING_FREECATS_WEIGHT_MAX', '10', 'What is the maximum weight you will ship? (zero to turn off)', '667', '8', now())");
  tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Minimum Amount', 'MODULE_SHIPPING_FREECATS_FREEAMOUNT', '199', 'What is the minimum amount to qualify for free shipping? (zero to turn off)', '667', '8', now())");
     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 Display', 'MODULE_SHIPPING_FREECATS_DISPLAY', 'True', 'Do you want to display text if products from needed categories not purchased?', '667', '7', '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, use_function, set_function, date_added) values ('Categories List', 'MODULE_SHIPPING_FREECATS_CATEGORIES', '', 'For what categories do you want to offer free shipping?<br />NOTE! not recurcive - select all subcategories if you need it.', '667', '8', 'tep_cfg_show_multicategories', 'tep_cfg_select_multicategories(', now())");
     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 ('Deduct shipping weight if Mixed Cart', 'MODULE_SHIPPING_FREECATS_MIXEDCART', 'No', 'Free shipping if all products are in free categories. Also, if some products are and some are not, instead of free shpiping, it deducts the weight of the free shipping products so shipping is recalculated. <b>This overrides All/One & Only/Any options.</b>', '667', '6', 'tep_cfg_select_option(array(\'Yes\', \'No\'), ', now())");
     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 ('All or One', 'MODULE_SHIPPING_FREECATS_ALL_OR_ONE', 'All', 'Do you want to offer a free shipping for orders with products from all mentioned categories, or with at least from one of them?', '667', '7', 'tep_cfg_select_option(array(\'All\', \'One\'), ', now())");
     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 ('Only or Any', 'MODULE_SHIPPING_FREECATS_ONLY_OR_ANY', 'Only', 'Do you want to offer a free shipping for orders with products only from mentioned categories, or with products from any categories (including mentioned)?', '667', '7', 'tep_cfg_select_option(array(\'Only\', \'Any\'), ', 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_FREECATS_SORT_ORDER', '0', 'Sort order of display.', '667', '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 ('Shipping Zone', 'MODULE_SHIPPING_FREECATS_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '667', '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, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_FREECATS_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '667', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");
  }

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

  function keys() {
    $keys = array(
          'MODULE_SHIPPING_FREECATS_STATUS',
          'MODULE_SHIPPING_FREECATS_WEIGHT_MAX',
	   'MODULE_SHIPPING_FREECATS_FREEAMOUNT',
          'MODULE_SHIPPING_FREECATS_SORT_ORDER',
          'MODULE_SHIPPING_FREECATS_DISPLAY',
          'MODULE_SHIPPING_FREECATS_MIXEDCART',
          'MODULE_SHIPPING_FREECATS_ALL_OR_ONE',
          'MODULE_SHIPPING_FREECATS_ONLY_OR_ANY',
          'MODULE_SHIPPING_FREECATS_CATEGORIES',
          'MODULE_SHIPPING_FREECATS_ZONE',
          'MODULE_SHIPPING_FREECATS_TAX_CLASS'
          );
    return $keys;
  }
}
?>

Edited by charinlasvegas
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...