Jump to content
Sign in to follow this  
cjwood555

Some mods I've written...

Recommended Posts

Hi guys,

 

I'm moving our shop over to Drupal & Ubercart - after spending a long time adding to / changing oscommerce to get it do, I've come to the conclusion that it will just get more and more awkward to maintain as time goes by. Therefore, I am happy to give away the mods/contribs I've written. They are not necessarily complete but do work and will not be supported. Posts to follow.

 

Regards,

Chris

 

N.B. all code is provided with any form of warantee express or implied. you are responsible for ensuring that you have taken any and all necessary measures to restore your installation to the state it was in previous to implementing this code. Neither I nor Gear 7 ltd accept any responsibility for loss or damages directly or indirectly consequential to the use of this code.

Edited by cjwood555

Share this post


Link to post
Share on other sites

Product availability:

Enables you to set products as 'buy online', 'see pricing - call to order' or 'poa'/'call for pricing'.

Also includes a quantity box with jQuery spin control next to the add-to-cart button.

 

 

In phpmyadmin or similar:

--
-- Table structure for table `products_availability`
--

DROP TABLE IF EXISTS `products_availability`;
CREATE TABLE IF NOT EXISTS `products_availability` (
 `products_availability_id` tinyint(4) NOT NULL,
 `products_availability_label` text NOT NULL,
 `buy_online` tinyint(1) NOT NULL,
 `preorder_online` tinyint(1) NOT NULL,
 `see_pricing` tinyint(1) NOT NULL,
 `call_to_order` tinyint(1) NOT NULL,
 `call_for_pricing` tinyint(1) NOT NULL,
 PRIMARY KEY  (`products_availability_id`),
 UNIQUE KEY `products_availability_id` (`products_availability_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `products_availability`
--

INSERT INTO `products_availability` (`products_availability_id`, `products_availability_label`, `buy_online`, `preorder_online`, `see_pricing`, `call_to_order`, `call_for_pricing`) VALUES
(1, 'Purchase Online', 1, 0, 1, 0, 0),
(2, 'See Pricing, Call To Order', 0, 0, 1, 1, 0),
(3, 'POA', 0, 0, 0, 0, 1),
(0, 'Default', 1, 0, 1, 0, 0);

 

 

In /product_info.php:

 

For each product $query

$query .= "p.products_availability_id";

 

~Line 153 change:

echo $currencies->format($pInfo->products_price)

 

to:

 

//Begin Availability echo $currencies->format($pInfo->products_price);
$products_availability_id = array();
$products_availability_id_query = tep_db_query("select products_availability_id from " . TABLE_PRODUCTS . " where products_id=" . (int)$HTTP_GET_VARS['products_id']);
$a = tep_db_fetch_array($products_availability_id_query);
$products_availability_id = array('id' => $a['products_availability_id']);

$products_availability = array();
$products_availability_query = tep_db_query("select products_availability_id, see_pricing, call_for_pricing, buy_online from " . TABLE_PRODUCTS_AVAILABILITY . " where products_availability_id =" . $products_availability_id['id']);
$a = tep_db_fetch_array($products_availability_query);
$products_availability = array('id' => $a['products_availability_id'], 'see_pricing' => $a['see_pricing'], 							'call_for_pricing' => $a['call_for_pricing'], 'buy_online' => $a['buy_online']);

if ($products_availability['see_pricing'] == 1) {
    if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
		$products_price = '<s>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
	} else {
	    $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));
	}
	if ($products_availability['buy_online'] == '0') {
		$products_price .= " - " . TEXT_CALL_TO_ORDER;
	}
} else if ($products_availability['call_for_pricing'] == 1) {
	$products_price = TEXT_CALL_FOR_PRICING;
} else {
	$products_price = TEXT_PRICING_NOT_AVAILABLE;
}

// End Availability

 

Shortly after that you shoudl come across:

 

echo '<h1>'.$products_price.'</h1>'
tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART);

 

change it to:

 

		<?php echo '<h1>'.$products_price.'</h1>';
		//Begin Availability 
		$products_availability_id = array();
		$products_availability_id_query = tep_db_query("select products_availability_id from " . TABLE_PRODUCTS . " where products_id=" . (int)$HTTP_GET_VARS['products_id']);
		$a = tep_db_fetch_array($products_availability_id_query);
		$products_availability_id = array('id' => $a['products_availability_id']);

		$products_availability = array();
		$products_availability_query = tep_db_query("select products_availability_id, buy_online from " . TABLE_PRODUCTS_AVAILABILITY . " where products_availability_id=" . $products_availability_id['id']);

		$a = tep_db_fetch_array($products_availability_query);
		$products_availability = array('id' => $a['products_availability_id'], 'buy_online' => $a['buy_online']);

		if ($products_availability['buy_online'] == 1) {
//				echo '<td valign="top" align="left">' . $products_model . '</td>'; 
			echo '<br />';
			echo '<span>';
			echo '<script language="javascript" type="text/javascript">' . PHP_EOL;
			echo '$(document).ready(function(){' . PHP_EOL;
			echo '  $(\'#quantity\').spin({max:10,min:1});' . PHP_EOL;
			echo '});' . PHP_EOL;
			echo '</script>' . PHP_EOL;
			echo TEXT_ENTER_QUANTITY . tep_draw_input_field('quantity', '1', 'size="3" id="quantity" style="height: 18px; line-height: 18px;"');
			echo '</span>';
//				echo '<span style="position: relative;">';
//				echo '<img src="/images/icon_plus.gif" style="position: relative; top: -6px;" onClick="javascript:changeValue(document.cart_quantity.quantity,1);return false;">';
//				echo '<img src="/images/icon_minus.gif" style="position: relative; top: 6px; left: -10px;" onClick="javascript:changeValue(document.cart_quantity.quantity,-1);return false;">';
//				echo '</span>';

			echo '<script language="javascript">';
			echo 'function changeValue(textObject,delta){';
			echo 'var myVal = parseInt(textObject.value);';
			echo '   if (myVal == NaN) {';
			echo '      myVal = 1;';
			echo '   } else {';
			echo '   myVal = myVal + delta;';
			echo '   }';
			echo '/* check that value is not negative */';
			echo 'if (myVal < 1) {';
			echo '   myVal = 1;';
			echo '   }';
			echo 'textObject.value = myVal;';
			echo 'return;';
			echo '}';
			echo '</script>';
			echo '<br />';
			echo '<br />';				

			echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART);
		}				
		// End Availability	

 

 

 

 

 

In /admin/categories.php:

 

Line 300 $sql_data_array insert this before end of array:

'products_availability_id' => (int)tep_db_prepare_input($HTTP_POST_VARS['products_availability_id'])

 

Line 449 $product_query = tep_db_query insert this before end of select:

, 'products_availability_id'

 

Line 454 tep_db_query insert this before end of query:

$product['products_availability_id']

 

Line 603 $parameters.... add this before end of array:

					   'products_availability_id' => ''

 

Line 640 $query=.... add this before end of select:

,  p.products_availability_id

 

Before line 674 ( $manufacturers_array = array(array('id' => '', 'text' => TEXT_NONE));) add:

//begin Availability
   $products_availability_array = array(array('id' => '', 'text' => TEXT_NONE));
   $products_availability_query = tep_db_query("select products_availability_id, products_availability_label from " . TABLE_PRODUCTS_AVAILABILITY . " order by products_availability_id");
   while ($products_availability = tep_db_fetch_array($products_availability_query)) {
     $products_availability_array[] = array('id' => $products_availability['products_availability_id'],
                                    'text' => $products_availability['products_availability_label']);
   }
//end Availability

 

Find:

          <tr>
           <td class="main"><?php echo TEXT_PRODUCTS_DATE_AVAILABLE; ?><br><small>(YYYY-MM-DD)</small></td>

 

add before it:

          <?php //Begin Availability ?>
         <tr>
           <td class="main"><?php echo TEXT_PRODUCTS_AVAILABILITY; ?></td>
           <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_pull_down_menu('products_availability_id', $products_availability_array, $pInfo->products_availability_id); ?></td>
         </tr>
         <?php //End Availability ?>
         <tr>
           <td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
         </tr>

 

Line 1053 $query=... add before end of select:

, p.products_availability_id

 

Line 1105 echo $currencies->format($pInfo->products_price); change to:

           	<?php //Begin Availability echo $currencies->format($pInfo->products_price);
			    $products_availability = array();
				$products_availability_query = tep_db_query("select products_availability_id, see_pricing, call_for_pricing, buy_online from " . TABLE_PRODUCTS_AVAILABILITY . " where products_availability_id =" . (int)$pInfo->products_availability_id);

				$a = tep_db_fetch_array($products_availability_query);
				$products_availability = array('id' => $a['products_availability_id'], 'see_pricing' => $a['see_pricing'], 							'call_for_pricing' => $a['call_for_pricing'], 'buy_online' => $a['buy_online']);

				if ($products_availability['see_pricing'] == 1) {
					$products_price = $currencies->format($pInfo->products_price);
					if ($products_availability['buy_online'] == '0') {
						$products_price .= " - " . TEXT_CALL_TO_ORDER;
					}
					echo $products_price;
				} else if ($products_availability['call_for_pricing'] == 1) {
					echo TEXT_CALL_FOR_PRICING;
				} else {
					echo TEXT_PRICING_NOT_AVAILABLE;
				}
			// End Availability ?>

 

 

In /admin/includes/database_tables.php and /includes/database_tables.php add before end:

 //Availability
 define('TABLE_PRODUCTS_AVAILABILITY', 'products_availability');

 

In /admin/includes/languages/english/categories.php and /includes/languages/english/product_info.php add before end:

//Begin availability
define('TEXT_PRODUCTS_AVAILABILITY', 'Availability:');
define('TEXT_CALL_FOR_PRICING', '£Please call for price');
define('TEXT_PRICING_NOT_AVAILABLE', 'Price not available');
define('TEXT_CALL_TO_ORDER', 'Call to Order');
//End availability

 

Think that's it - let me know if it behaves strangely and I'll find which bit I've missed!

Share this post


Link to post
Share on other sites

Tweaked ULCategories:

At top-level/home - is hidden.

 

At 1st level - displays sub-categories of selected 1st level

 

At 2nd + 3rd level - as above.

 

 

Animated using jQuery. Layout is CSS.

 

 

 

new file /includes/boxes/ul_categories.php

<?php
/*
 $Id: ul_categories.php,v 1.00 2006/04/30 01:13:58 nate_02631 Exp $

Outputs the store category list as a proper unordered list, opening up
possibilities to use CSS to style as drop-down/flyout, collapsable or 
other menu types.

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

 Copyright (c) 2006 Nate Welch http://www.natewelch.com

 Released under the GNU General Public License
*/

// BEGIN Configuration options

 // Set to false to display the unordered list only. Set to true to display in
// a regular box. The former is useful for better integrating the menu with your layout.
$show_ulcats_as_box = false;

// Indicates whether or not to render your entire category list or just the root categories
// and the currently selected submenu tree. Rendering the full list is useful for dynamic menu
// generation where you want the user to have instant access to all categories. The other option
// is the default oSC behaviour, when the subcats aren't available until the parent is clicked. 
$show_full_tree = true;	

// This is the CSS *ID* you want to assign to the UL (unordered list) containing
// your category menu. Used in conjuction with the CSS list you create for the menu.
// This value cannot be blank.
$idname_for_menu = 'subcat';

// This is the *CLASSNAME* you want to tag a LI to indicate the selected category.
// The currently selected category (and its parents, if any) will be tagged with
// this class. Modify your stylesheet as appropriate. Leave blank or set to false to not assign a class. 
$classname_for_selected = 'subcat_selected';

// This is the *CLASSNAME* you want to tag a LI to indicate a category has subcategores.
// Modify your stylesheet to draw an indicator to show the users that subcategories are
// available. Leave blank or set to false to not assign a class. 	
$classname_for_parent = 'subcat_parent';
$classname_for_child = 'subcat_child';
$classname_for_no_children = 'subcat_no_children';	

// This is the HTML that you would like to appear before your categories menu if *not*
// displaying in a standard "box". This is useful for reconciling tables or clearing
// floats, depending on your layout needs.	
$before_nobox_html = '<span class="subcat_heading">Subcategories</span><br /><div class="subcat">';

// This is the HTML that you would like to appear after your categories menu if *not*
// displaying in a standard "box". This is useful for reconciling tables or clearing
// floats, depending on your layout needs.	
 $after_nobox_html = '';	


// END Configuration options

// Global Variables
$GLOBALS['this_level'] = 0;
$GLOBALS['last_parent_id'] = 0;

// If Top of store then do nothing:

if (sizeof($cPath_array) == 0 ) {
return '';
}

// Initialize HTML and info_box class if displaying inside a box
if ($show_ulcats_as_box) {
   echo '<tr><td>';
   $info_box_contents = array();
   $info_box_contents[] = array('text' => 'Sub Categories');
   new infoBoxHeading($info_box_contents, true, false);					
}

// Generate a bulleted list (uses configuration options above)
$categories_string = tep_make_cat_ullist();


// Output list inside a box if specified, otherwise just output unordered list
if ($show_ulcats_as_box) {
   $info_box_contents = array();
   $info_box_contents[] = array('text' => $categories_string);
   new infoBox($info_box_contents);
	echo '</td></tr>';	
} else {
	echo $before_nobox_html;	
   echo $categories_string;
	echo $after_nobox_html;
}


// Create the root unordered list
function tep_make_cat_ullist($rootcatid = 0, $maxlevel = 0){

   global $idname_for_menu, $cPath_array, $show_full_tree, $languages_id;

   // Modify category query if not fetching all categories (limit to root cats and selected subcat tree)

	if (!$show_full_tree) {
	  $parent_query = '';
//        $parent_query	= 'AND (c.parent_id = "0"';	

			if (isset($cPath_array)) {

			    $cPath_array_temp = $cPath_array;

			    foreach($cPath_array_temp AS $key => $value) {
				if ($parent_query == '') {
						$parent_query = 'AND (c.parent_id = "' . $value . '"';
					} else {
					    $parent_query	.= ' OR c.parent_id = "'.$value.'"';
					}
				}
					unset($cPath_array_temp);
			}	

	   		$parent_query .= ')';				
	} else {
       $parent_query	= '';	
	}

	$result = tep_db_query('select c.categories_id, cd.categories_name, c.parent_id from ' . TABLE_CATEGORIES . ' c, ' . TABLE_CATEGORIES_DESCRIPTION . ' cd where c.categories_id = cd.categories_id and cd.language_id="' . (int)$languages_id .'" '.$parent_query.' order by sort_order, cd.categories_name');

	while ($row = tep_db_fetch_array($result)) {				
       $table[$row['parent_id']][$row['categories_id']] = $row['categories_name'];
   }

//    $output .= '<div id="'.$idname_for_menu.'">';

$rootcatid = $cPath_array[0];

//	echo $rootcatid;

   $output .= tep_make_cat_ulbranch($rootcatid, $table, 0, $maxlevel);

	// Close off nested lists
   for ($nest = 0; $nest <= $GLOBALS['this_level']; $nest++) {
       $output .= '</div>';		
	}

       $output .= '';					 
   return $output;
}

// Create the branches of the unordered list
function tep_make_cat_ulbranch($parcat, $table, $level, $maxlevel) {

   global $cPath_array, $classname_for_selected, $classname_for_parent;

   $list = $table[$parcat];
$this_class = 'subcat_parent';	

   while(list($key,$val) = each($list)){

       if ($GLOBALS['this_level'] != $level) {

	        if ($GLOBALS['this_level'] < $level) {
			        $output .= "\n".'<div id="subcat_nest_' . $GLOBALS['last_parent_id'] .'" class="subcat_nest_div">';
					$this_class = 'subcat_child';
			    } else {
               for ($nest = 1; $nest <= ($GLOBALS['this_level'] - $level); $nest++) {
                   $output .= '</div>'."\n";
				$this_class = 'subcat_parent';
	            }
					}			

	        $GLOBALS['this_level'] = $level;
       }

//        if (isset($cPath_array) && in_array($key, $cPath_array) && $classname_for_selected) {
//            $this_class = $classname_for_selected;
//        } else {
//            $this_class = 'subcat_no_children';		
//		}


       if (!$level) {
//				    unset($GLOBALS['cPath_set']);
//						$GLOBALS['cPath_set'][0] = $key;
           $cPath_new = 'cPath=' . $key;

       } else {
					$GLOBALS['cPath_set'][$level] = $key;										
           $cPath_new = 'cPath=' . implode("_", array_slice($GLOBALS['cPath_set'], 0, ($level+1)));
       }

    if (tep_has_category_subcategories($key) && $classname_for_parent) {
           $this_class = $classname_for_parent;
		$GLOBALS['last_parent_id'] = $key;
	    }				

       $output .= '<span class="'.$this_class .'">';

       $output .= '<a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '"' . $this_parent_class ./*$this_cat_class . */'>'.$val;		

       if (SHOW_COUNTS == 'true') {
           $products_in_category = tep_count_products_in_category($key);
           if ($products_in_category > 0) {
               $output .= ' (' . $products_in_category . ')';
           }
       }

       $output .= '</a>';	

	$div_id = 'subcat_nest_' . $key;
	$img_id = 'subcat_nest_img_' . $key;

	if (tep_has_category_subcategories($key)) {
		$output .= '<img src="/images/icon_plus.gif" style="line-height: 18px; position: absolute; right: 0px; top: 3px;" id="' . $img_id .'" onClick="javascript: show_subnav_div(\'' . $div_id . '\', \'' . $img_id . '\');"></span>';
	}

       if (!tep_has_category_subcategories($key)) {
           $output .= '</span><br />'."\n";	
       }						 

       if ((isset($table[$key])) AND (($maxlevel > $level + 1) OR ($maxlevel == '0'))) {
           $output .= tep_make_cat_ulbranch($key,$table,$level + 1,$maxlevel);
       }

	} // End while loop

   return $output;
}	

?>

 

 

in stylesheet.css or whatever you use:

/* START Subcategories nav */
.subcat_heading {
font-family: Verdana, Arial, sans-serif;
font-size: 10px;
font-weight: bold;
background: #5469FE;
color: #FFFFFF;
margin: 0;
padding-left: 5px;
width: 163px;
height: 18px;
line-height: 18px;
display: inline-block;
float: left;
}

.subcat { 
 padding:0; 
 margin:0; 
 margin-bottom: 8px;
 width: 166px;
 border: 1px solid black;
 border-bottom: none;
 float: left;
 } 

.subcat_parent {
	display:block;
	float: left;		
	width: 166px;
	height: 16px;
	background-color: #0044CC;
	font-size: 12px;
	border-bottom: 1px solid black;
	line-height: 16px;
	position: relative;
	margin: 0px;
}

	.subcat_parent a:link, .subcat_no_children a:link {
		text-decoration: none;
		color: #AAAAAA;
	}
	.subcat_parent a:visited,  .subcat_no_children a:visited {
		text-decoration: none;
		font-size: 12px;
		color: #AAAAAA;
	}	
	.subcat_parent a:hover,  .subcat_no_children a:hover {
		text-decoration: underline;
		font-size: 12px;
		color: #FFFFFF;
	}
	.subcat_parent a:active,  .subcat_no_children a:active {
		text-decoration: none;
		font-size: 12px;
		color: #AAAAAA;
	}

.subcat_nest_div {
	display: none;
	width: 166px;		
	padding: 0px;
  	margin: 0px;
  	color: #FFFFFF;
	float: left;
	line-height: 16px;		
}

	.subcat_child {				/* Spans */
		background-color: #9FBAFF;
		width: 166px;
		float: left;
		height: 16px;
		border-bottom: 1px solid #666666;
		font-size: 10px;
		line-height: 16px;
		}

		.subcat_child a:link {
			text-decoration: none;
			color: #444444;
			text-indent: 4px;
		}
		.subcat_child a:visited {
			text-decoration: none;
			color: #444444;
			text-indent: 4px;
		}
		.subcat_child a:hover {
			text-decoration: underline;
			color: #000000;
			text-indent: 4px;
		}
		.subcat_child a:active {
			text-decoration: none;
			color: #444444;
			text-indent: 4px;
		}

.subcat_selected {
		background-color: #CCCCCC;
		color: #0000FF;
		text-decoration: none;
		width: 165px;
		float: left;
		height: 18px;
		border-bottom: 1px solid #666666;
		font-size: 10px;
		line-height: 18px;					
}
	.subcat_selected a:link {
		text-decoration: none;
		color: #0000FF;
		text-indent: 4px;
	}
	.subcat_selected a:visited {
		text-decoration: none;
		color: #0000FF;
		text-indent: 4px;
	}
	.subcat_selected a:hover {
		text-decoration: none;
		color: #0000FF;
		text-indent: 4px;
	}
	.subcat_selected a:active {
		text-decoration: none;
		color: #0000FF;
		text-indent: 4px;
	}

/* END Subcategories nav */

 

 

 

In /includes/column_left.php:

 

Find:

  if ((USE_CACHE == 'true') && empty($SID)) {
echo tep_cache_categories_box();
 } else {
include(DIR_WS_BOXES . 'categories.php');
 }

 

Replace with:

 

 if ((USE_CACHE == 'true') && empty($SID)) {
echo tep_cache_categories_box();
 } else {
include(DIR_WS_BOXES . 'ul_categories.php');
 }

 

Think that's it, again let me know if I've left out any code mods.

Share this post


Link to post
Share on other sites

Demos of both are available presently on http://shop.gear7.co.uk - they will not be available in about a months time. I may take some screenshots, although anybody else is welcome to do that.

 

Regards,

Chris Wood

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  

×