aelalfy1989 Posted January 4, 2010 Posted January 4, 2010 Hi, I want to ask for a favor, can anyone take a look at my code for my "similar products" and check why its not generating any products. I took the original code and changed it in the hope that it will look like my "Others Also Bought" code (because for some reason the way the new to the store infobox is created, creates lines between each product), but that didn't work. I don't know where these horizontal lines come from (they are not drawn using an image or such, and they only exist between products and not after the last product). My "similar products" code doesn't have that, I don't know why. If someone can help that would be great Thanks AE Here is the original "similar products code" <?php /* $Id: similar_products.php,v 1.0 2004/06/06 jck Exp $ Based on whats_new.php,v 1.31 by hpdl osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2004 osCommerce Released under the GNU General Public License */ // Set the sort order for the display switch(SIMILAR_PRODUCTS_ORDER){ case 'Random': $sort_order = 'RAND() '; break; case 'Products ID': $sort_order = 'p.products_id '; break; case 'Model Number': $sort_order = 'p.products_model '; break; case 'Price': $sort_order = 'p.products_price '; break; case 'Date Added': $sort_order = 'p.products_date_added '; break; case 'Last Modified': $sort_order = 'p.products_last_modified '; break; case 'Products Ordered': $sort_order = 'p.products_ordered '; break; case 'Products Name': $sort_order = 'pd.products_name '; break; case 'Products Viewed': $sort_order = 'pd.products_viewed '; break; default: $sort_order = 'RAND() '; } // switch switch(SIMILAR_PRODUCTS_SORT_ORDER){ case 'Ascending': $sort_order .= 'asc'; break; case 'Descending': $sort_order .= 'desc'; break; default: $sort_order .= 'asc'; } // switch // Find the id # of the category that the current product is in $category_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$_GET['products_id'] . "'" ); $category = tep_db_fetch_array($category_query); $category_id = $category['categories_id']; // Count prods in category; if less than 2 dont display (removes empty infobox from pages) $product_count_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc where p.products_id = pc.products_id and p.products_id = pd.products_id and p.products_id != '" . (int)$_GET['products_id'] . "' and p.products_status = '1' and pc.categories_id = '" . (int)$category_id . "' and pd.language_id = '". (int)$languages_id ."'" ); $product_count = tep_db_fetch_array($product_count_query); // if less than total similar prods displayed exist in current category, dont display (empty) infobox if ($product_count['total'] <= MAX_SIMILAR_PRODUCTS) { // Select the other products in the same category $products_query = tep_db_query("select p.products_id, p.products_image, p.products_price, p.products_model, pd.products_name, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc where p.products_id = pc.products_id and p.products_id = pd.products_id and p.products_id != '" . (int)$_GET['products_id'] . "' and p.products_status = '1' and pc.categories_id = '" . (int)$category_id . "' and pd.language_id = '" . (int)$languages_id . "' order by " . $sort_order . " limit " . MAX_SIMILAR_PRODUCTS ); // Write the output containing each of the products $products_string = ''; $count_products = 0; while ($products = tep_db_fetch_array($products_query)) { $p_name = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products['products_id']) . '">' . $products['products_name']. '</a>'; $p_price = '<span class="productSpecialPrice">'.$currencies->display_price($products['products_price'], tep_get_tax_rate($products['products_tax_class_id'])).'</span>'; $ratings = 0; $rating_query = tep_db_query("select count(*) as count, sum(reviews_rating) as total from " . TABLE_REVIEWS . " where products_id = '" . (int)$listing['products_id'] . "'"); //$rating_query = tep_db_query("select count(*) as count, sum(reviews_rating) as total from " . TABLE_REVIEWS . " where products_id = '103'"); $rating_result = tep_db_fetch_array($rating_query); if($rating_result['count'] > 0) { $ratings = round(($rating_result['total'] / $rating_result['count']), 2); } if ($products['products_id'] != $_GET['products_id']) { $products_string .= '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products["products_id"]) . '">' . tep_image(DIR_WS_IMAGES . $products['products_image'], $orders['products_name'], TINY_IMAGE_WIDTH, TINY_IMAGE_HEIGHT) . '<br>' . $p_name. '<br>' . tep_image(DIR_WS_IMAGES . 'stars_' . $ratings . '.gif' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $ratings)) . '<br>'.$p_price.'</a><br>'; $count_products++; } } ?> <!-- similar_products //--> <tr> <td> <div width="100%"> <?php $info_box_contents = array(); $info_box_contents[] = array('text' => '<strong>'. BOX_HEADING_SIMILAR_PRODUCTS .'</strong>'); new infoBoxHeading($info_box_contents, false, false); ?> <? tep_draw_heading_top_3();?> <?php $info_box_contents = array(); $info_box_contents[] = array('align' => 'center', 'params' => '', 'text' => $products_string ); new infoBox($info_box_contents); ?> <? tep_draw_heading_bottom_3();?> </div> </td> </tr> <? } // END PROD TOTAL (WITHIN CURRENT CATEGORY) CHECK ?> <!-- similar_products_eof //--> HERE is my "similar products" attempt in changing the code <?php /* $Id: similar_products.php,v 1.0 2004/06/06 jck Exp $ Based on whats_new.php,v 1.31 by hpdl osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2004 osCommerce Released under the GNU General Public License */ // Set the sort order for the display switch(SIMILAR_PRODUCTS_ORDER){ case 'Random': $sort_order = 'RAND() '; break; case 'Products ID': $sort_order = 'p.products_id '; break; case 'Model Number': $sort_order = 'p.products_model '; break; case 'Price': $sort_order = 'p.products_price '; break; case 'Date Added': $sort_order = 'p.products_date_added '; break; case 'Last Modified': $sort_order = 'p.products_last_modified '; break; case 'Products Ordered': $sort_order = 'p.products_ordered '; break; case 'Products Name': $sort_order = 'pd.products_name '; break; case 'Products Viewed': $sort_order = 'pd.products_viewed '; break; default: $sort_order = 'RAND() '; } // switch switch(SIMILAR_PRODUCTS_SORT_ORDER){ case 'Ascending': $sort_order .= 'asc'; break; case 'Descending': $sort_order .= 'desc'; break; default: $sort_order .= 'asc'; } // switch // Find the id # of the category that the current product is in $category_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . (int)$_GET['products_id'] . "'" ); $category = tep_db_fetch_array($category_query); $category_id = $category['categories_id']; $product_count_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc where p.products_id = pc.products_id and p.products_id = pd.products_id and p.products_id != '" . (int)$_GET['products_id'] . "' and p.products_status = '1' and pc.categories_id = '" . (int)$category_id . "' and pd.language_id = '". (int)$languages_id ."'" ); $product_count = tep_db_fetch_array($product_count_query); // if less than total similar prods displayed exist in current category, dont display (empty) infobox if ($product_count['total'] <= MAX_SIMILAR_PRODUCTS) { // Select the other products in the same category $products_query = tep_db_query("select p.products_id, p.products_image, p.products_price, p.products_model, pd.products_name, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " pc where p.products_id = pc.products_id and p.products_id = pd.products_id and p.products_id != '" . (int)$_GET['products_id'] . "' and p.products_status = '1' and pc.categories_id = '" . (int)$category_id . "' and pd.language_id = '" . (int)$languages_id . "' order by " . $sort_order . " limit " . MAX_SIMILAR_PRODUCTS ); // Write the output containing each of the products $count_products = 0; ?> <!-- similar_products //--> <tr> <td> <?php $info_box_contents = array(); $info_box_contents[] = array('text' => '<strong>'. BOX_HEADING_SIMILAR_PRODUCTS .'</strong>'); new infoBoxHeading($info_box_contents); ?> <? tep_draw_heading_top_3();?> <?php $row = 0; $col = 0; while ($products = tep_db_fetch_array($products_query)) { $products['products_name'] = tep_get_products_name($products['products_id']); $p_id = $product['products_id']; $p_pic = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $products['products_image'], $products['products_name'], TINYL_IMAGE_WIDTH, TINY_IMAGE_HEIGHT) . '</a>'; $p_name = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products['products_id']) . '">' . $products['products_name']. '</a>'; $p_price = '<span class="productSpecialPrice">'.$currencies->display_price($products['products_price'], tep_get_tax_rate($products['products_tax_class_id'])).'</span>'; $products_reviews_query = tep_db_query("select r.reviews_rating from " . TABLE_REVIEWS . " r, " . TABLE_PRODUCTS . " p where r.products_id = " . (int)$orders['products_id'] . ""); $products_reviews = tep_db_fetch_array($products_reviews_query); $products_reviews_rating = (($products_reviews['reviews_rating'] >= '1') ? tep_image(DIR_WS_IMAGES . 'stars_' . $products_reviews['reviews_rating'] . '.gif' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $products_reviews['reviews_rating'])) : tep_image(DIR_WS_IMAGES . 'stars_0.gif' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, '0'))); if ($products['products_id'] != $_GET['products_id']) { $info_box_contents = array(); $info_box_contents[$row][$col] = array('align' => 'center', 'params' => '', 'text' =>'<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products["products_id"]) . '">' . tep_image(DIR_WS_IMAGES . $products['products_image'], $products['products_name'], TINY_IMAGE_WIDTH, TINY_IMAGE_HEIGHT) . '<br>' . $products['products_name'] . '<br>' . $products_reviews_rating . '<br>'.$p_price.'</a>'); $col ++; if ($col >= 1) { $col = 0; $row ++; } $count_products++; } } new infoBox($info_box_contents); ?> <? tep_draw_heading_bottom_3();?> </td> </tr> <?php } // END PROD TOTAL (WITHIN CURRENT CATEGORY) CHECK ?> <!-- similar_products_eof //--> And just in case someone wants to see how my "Others also bought" code looks like <?php /* $Id: also_purchased_products.php,v 1.21 2003/02/12 23:55:58 hpdl Exp $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ if (isset($HTTP_GET_VARS['products_id'])) { $orders_query = tep_db_query("select p.products_id, p.products_image, p.products_price, p.products_tax_class_id from " . TABLE_ORDERS_PRODUCTS . " opa, " . TABLE_ORDERS_PRODUCTS . " opb, " . TABLE_ORDERS . " o, " . TABLE_PRODUCTS . " p where opa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and opa.orders_id = opb.orders_id and opb.products_id != '" . (int)$HTTP_GET_VARS['products_id'] . "' and opb.products_id = p.products_id and opb.orders_id = o.orders_id and p.products_status = '1' group by p.products_id order by o.date_purchased desc limit " . MAX_DISPLAY_ALSO_PURCHASED); $num_products_ordered = tep_db_num_rows($orders_query); if ($num_products_ordered >= MIN_DISPLAY_ALSO_PURCHASED) { ?> <!-- also_purchased_products //--> <tr> <td> <?php $info_box_contents = array(); $info_box_contents[] = array('text' => '<strong>Others Also Bought</strong>'); new contentBoxHeading($info_box_contents); ?> <? tep_draw_heading_top_3();?> <?php $row = 0; $col = 0; $info_box_contents = array(); while ($orders = tep_db_fetch_array($orders_query)) { $orders['products_name'] = tep_get_products_name($orders['products_id']); $p_id = $product['products_id']; $p_pic = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $orders['products_image'], $orders['products_name'], TINYL_IMAGE_WIDTH, TINY_IMAGE_HEIGHT) . '</a>'; $p_name = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders['products_id']) . '">' . $orders['products_name']. '</a>'; $p_price = '<span class="productSpecialPrice">'.$currencies->display_price($orders['products_price'], tep_get_tax_rate($orders['products_tax_class_id'])).'</span>'; $orders_reviews_query = tep_db_query("select r.reviews_rating from " . TABLE_REVIEWS . " r, " . TABLE_PRODUCTS . " p where r.products_id = " . (int)$orders['products_id'] . ""); $orders_reviews = tep_db_fetch_array($orders_reviews_query); $orders_reviews_rating = (($orders_reviews['reviews_rating'] >= '1') ? tep_image(DIR_WS_IMAGES . 'stars_' . $orders_reviews['reviews_rating'] . '.gif' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $orders_reviews['reviews_rating'])) : tep_image(DIR_WS_IMAGES . 'stars_0.gif' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, '0'))); $orders['products_name'] = tep_get_products_name($orders['products_id']); $info_box_contents[$row][$col] = array('align' => 'center', 'params' => '', 'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $orders["products_id"]) . '">' . tep_image(DIR_WS_IMAGES . $orders['products_image'], $orders['products_name'], TINY_IMAGE_WIDTH, TINY_IMAGE_HEIGHT) . '<br>' . $orders['products_name'] . '<br>' . $orders_reviews_rating . '<br>'.$p_price.'</a>'); $col ++; if ($col >= 1) { $col = 0; $row ++; } } new contentBox($info_box_contents); ?> <? tep_draw_heading_bottom_3();?> </td> </tr> <!-- also_purchased_products_eof //--> <?php } } ?> Thank you in advance, AE
Recommended Posts
Archived
This topic is now archived and is closed to further replies.