Jump to content
Sign in to follow this  
AdamPGT

Year/Make/Model - Finally!

Recommended Posts

So I've needed this functionality for some time and finally got something to work using the chained select code from yxscripts.com and some basic PHP. Now the code is a little sloppy so if anyone would like to help clean it up before it is released as a contribution that'd be great.

 

This is the DB Heirarchy I'm using:

 

-> Make

----> Model

-------> Years

 

For the years, I'm using ranges for specific generations.

 

Here is the JS/PHP content for the document head:

 

<!-- Start Navigation -->

<script language="javascript" src="chainedselects.js">

/***********************************************
* Chained Selects script- By Xin Yang (http://www.yxscripts.com/)
* Script featured on/available at http://www.dynamicdrive.com/
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

</script>
<?php 
echo "
<script language=\"javascript\">
//var hide_empty_list=true; //uncomment this line to hide empty selection lists

var disable_empty_list=true; //uncomment this line to disable empty selection lists

addListGroup(\"vehicles\", \"make\");\n
addOption(\"make\", \"Select a Make\", \"Select a Make\", \"\"); //Empty starter option
";

$make = "SELECT categories.categories_id, categories_name FROM categories, categories_description WHERE categories.parent_id = '0' AND categories_description.categories_id = categories.categories_id ORDER BY sort_order";
$makeResult = mysql_query($make);
while ($makeRow = mysql_fetch_array($makeResult)){
$mkid = $makeRow['categories_id'];
$mkname = $makeRow['categories_name'];
echo "addList(\"make\", \"" . $mkname . "\", \"" . $mkid . "\", \"" . $mkname . "\");
";
echo "addOption(\"" . $mkname . "\", \"Select a Model\", \"Select a Model\", \"\"); //Empty starter option
";
$model = "SELECT categories.categories_id, categories_name FROM categories, categories_description WHERE categories.parent_id = '" . $mkid . "' AND categories_description.categories_id = categories.categories_id ORDER BY sort_order";
$modelResult = mysql_query($model);
while ($modelRow = mysql_fetch_array($modelResult)){
	$mdid = $modelRow['categories_id'];
	$mdname = $modelRow['categories_name'];
	echo "addList(\"" . $mkname . "\", \"" . $mdname . "\", \"" . $mdid . "\", \"" . $mdname . "\");
	";
	echo "addOption(\"" . $mdname . "\", \"Select a year\", \"\", 1);
	";
	$year = "SELECT categories.categories_id, categories_name FROM categories, categories_description WHERE categories.parent_id = '" . $mdid . "' AND categories_description.categories_id = categories.categories_id ORDER BY sort_order";
	$yearResult = mysql_query($year);
	while ($yearRow = mysql_fetch_array($yearResult)){
		$yrid = $yearRow['categories_id'];
		$yrname = $yearRow['categories_name'];
		echo "addOption(\"" . $mdname . "\", \"" . $yrname . "\", \"http://www.gforceauto.com/index.php?cPath=" . $mkid . "_" . $mdid . "_" . $yrid . "\");
		";
	}
}
}

echo "</script>";
?>
<script language="javascript">
function openLink(url) {
 if (url != "") {
location.href = url;
 }
 else {
alert("Please select a site.");
 }
}
</script>

<!-- End Navigation -->

 

Also, this script has cookie functionality so the selections will stick after visiting different pages, so the <BODY> tag needs the following:

 

<body onload="initListGroup('vehicles', document.forms[0].make, document.forms[0].model, document.forms[0].year, 'cs')">

 

Now the form for the categories box:

 

<form>
 <table align=\"center\">
<tr>
  <td><select name=\"make\" style=\"width:160px;\"></select></td>
</tr>
<tr>
  <td><select name=\"model\" style=\"width:160px;\"></select></td>
</tr>
<tr>
  <td><select name=\"year\" style=\"width:160px;\" onchange=\"openLink(this.value)\"></select></td>
</tr>
 </table>
</form>

 

I'm using BTS so my categories.php looks like this:

 

<?php

/*

 $Id: categories.php,v 1.24 2003/06/09 22:09:55 hpdl Exp $

 modified by paulm_nl 2003/12/23

 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com



 Copyright (c) 2003 osCommerce



 Released under the GNU General Public License

*/



 $boxHeading = BOX_HEADING_CATEGORIES;

 $corner_left = 'rounded';

 $corner_right = 'square';

 $box_base_name = 'categories'; // for easy unique box template setup (added BTSv1.2)



 $box_id = $box_base_name . 'Box';  // for CSS styling paulm (editted BTSv1.2)

 $boxContent .= "<form>
				<table align=\"center\">
					<tr>
						<td><select name=\"make\" style=\"width:160px;\"></select></td>
					</tr>
					<tr>
						<td><select name=\"model\" style=\"width:160px;\"></select></td>
					</tr>
					<tr>
						<td><select name=\"year\" style=\"width:160px;\" onchange=\"openLink(this.value)\"></select></td>
					</tr>
				</table>
			  </form>";

