Juto Posted May 8, 2011 Share Posted May 8, 2011 Hi! I have a modified specials module, code below. How do I change it so that it doesn't display anything when there are no specials? See my site www.u2commerce.com especially the index page. Kine regards and thanks for any help. <?php /* $Id: default_specials.php,v 2.0 2003/06/13 osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ ?> <!--specials_mod//--> <?php if (!defined('PRODUCT_LIST_COLUMNS_SPECIALS')) { tep_db_query( "insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Number of products per row on specials products page', 'PRODUCT_LIST_COLUMNS_SPECIALS', '3', 'Set the number of products per row to display?', '8', '26', now());" ); define('PRODUCT_LIST_COLUMNS_SPECIALS', '3'); } if (!defined('MAX_DISPLAY_SPECIALS_PRODUCTS_MODULE')) { tep_db_query( "insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Maximum number of products to display on special products page', 'MAX_DISPLAY_SPECIALS_PRODUCTS_MODULE', '9', 'Set maximum number of products to display?', '8', '27', now());" ); define('MAX_DISPLAY_SPECIALS_PRODUCTS_MODULE', '9'); } $info_box_contents = array(); $info_box_contents[] = array('align' => 'left', 'text' => sprintf(TABLE_HEADING_SPECIALS_PRODUCTS_MODULE, strftime('%B'))); //Fix for heading corners the boolean 'USE_MID_CORNERS' is set in application_top //Replace new contentBoxHeading($info_box_contents); // With if (USE_MID_CORNERS == TRUE) { new contentBoxHeading($info_box_contents); } else { //Remove link to specials // new infoBoxHeading($info_box_contents, false, false, tep_href_link(FILENAME_SPECIALS)); new infoBoxHeading($info_box_contents, false, false, false); } // End fix $new = tep_db_query("select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and s.status = '1' order by s.specials_date_added DESC limit " . MAX_DISPLAY_SPECIALS_PRODUCTS_MODULE); $info_box_contents = array(); $row = 0; $col = 0; while ($default_specials = tep_db_fetch_array($new)) { $default_specials['products_name'] = tep_get_products_name($default_specials['products_id']); $info_box_contents[$row][$col] = array('align' => 'center', 'params' => 'class="smallText" width="'. round(100/PRODUCT_LIST_COLUMNS_NEW_PRODUCTS) .'%" valign="top"', 'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $default_specials["products_id"]) . '">' . tep_image(DIR_WS_IMAGES . $default_specials['products_image'], $default_specials['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $default_specials['products_id']) . '">' . $default_specials['products_name'] . '</a><br><s>' . $currencies->display_price($default_specials['products_price'], tep_get_tax_rate($default_specials['products_tax_class_id'])) . '</s><br><span class="productSpecialPrice">' . $currencies->display_price($default_specials['specials_new_products_price'], tep_get_tax_rate($default_specials['products_tax_class_id'])) . '</span>'); $col ++; if ($col > (PRODUCT_LIST_COLUMNS_SPECIALS-1)) { $col = 0; $row ++; } } while ($col != 0 && sizeof($info_box_contents[$row]) < PRODUCT_LIST_COLUMNS_SPECIALS) { $info_box_contents[$row][$col] = array( 'align' => 'center', 'params' => 'width="'. round(100/PRODUCT_LIST_COLUMNS_SPECIALS) .'%"', 'text' => ' ' ); $col ++; } new contentBox($info_box_contents); ?> <!--specials_mod_eof //--> Contributions: http://addons.oscommerce.com/info/8010 http://addons.oscommerce.com/info/8204 http://addons.oscommerce.com/info/8681 Link to comment Share on other sites More sharing options...
KDM Posted May 9, 2011 Share Posted May 9, 2011 Hi! I have a modified specials module, code below. How do I change it so that it doesn't display anything when there are no specials? See my site www.u2commerce.com especially the index page. Kine regards and thanks for any help. If you know where your default_specials is being called from (which program) then all you need to do is wrap a (if statement) around that line of code and check your database to see if you have any specials, if you do you would call your default_specials program else you skip it. That should solve your problem. Link to comment Share on other sites More sharing options...
Juto Posted May 9, 2011 Author Share Posted May 9, 2011 Thanks for answering. Yes, that would be the logic. But I would like to have it in my module. I.e to check if there are any specials before the line: $info_box_contents = array(); And if not just have a return statment. Sara Contributions: http://addons.oscommerce.com/info/8010 http://addons.oscommerce.com/info/8204 http://addons.oscommerce.com/info/8681 Link to comment Share on other sites More sharing options...
KDM Posted May 9, 2011 Share Posted May 9, 2011 Thanks for answering. Yes, that would be the logic. But I would like to have it in my module. I.e to check if there are any specials before the line: $info_box_contents = array(); And if not just have a return statment. Sara Yes you can put it in the program itself. If it was me I would do it first thing inside the program as there is less overhead if you pass up the whole process, the less processes that are ran the quicker your page loads. If of course there is some process inside that program you need to run then don't include that within your logic. Link to comment Share on other sites More sharing options...
Juto Posted May 10, 2011 Author Share Posted May 10, 2011 Hi again. Problem solved, here's the final code: <?php /* $Id: specials_mod.php,v 2.0 2011/05/10 osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2010 www.u2Commerce.com Released under the GNU General Public License */ ?> <!--specials_mod//--> <?php //check if there are any specials products at all: $new = tep_db_query("select p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and s.products_id = p.products_id and p.products_id = pd.products_id and pd.language_id = '" . $languages_id . "' and s.status = '1' order by s.specials_date_added DESC limit " . MAX_DISPLAY_SPECIALS_PRODUCTS_MODULE); if (tep_db_num_rows($new) > 0) { if (!defined('PRODUCT_LIST_COLUMNS_SPECIALS')) { tep_db_query( "insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Number of products per row on specials products page', 'PRODUCT_LIST_COLUMNS_SPECIALS', '3', 'Set the number of products per row to display?', '8', '26', now());" ); define('PRODUCT_LIST_COLUMNS_SPECIALS', '3'); } if (!defined('MAX_DISPLAY_SPECIALS_PRODUCTS_MODULE')) { tep_db_query( "insert into configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Maximum number of products to display on special products page', 'MAX_DISPLAY_SPECIALS_PRODUCTS_MODULE', '9', 'Set maximum number of products to display?', '8', '27', now());" ); define('MAX_DISPLAY_SPECIALS_PRODUCTS_MODULE', '9'); } $info_box_contents = array(); $info_box_contents[] = array('align' => 'left', 'text' => sprintf(TABLE_HEADING_SPECIALS_PRODUCTS_MODULE, strftime('%B'))); //Fix for heading corners the boolean 'USE_MID_CORNERS' is set in application_top //Replace new contentBoxHeading($info_box_contents); // With if (USE_MID_CORNERS == TRUE) { new contentBoxHeading($info_box_contents); } else { //Remove link to specials // new infoBoxHeading($info_box_contents, false, false, tep_href_link(FILENAME_SPECIALS)); new infoBoxHeading($info_box_contents, false, false, false); } // End fix $info_box_contents = array(); $row = 0; $col = 0; while ($default_specials = tep_db_fetch_array($new)) { $default_specials['products_name'] = tep_get_products_name($default_specials['products_id']); $info_box_contents[$row][$col] = array('align' => 'center', 'params' => 'class="smallText" width="'. round(100/PRODUCT_LIST_COLUMNS_NEW_PRODUCTS) .'%" valign="top"', 'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $default_specials["products_id"]) . '">' . tep_image(DIR_WS_IMAGES . $default_specials['products_image'], $default_specials['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $default_specials['products_id']) . '">' . $default_specials['products_name'] . '</a><br><s>' . $currencies->display_price($default_specials['products_price'], tep_get_tax_rate($default_specials['products_tax_class_id'])) . '</s><br><span class="productSpecialPrice">' . $currencies->display_price($default_specials['specials_new_products_price'], tep_get_tax_rate($default_specials['products_tax_class_id'])) . '</span>'); $col ++; if ($col > (PRODUCT_LIST_COLUMNS_SPECIALS-1)) { $col = 0; $row ++; } } while ($col != 0 && sizeof($info_box_contents[$row]) < PRODUCT_LIST_COLUMNS_SPECIALS) { $info_box_contents[$row][$col] = array( 'align' => 'center', 'params' => 'width="'. round(100/PRODUCT_LIST_COLUMNS_SPECIALS) .'%"', 'text' => ' ' ); $col ++; } new contentBox($info_box_contents); } ?> <!--specials_mod_eof //--> You can call it from index.php like so: <!--BOF Specials Products//--> <tr> <td><table border="0" width="100%" cellspacing="0" cellpadding="0" class="mid_column"> <tr> <td><?php include(DIR_WS_MODULES . FILENAME_SPECIALS_MOD); ?></td> </tr> </table></td> </tr> <!--EOF Specials Products//--> And have it look nice with the class="mid_column". Please note the following: //Fix for heading corners the boolean 'USE_MID_CORNERS' is set in application_top //Replace new contentBoxHeading($info_box_contents); // With if (USE_MID_CORNERS == TRUE) { new contentBoxHeading($info_box_contents); } else { //Remove link to specials // new infoBoxHeading($info_box_contents, false, false, tep_href_link(FILENAME_SPECIALS)); new infoBoxHeading($info_box_contents, false, false, false); } // End fix On the line new infoBoxHeading($info_box_contents, false, false, false); the first two false's specifies no rounded corners, the third false specifies no link to FILENAME_SPECIALS View the result at www.u2commerce.com Thanks for your time. Now I am on to the next enhancement :) Sara Contributions: http://addons.oscommerce.com/info/8010 http://addons.oscommerce.com/info/8204 http://addons.oscommerce.com/info/8681 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.