matts213 Posted July 6, 2010 Share Posted July 6, 2010 I have tried to add the simple ability to select a product to be a "featured product" that will show in a box above the new products box on the index page.What I have done appears to be working but I am very new to PHP and don't fully understand all the code that I modified. - I basically modified all the code I found for product_status in admin/categories.php and added featured_status to add a radio button and insert the choice into the db. -I modified includes/modules/new_products.php and created featured_products.php. I added to the PRODUCTS table in the db featured_status. -I added the appropriate defines in the English files. I don't really know if this makes sense to do it this way. One thing that I know is weird is that in the new featured_products.php there is still MAX_DISPLAY_NEW PRODUCTS. I looked in admin/configuration.php but can't figure out how to add an option to set a max value for this. I was hoping that someone could look at it and determine if what i have done here is ok. I also want to make sure I haven't created any unforeseen issues. Thanks admin/categories.php <tr> <td class="main"><?php echo TEXT_PRODUCTS_STATUS; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_radio_field('products_status', '1', $in_status) . ' ' . TEXT_PRODUCT_AVAILABLE . ' ' . tep_draw_radio_field('products_status', '0', $out_status) . ' ' . TEXT_PRODUCT_NOT_AVAILABLE; ?></td> </tr> <!-- **********BOF Featured Products*********************--> <tr> <td class="main"><?php echo TEXT_FEATURED_STATUS; ?></td> <td class="main"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_radio_field('featured_status', '1', $out_status) . ' ' . 'true' . ' ' . tep_draw_radio_field('featured_status', '0', $in_status) . ' ' . 'false'; ?></td> </tr> $product_query = tep_db_query("select p.products_subimage1, p.products_subimage2, p.products_subimage3, p.products_subimage4, p.products_subimage5, p.products_subimage6, p.products_id, pd.language_id, pd.products_name, pd.products_description, pd.products_head_title_tag, pd.products_head_desc_tag, pd.products_head_keywords_tag, pd.products_url, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_weight, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.featured_status, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "'"); $products_count = 0; if (isset($HTTP_GET_VARS['search'])) { $products_query = tep_db_query("select p.products_subimage1, p.products_subimage2, p.products_subimage3, p.products_subimage4, p.products_subimage5, p.products_subimage6, p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p.featured_status, p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and pd.products_name like '%" . tep_db_input($search) . "%' order by pd.products_name"); } else { $products_query = tep_db_query("select p.products_subimage1, p.products_subimage2, p.products_subimage3, p.products_subimage4, p.products_subimage5, p.products_subimage6, p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . "' order by pd.products_name"); } admin/includes/modules/featured_products.php <?php $info_box_contents = array(); $info_box_contents[] = array('text' => sprintf(TABLE_HEADING_FEATURED_PRODUCTS, strftime('%B'))); new contentBoxHeading($info_box_contents); if ( (!isset($featured_products_category_id)) || ($featured_products_category_id == '0') ) { $featured_products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.featured_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS); } else { $featured_products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES . " c where p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and c.parent_id = '" . (int)$featured_products_category_id . "' and p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_date_added desc limit " . MAX_DISPLAY_NEW_PRODUCTS); } $row = 0; $col = 0; $info_box_contents = array(); while ($featured_products = tep_db_fetch_array($featured_products_query)) { $info_box_contents[$row][$col] = array('align' => 'center', 'params' => 'class="smallText" width="33%" valign="top"', 'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $featured_products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $featured_products['products_image'], $featured_products['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $featured_products['products_id']) . '">' . $featured_products['products_name'] . '</a><br>' . $currencies->display_price($featured_products['products_price'], tep_get_tax_rate($featured_products['products_tax_class_id']))); $col ++; if ($col > 2) { $col = 0; $row ++; } } new contentBox($info_box_contents); echo ' '; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.