Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

More Control of Product Display


Guest

Recommended Posts

I need help in modifying the appropriate code so that the product listings include checkboxes for new and old and their selection affects the existing category or manufacturer. I have added an "age" field within the products table and populated with "new", "refurbished", or "old." I want the user to be able to have the ability to view "new", "refurbished" and "used" and easily remove viewing the used product, for example, within a given category.

 

It appears the that the index.php file contains the query sections that need modification but I don't have the php knowledge to make this work. Can someone help?

Link to comment
Share on other sites

I've got the front end of this working. No admin yet, but that should be easy. To get an idea of what this does, I have it up on my test site. Go ahead and try it out.

 

The first batch of modifications are to catalog/index.php. First, find this code near line 171:

// show the products of a specified manufacturer
if (isset($HTTP_GET_VARS['manufacturers_id'])) {

and add this code just above it:

	
// Age filter
$new = 'on';
$refurb = 'on';
$used = 'on';
if (isset($HTTP_GET_VARS['new']) || isset($HTTP_GET_VARS['refurb']) || isset($HTTP_GET_VARS['used'])) {
  $new = ($HTTP_GET_VARS['new'] == 'on') ? 'on' : 'off';
  $refurb = ($HTTP_GET_VARS['refurb'] == 'on') ? 'on' : 'off';
  $used = ($HTTP_GET_VARS['used'] == 'on') ? 'on' : 'off';
}

$filter_more = false;
$filter_sql = '';

if ($new == 'on') {
  $filter_more = true;
  $filter_sql .= " and (p.age='new'";
}

if ($refurb == 'on') {
  if ($filter_more) {
	$filter_sql .= " or p.age='refurb'";
  } else {
	$filter_sql .= " and (p.age='refurb'";
  }
  $filter_more = true;
}

if ($used == 'on') {
  if ($filter_more) {
	$filter_sql .= " or p.age='used'";
  } else {
	$filter_sql .= " and (p.age='used'";
  }
  $filter_more = true;
}

if ($filter_more) {
  $filter_sql .= ')';
}
// End Age filter

Now find this code near line 216 (this is a long string, so I've left out the middle part):

		$listing_sql = "select " . $select_column_list ...... "'";

We need to add our filter variable to the end of that (just before the semicolon), so it looks like this:

		$listing_sql = "select " . $select_column_list ...... "'" . $filter_sql;

There are three more similar strings in the next few lines; add the same code to the end of each one.

 

Now find this code around line 306:

// Get the right image for the top-right
$image = DIR_WS_IMAGES . 'table_background_list.gif';

and paste the following code just above it:

// Age filter
echo '<td align="center" class="main">' . tep_draw_form('age', FILENAME_DEFAULT, 'get') . TEXT_SHOW_AGE . ' ';
echo tep_draw_checkbox_field('new', '', ($new == 'on' ? true : false)) . ' ' . TEXT_NEW . ' ';
echo tep_draw_checkbox_field('refurb', '', ($refurb == 'on' ? true : false)) . ' ' . TEXT_REFURBISHED . ' ';
echo tep_draw_checkbox_field('used', '', ($used == 'on' ? true : false)) . ' ' . TEXT_USED . ' ';
if (isset($HTTP_GET_VARS['manufacturers_id'])) {
  echo tep_draw_hidden_field('manufacturers_id', $HTTP_GET_VARS['manufacturers_id']);
} else {
  echo tep_draw_hidden_field('cPath', $cPath);
}
echo tep_draw_hidden_field('sort', $HTTP_GET_VARS['sort']);
echo tep_image_submit('small_view.gif', IMAGE_BUTTON_VIEW);
echo '</form></td>' . "\n";
// End age filter

Now find the following code in catalog/includes/languages/english/index.php, near line 34:

  define('TEXT_ALL_CATEGORIES', 'All Categories');
 define('TEXT_ALL_MANUFACTURERS', 'All Manufacturers');

and add the following just after it:

  define('TEXT_SHOW_AGE', 'Age:');
 define('TEXT_NEW', 'New');
 define('TEXT_REFURBISHED', 'Refurbished');
 define('TEXT_USED', 'Used');
 define('IMAGE_BUTTON_VIEW', 'View');

The definitions in the last section can be changed to say whatever you want. I put the selections up near the top of the page, next to the Manufacturer selection dropdown. You can put them wherever you want by moving that last block of code in catalog/index.php. I'm not real happy about using the View button, but it was the best available choice. Feel free to make a better button.

 

If you have any questions or suggestions please post them. I'm going to whip up an admin update for this. I think it might make a good Contribution. If I can manage to find the time.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

And now for the admin side. In admin/categories.php, find the following code near line 223:

								  'products_tax_class_id' => tep_db_prepare_input($HTTP_POST_VARS['products_tax_class_id']),
							  'manufacturers_id' => tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id']));

and change those lines to:

								  'products_tax_class_id' => tep_db_prepare_input($HTTP_POST_VARS['products_tax_class_id']),
							  'manufacturers_id' => tep_db_prepare_input($HTTP_POST_VARS['manufacturers_id']),
							  'age' => tep_db_prepare_input($HTTP_POST_VARS['age']));

Now find the following code near line 223:

		  } elseif ($HTTP_POST_VARS['copy_as'] == 'duplicate') {
		$product_query = tep_db_query("select products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_tax_class_id, manufacturers_id from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");

and replace the last line of that with:

			$product_query = tep_db_query("select products_quantity, products_model, products_image, products_price, products_date_available, products_weight, products_tax_class_id, manufacturers_id, age from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");

Now find this line, two lines below the above code:

			tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model, products_image, products_price, products_date_added, products_date_available, products_weight, products_length, products_width, products_height, products_status, products_tax_class_id, manufacturers_id) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '" . tep_db_input($product['products_price']) . "',  now(), '" . tep_db_input($product['products_date_available']) . "', '" . tep_db_input($product['products_weight']) . "', '" . tep_db_input($product['products_length']) . "', '" . tep_db_input($product['products_width']) . "', '" . tep_db_input($product['products_height']) . "', '0', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id'] . "'"')");