include (bts_select('boxes', $box_base_name)); // BTS 1.5

?>

 

You may see the menu in action here: http://www.gforceauto.com (I haven't even started templating anything, nor do I have all makes and models entered etc.)

 

Have fun and any input is appreciated.

 

Thanks,

 

Adam

Edited by AdamPGT

Share this post


Link to post
Share on other sites

Alright, well I'm going to add this to the contributions and start a support thread. Feel free to make edits to this and update the contribution. :)

 

--Adam

Share this post


Link to post
Share on other sites

thats cool, but what if a part fits 5 different cars? you going to list that part 5 times? or do the multi category contrib and have that 1 products added to all these diff cats?

i have the same idea, but im using the dropdowns in more or a search method, and each product has compatible car makes applied to it from a database list of cars.


Check out my fully customized oscommerce site by viewing my profile.

Share this post


Link to post
Share on other sites

I am currently constructing my website/database as well. I have a few quesitons

 

1. where/how did u compile all of the makes/models/years? is it accurate?

 

2. Regarding listing 5 items for 1 item that fits multiple cars or years, how did u get around this?

 

My programmer is having one hell of a time trying to figure this out. Any information you can provide is mighty helpful. Thanx.

Share this post


Link to post
Share on other sites

Good idea guys. I haven't tested the code personally, but upon initial review that's A LOT of database queries to create the chained select. A hundred or so extra queries at every page load is gonna wreck havoc on your page parse times and server load.

 

1) You should save the Javascript code with the queries into a seperate php file like chainedselectdata.php

 

2) Create a script called something like cachechainedselecctdata.php that runs the same script as chainedselectdata.php and saves the results (and overwrites if needed) into a file in the catalog directory called chainedselectdata.js

 

3) Create something like a "Refresh Chained Select Data" button somewhere on the Administrative Panel that refreshes the cache. You'll have to click this whenever you edit/update categories and products. Alternatively you can have a cronjob run every 5 minutes refreshing it.

 

4) Where you had the Javascript code with the queries put in something like this:

 

if file_exists(chainedselectdata.js) {
 include(chainedselectdata.js)
} else {
 include(chainedselectdata.php)
}

 

To answer some of MajorMods questions:

 

1) You should compile the make/model/year data based on the products you add to the catalog. If you create the categories for a product you are going to be add then you make sure that your pulldowns actually have parts. We all know how much of a pain in the butt it is to use a pulldown that when you drill down to what you need it always ends up empty.

 

2) You guys are doing it different than me...so don't know.


I ♥ PHP/MYSQL/CSS

Share this post


Link to post
Share on other sites

doing it different than u?

 

if u went to my website, its not really that... that site was setup as a dummy site for the time being. :) This is the basic layout of my current site http://www.fif.pl/mods/new/ I just dont know relational databasing. I dont wanna have the same item listed multiple times because of keeping track of inventory. Im trying to find a way so the one item will show up when a customer searches for make/model/year and the item works for multiple vehicles. ie. shift knob, neons, etc.

Edited by MajorMods

Share this post


Link to post
Share on other sites

MajorMods, you don't have to worry about inventory when you are copying a product across many categories. OSC just creates multiple category links to a single product. You aren't duplicating products, you are just having OSC making it able to be found in multiple categories. If you do a copy, look at the productID number. Its still the same no matter which category you found it in.

 

But yeah you are right in it being a pain. If you add a new vehicle, you have to copy all the more universal products into the new vehicle's category. Like you mentioned with shift knobs, light bulbs, etc. You might want to create a top level category for those universal items.

 

Also your catalog I think its broken. How come I couldn't find any parts for my 1972 Acura 200SX SE-R? There has to be something for it :P I know I'm just teasing about your pulldowns not being "smarter". I've managed to teach mine pretty good and doing the method above will do a good job too.

 

And yes, I am doing it different than you guys. The complexity of car parts is astonishing and I wasn't content with the way most people are doing it. Had to create my own custom solution. Way too busy to get the cart up though...so its currently collecting dust :(

Edited by AXM

I ♥ PHP/MYSQL/CSS

Share this post


Link to post
Share on other sites

yeah but im not using OSC, im actually using zencart as I was referred to that and my programmer is getting fairly close to being done. Then I gotta update my spreadsheets so they can transferred into the software. Are you familiar with zencart?

Share this post


Link to post
Share on other sites

Zencart is just OSCommerce with some contributions pre-built into it. I haven't checked it out in a while but its not as good as a base OSC and you having your programmer add in the contributions himself.


I ♥ PHP/MYSQL/CSS

Share this post


Link to post
Share on other sites
Alright, well I'm going to add this to the contributions and start a support thread. Feel free to make edits to this and update the contribution. :)

 

--Adam

 

I searched for this contribution and did not find it. Do you have a link?

 

Thx!

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  

×