Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

"New" icon for newly added products


joeyjgarcia

Recommended Posts

Posted

I've added a radio button on the Add New Products page that will display a new image around (you choose where) your new product.

 

Basically, I cloned the "Product Status" field in the MySQL database and called it Products_isNew and it matched the structure of Products_Status.

 

Then in the Admin area, on the page where you add new products (admin/categories.php). I searched the SQL queries for p.products_status and changed it to p.products_status, p.products_isNew.

 

Then I foun the piece of code that creates the HTML for the Product Status on the Add New Products page, copied those lines and replaced the reference to Status with a reference to isNew.

 

The only exception where I didn't clone the HTML was where there is a little red and green light image that lets you set the status of the product without going into "edit mode". Look for icon_status_red_light.gif, this is the section I didn't copy.

 

The Copy as Duplicate query had a simple change to it. I show you what it is and I'll display enough code to make it easy to find.

 

I changed this:

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

? ? ? ? ? ?tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model,products_image,
products_image_small, products_price, products_price_msrp, products_date_added, products_date_available,
products_weight, products_status, products_isNew, 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_image_small']) . "', '" . tep_db_input($product['products_price']) . "', '" .
tep_db_input($product['products_price_msrp']) . "', ?now(), '" . tep_db_input($product['products_date_available']) .
"', '" . tep_db_input($product['products_weight']) . "', '0', ?'" . (int)$product['products_tax_class_id'] . "', '" .
(int)$product['manufacturers_id'] . "')");

 

to this (look for a second '0', in the end of the query):

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

? ? ? ? ? ?tep_db_query("insert into " . TABLE_PRODUCTS . " (products_quantity, products_model,products_image,
products_image_small, products_price, products_price_msrp, products_date_added, products_date_available,
products_weight, products_status, products_isNew, 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_image_small']) . "', '" . tep_db_input($product['products_price']) . "', '" .
tep_db_input($product['products_price_msrp']) . "', ?now(), '" . tep_db_input($product['products_date_available']) .
"', '" . tep_db_input($product['products_weight']) . "', '0','0', '" . (int)$product['products_tax_class_id'] . "', '" .
(int)$product['manufacturers_id'] . "')");

 

 

 

There was one section that I had to change to be different from the product status code.

 

Product Status Code was like this:

 

 ? ?if (!isset($pInfo->products_status)) $pInfo->products_status = '1';
? ?switch ($pInfo->products_status) {
? ? ?case '0': $in_status = false; $out_status = true; break;
? ? ?case '1':
? ? ?default: $in_status = true; $out_status = false;
? ?}

 

Product IsNew Code was changed to this:

 ? ?if (!isset($pInfo->products_isNew)) $pInfo->products_isNew = '1';
? ?switch ($pInfo->products_isNew) {
? ? ?case '0': $isNew = false; $isOld = true; break;
? ? ?case '1': $isNew = true; $isOld = false; break;
? ? ?default: $isOld = true; $isNew = false;
? ?}

 

 

Now for displaying the image part.

 

I changed four files the catalog/index.php, the catalog/product_info.php, catalog/includes/module/new_products.php, and catalog/includes/module/product_listing.php

 

In the index.php file I, again, search the "$listing_sql" queries and made the simple change.

 

Changed this:

p.products_id,

 

To This:

p.products_id, p.products_isNew,

 

In the new_products.php file I made the following changes.

 

In the $new_products_queries.

 

Changed this:

p.products_tax_class_id,

 

To this:

p.products_tax_class_id, p.products_isNew as isNew,

 

Inside this while loop:

while ($new_products = tep_db_fetch_array($new_products_query)) {

 

 

I added this code:

 

	if( $new_products['isNew'] == 1){
? ? ? ?$isNew = "<div style='position:relative;top:10'><img src='images/new_design.gif' alt='New Design' border=0></div>";
}else{
? ? ? ?$isNew = "<img src='images/trans.gif' width='112' height='26'>";
}

 

Since the positon of the product was displaced when the new image was displayed, I put a transparent image in its place when it is not new to keep all the products aligned. The style attribute was to position the image exactly where I wanted it to appear.

 

I added this variable ($isNew) to the string that displays my product. In my case, my products are displayed in an complex coded HTML table, so I won't show you this, you can just append it to your code with an append operator. For example, $isNew.$yourStringForYourProduct.

 

 

In the product_listing file you do the same type of thing, but you don't have to substitute a transparent image for old products. This file change is needed for search results.

 

I changed this code:

 ? ? ? ?switch ($column_list[$col]) {
? ? ? ? ?case 'PRODUCT_LIST_MODEL':

 

to:

	if( $listing['products_isNew'] == 1){
?$isNew = "<div style='position:relative;top:-30'><img src='images/new_design.gif' alt='New Design' border=0></div>";
}else{
?$isNew = "";
}


? ? ? ?switch ($column_list[$col]) {
? ? ? ? ?case 'PRODUCT_LIST_MODEL':

 

and I changed this:

 ? ? ? ? ? ?} else {
? ? ? ? ? ? ?$lc_text = ' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a> ';
? ? ? ? ? ?}
? ? ? ? ? ?break;
? ? ? ? ?case 'PRODUCT_LIST_MANUFACTURER':

to this:

 ? ? ? ? ? ?} else {
? ? ? ? ? ? ?$lc_text = $isNew.' <a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a> ';
? ? ? ? ? ?}
? ? ? ? ? ?break;
? ? ? ? ?case 'PRODUCT_LIST_MANUFACTURER':

 

 

I hope this helps.

 

BTW, I did something like this for displaying the MSRP price with a strikethough font on my products too. It wasn't as complicated and I cloned the Products_Price and made a Products_Price_Msrp field in the database.

 

Joey

Archived

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

×
×
  • Create New...