and replace it with this:

			tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model, products_image, products_price, products_date_added, products_date_available, products_weight, products_length, products_width, products_height, products_status, products_tax_class_id, manufacturers_id, age) values ('" . tep_db_input($product['products_quantity']) . "', '" . tep_db_input($product['products_model']) . "', '" . tep_db_input($product['products_image']) . "', '" . tep_db_input($product['products_price']) . "',  now(), '" . tep_db_input($product['products_date_available']) . "', '" . tep_db_input($product['products_weight']) . "', '" . tep_db_input($product['products_length']) . "', '" . tep_db_input($product['products_width']) . "', '" . tep_db_input($product['products_height']) . "', '0', '" . (int)$product['products_tax_class_id'] . "', '" . (int)$product['manufacturers_id'] . "', '" . (int)$product['age'] . "')");

Next, find code that looks like this around line 372:

					   'products_status' => '',
				   'products_tax_class_id' => '',
				   'manufacturers_id' => '');

and replace it with this:

					   'products_status' => '',
				   'products_tax_class_id' => '',
				   'manufacturers_id' => '',
				   'age' => '');

Now find the following a few lines below that:

	  $product_query = tep_db_query("select pd.products_name, pd.products_description, pd.products_url, p.products_id, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available, p.products_status, p.products_tax_class_id, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");

and replace it with this:

	  $product_query = tep_db_query("select pd.products_name, pd.products_description, pd.products_url, p.products_id, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, date_format(p.products_date_available, '%Y-%m-%d') as products_date_available, p.products_status, p.products_tax_class_id, p.manufacturers_id, p.age from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");

Now find this code around line 412:

	$languages = tep_get_languages();

and paste the following just above it:

// Age filter
$ages_array = array (array ('id' => 'new', 'text' => TEXT_NEW),
					 array ('id' => 'refurb', 'text' => TEXT_REFURB),
					 array ('id' => 'used', 'text' => TEXT_USED)
					);
// End age filter

Now find this code around line 510:

<?php
for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
?>
	  <tr>
		<td class="main"><?php if ($i == 0) echo TEXT_PRODUCTS_NAME; ?></td>

and paste this just above it:

<?php
// Age Filter
?>
	  <tr>
		<td class="main"><?php echo TEXT_PRODUCTS_AGE; ?></td>
		<td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_pull_down_menu('age', $ages_array, $pInfo->age); ?></td>
	  </tr>
	  <tr>
		<td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
	  </tr>

That's all for this file. To finish it off, find the following in admin/includes/languages/english/categories.php near line 87:

define('TEXT_PRODUCTS_PRICE_GROSS', 'Products Price (Gross):');
define('TEXT_PRODUCTS_WEIGHT', 'Products Weight:');

and add the following just below:

// Age Filter
define('TEXT_NEW', 'New');
define('TEXT_REFURB', 'Refurbished');
define('TEXT_USED', 'Used');
define('TEXT_PRODUCTS_AGE', 'Products Age: ');
// End Age Filter

That should do it. Of course if you use other languages you will need to modify the language files for those similar to the English files I've modified.

 

I've tested this on a test site, but there may still be lurking bugs. Use with care. Please post any suggestions or comments.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

That should do it. Of course if you use other languages you will need to modify the language files for those similar to the English files I've modified.

 

I've tested this on a test site, but there may still be lurking bugs. Use with care. Please post any suggestions or comments.

 

Regards

Jim

 

Very nice, Jim. It's working just fine for me.

 

I've added the admin portion and while I do not get any errors when accessing the admin, I don't see what these admin changes did. Where should they show up?

Link to comment
Share on other sites

Very nice, Jim. It's working just fine for me.

 

I've added the admin portion and while I do not get any errors when accessing the admin, I don't see what these admin changes did. Where should they show up?

They show up in the Categories/Products admin when you are editing or adding a product. You should have a dropdown to assign the "age" to the product.

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

They show up in the Categories/Products admin when you are editing or adding a product. You should have a dropdown to assign the "age" to the product.

 

Regards

Jim

 

Yes, I see that now.

Link to comment
Share on other sites

  • 3 years later...

I have a question...

 

I select a manufacturer and from that manufacturer i have both new and used products. If i want to select only the new products it will display the new products from ALL manufacturers. What must be modified to work with the manufacturer drop-down?

 

Thank you

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...