PDA

View Full Version : [Mod Installation] Discontinued Products



SMurphy
06-14-2012, 04:37 AM
I recently noticed there were loads of broken links to our site for products that we have took off the site.

This mod will add an extra button into the "Status" column in the admin panel so you can now set an item as "Active", "Discontinued" or "Inactive". The new discontinued settings will stop products showing up on your site as if they were inactive, but allow people following a direct link to the product to view it and see that its discontinued. This way you will not lose out on any hits to your site, and can use cross selling to recommend alternative products.

How To Install

Admin Side Install

Open file /catalog/admin/categories.php

Find around line 143;

if ( ($_GET['flag'] == '0') || ($_GET['flag'] == '1') ) {
Change to;

if ( ($_GET['flag'] == '0') || ($_GET['flag'] == '1') || ($_GET['flag'] == '2') ) {

Find around line 2520;

if ($products['products_status'] == '1') {
echo tep_image(DIR_WS_ICONS . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&amp;flag=0&amp;pID=' . $products['products_id'] . '&amp;cPath=' . $cPath) . '">' . tep_image(DIR_WS_ICONS . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>';
} else {
echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&amp;flag=1&amp;pID=' . $products['products_id'] . '&amp;cPath=' . $cPath) . '">' . tep_image(DIR_WS_ICONS . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a>&nbsp;&nbsp;' . tep_image(DIR_WS_ICONS . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10);
}
Change to;

if ($products['products_status'] == '1') {
echo tep_image(DIR_WS_ICONS . 'icon_status_green.gif', IMAGE_ICON_STATUS_GREEN, 10, 10) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&amp;flag=2&amp;pID=' . $products['products_id'] . '&amp;cPath=' . $cPath) . '">' . tep_image(DIR_WS_ICONS . 'icon_status_yellow_light.gif', IMAGE_ICON_STATUS_YELLOW_LIGHT, 10, 10) . '</a>&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&amp;flag=0&amp;pID=' . $products['products_id'] . '&amp;cPath=' . $cPath) . '">' . tep_image(DIR_WS_ICONS . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>';
} elseif ($products['products_status'] == '2') {
echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&amp;flag=1&amp;pID=' . $products['products_id'] . '&amp;cPath=' . $cPath) . '">' . tep_image(DIR_WS_ICONS . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a>&nbsp;&nbsp;' . tep_image(DIR_WS_ICONS . 'icon_status_yellow.gif', IMAGE_ICON_STATUS_YELLOW, 10, 10) . '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&amp;flag=0&amp;pID=' . $products['products_id'] . '&amp;cPath=' . $cPath) . '">' . tep_image(DIR_WS_ICONS . 'icon_status_red_light.gif', IMAGE_ICON_STATUS_RED_LIGHT, 10, 10) . '</a>';
} else {
echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&amp;flag=1&amp;pID=' . $products['products_id'] . '&amp;cPath=' . $cPath) . '">' . tep_image(DIR_WS_ICONS . 'icon_status_green_light.gif', IMAGE_ICON_STATUS_GREEN_LIGHT, 10, 10) . '</a>&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action=setflag&amp;flag=2&amp;pID=' . $products['products_id'] . '&amp;cPath=' . $cPath) . '">' . tep_image(DIR_WS_ICONS . 'icon_status_yellow_light.gif', IMAGE_ICON_STATUS_YELLOW_LIGHT, 10, 10) . '</a>&nbsp;&nbsp;' . tep_image(DIR_WS_ICONS . 'icon_status_red.gif', IMAGE_ICON_STATUS_RED, 10, 10);
}


Open file /catalog/admin/includes/functions/general.php

Find around line 925;

if ($status == '1') {
return tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '1', products_last_modified = now() where products_id = '" . (int)$products_id . "'");
Change to;

if ($status == '1' || $status == '2') {
return tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '" . $status . "', products_last_modified = now() where products_id = '" . (int)$products_id . "'");


Open file /catalog/admin/includes/languages/english/core.php

Find around line 459;

define('IMAGE_ICON_STATUS_GREEN_LIGHT', 'Set Active');
define('IMAGE_ICON_STATUS_RED', 'Inactive');
Insert the following between those lines;

define('IMAGE_ICON_STATUS_YELLOW', 'Discontinued');
define('IMAGE_ICON_STATUS_YELLOW_LIGHT', 'Set Discontinued');

Store Side Install

Open file /catalog/product_info.php

Find around line 28;

$product_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd left join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c using(products_id) left join " . TABLE_CATEGORIES . " c using(categories_id) where p.products_status = '1' and p.products_id = '" . (int)$_GET['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and find_in_set('".$customer_group_id."', products_hide_from_groups) = 0 and find_in_set('" . $customer_group_id . "', categories_hide_from_groups) = 0");
Change to;

$product_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd left join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c using(products_id) left join " . TABLE_CATEGORIES . " c using(categories_id) where p.products_status > '0' and p.products_id = '" . (int)$_GET['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and find_in_set('".$customer_group_id."', products_hide_from_groups) = 0 and find_in_set('" . $customer_group_id . "', categories_hide_from_groups) = 0");

Find around line 61;

$query .= " from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$_GET['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'";
Change to;

$query .= " from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status > '0' and p.products_id = '" . (int)$_GET['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'";


Open file /catalog/templates/fallback/content/product_info.tpl.php

Find around line 59;

$query = "select p.products_id, pd.products_name, pd.products_description, pd.tab1, pd.tab2, pd.tab3, pd.tab4, pd.tab5, pd.tab6, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_msrp, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id";
Change to;

$query = "select p.products_id, pd.products_name, pd.products_description, pd.tab1, pd.tab2, pd.tab3, pd.tab4, pd.tab5, pd.tab6, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_msrp, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id, p.products_status";

Find around line 63;

$query .= " from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$_GET['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'";
Change to;

$query .= " from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status > '0' and p.products_id = '" . (int)$_GET['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'";

Find around line 157;

if ( ($hi_product_price == CALL_FOR_PRICE_VALUE) || ($lo_product_price == CALL_FOR_PRICE_VALUE) ){
echo '<a href="' . tep_href_link(FILENAME_CONTACT_US, 'enquiry=' . TEXT_QUESTION_PRICE_ENQUIRY . '%0D%0A%0D%0A' . TEXT_QUESTION_MODEL . '%20' . str_replace(' ', '%20', $product_info['products_model']) . '%0D%0A' . TEXT_QUESTION_PRODUCT_NAME . '%20' . str_replace(' ', '%20', $product_info['products_name']) . '%0D%0A' . TEXT_QUESTION_PRODUCT_ID . '%20' . $product_info['products_id'] .'%0D%0A%0D%0A') . '">' . $products_price; ?></a>
<?php } else { echo $products_price; } ?>
Change to;

if ( ($hi_product_price == CALL_FOR_PRICE_VALUE) || ($lo_product_price == CALL_FOR_PRICE_VALUE) ){
echo '<a href="' . tep_href_link(FILENAME_CONTACT_US, 'enquiry=' . TEXT_QUESTION_PRICE_ENQUIRY . '%0D%0A%0D%0A' . TEXT_QUESTION_MODEL . '%20' . str_replace(' ', '%20', $product_info['products_model']) . '%0D%0A' . TEXT_QUESTION_PRODUCT_NAME . '%20' . str_replace(' ', '%20', $product_info['products_name']) . '%0D%0A' . TEXT_QUESTION_PRODUCT_ID . '%20' . $product_info['products_id'] .'%0D%0A%0D%0A') . '">' . $products_price . '</a>';
} elseif ($product_info['products_status'] == '2') {
echo TEXT_PRODUCT_DISCONTINUED;
} else { echo $products_price; }?>

Find around line 362;

if (SHOW_ASK_A_QUESTION == 'True') { ?>
Change to;

if (SHOW_ASK_A_QUESTION == 'True' && $product_info['products_status'] != '2') { ?>

Find around line 402;

<td align="left"><?php echo tep_image_submit('button_wishlist.gif', IMAGE_BUTTON_WISHLIST, 'name="wishlist" value="wishlist"'); ?></td>
Change to;

<td align="left"><?php if ($product_info['products_status'] != '2') echo tep_image_submit('button_wishlist.gif', IMAGE_BUTTON_WISHLIST, 'name="wishlist" value="wishlist"'); ?></td>

Find around line 411;

<?php } else { ?>
Change to;

<?php } elseif ($product_info['products_status'] == '2') {
echo '<a href="' . tep_href_link(FILENAME_CONTACT_US, 'enquiry=' . TEXT_QUESTION_ABOUT . str_replace(' ', '%20', $product_info['products_name']) . '%0D%0A' . TEXT_QUESTION_MODEL . '%20' . str_replace(' ', '%20', $product_info['products_model']) . '%0D%0A' . TEXT_QUESTION_PRODUCT_ID . '%20' . $product_info['products_id'] .'%0D%0A%0D%0A' . TEXT_QUESTION_TYPE . '%0D%0A%0D%0A') . '">' . tep_image_button('button_aaq.gif', IMAGE_BUTTON_AAQ) . '</a>';
} else { ?>


Open file /catalog/includes/languages/english/product_info.php

Find at the end of the file;

?>
Insert the following before that line;

define('TEXT_PRODUCT_DISCONTINUED', 'Discontinued');

pgmarshall
06-14-2012, 01:13 PM
Hi there - this looks to be an excellent addition to the core code - can you post a link to it in the bugtracker?

Regards.

SMurphy
06-14-2012, 01:17 PM
Yeah, no problem.

To make things easier for some people, I have attached all the modified files to this post. The files are all from 2.5.1 so if you are using an older/newer version, you'll just have to do it the way described above.

SMurphy
06-15-2012, 04:15 AM
UPDATE

Forgot to add in a new radio button to the add/edit product page, so here is how to do that.
Not sure how accurate my line numbers will be as I do not have access to a "clean" version of /catalog/admin/categories.php just now. Would take the lines numbers as +/- 30 or so.

Open file /catalog/admin/categories.php

Find around line 1354;

case '0': $in_status = false; $out_status = true; break;
case '1':
default: $in_status = true; $out_status = false;
Change to;

case '0': $in_status = false; $discontinued_status = false; $out_status = true; break;
case '2': $in_status = false; $discontinued_status = true; $out_status = false; break;
case '1':
default: $in_status = true; $discontinued_status = false; $out_status = false;

Find around line 1468;

<?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('products_status', '1', $in_status) . '&nbsp;' . TEXT_PRODUCT_AVAILABLE . '&nbsp;' . tep_draw_radio_field('products_status', '0', $out_status) . '&nbsp;' . TEXT_PRODUCT_NOT_AVAILABLE .
Change to;

<?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . tep_draw_radio_field('products_status', '1', $in_status) . '&nbsp;' . TEXT_PRODUCT_AVAILABLE . '&nbsp;' . tep_draw_radio_field('products_status', '2', $discontinued_status) . '&nbsp;' . TEXT_PRODUCT_DISCONTINUED .'&nbsp;' . tep_draw_radio_field('products_status', '0', $out_status) . '&nbsp;' . TEXT_PRODUCT_NOT_AVAILABLE .

Open file /catalog/admin/includes/languages/english/categories.php

Find around line 74;

define('TEXT_PRODUCT_AVAILABLE', 'Active');
define('TEXT_PRODUCT_NOT_AVAILABLE', 'Inactive');
Change to;

define('TEXT_PRODUCT_AVAILABLE', 'Active');
define('TEXT_PRODUCT_DISCONTINUED', 'Discontinued');
define('TEXT_PRODUCT_NOT_AVAILABLE', 'Inactive');

pgmarshall
06-15-2012, 11:41 PM
If you are using the Wish List then there are a couple of conditionals that need flipping ...

eg. wishlist.tpl.php

Line 143: if($products['products_status'] != 0) {

Line 131: if($products['products_status'] == 0) {

and wishlist_public.tpl.php

Line 158: if($products['products_status'] == 0) {

Line 173: if($products['products_status'] != 0) {

I will merge these in when I put this into the core soon.

Regards,