Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Similar products infobox question


aelalfy1989

Recommended Posts

Posted

Hi everyone,

 

I have a short question. I have a similar products infobox. I noticed that it works well except when there is only one product in a subcategory. I tried to change it without sucess. Initially I want it to check if there are other products within that subcategory. If not i want it to take products from a neighbouring subcategory. For example if I cell laptops. Assuming I have a 1 kind of dell computer so if there isn't anymore dell it should pick the neighbouring subcategory for example sony, etc. But if there is for example 1 other dell computer in that same subcategory and I allowed for 5 similar products to be displayed, it should first take that one dell product then 4 other products from other subcategories. I don't know if anyone understood what i said about but I really tried. I think this has to do with my query as well as my if statements within my code but I can't change it and make it work. Here is my code so far. Thanks in advance for the help.

 

<?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'];


// Select the other products in the same category

  		$products_query = tep_db_query("select p.products_id, 
                                  p.products_image,
                                  p.products_model,
                                  pd.products_name,
			   p.products_tax_class_id, 
			   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 . " 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
                                 );


?>
<!-- similar_products //-->
          <tr>
               <td>
<?php 
            $info_box_contents = array();
 $info_box_contents[] = array('align' => 'left', 'text' => sprintf('<span style="color:#fff; font-family: Lucida Grande, Lucida Sans Unicode, Arial, Verdana, sans-seri; font-size:13px; font-weight:bold;">Similar Products</span>', strftime('%B')));
new infoBoxHeading($info_box_contents);


?>
   <? tep_draw_heading_top_3();?>	

<?php


        $row = 0;
     		$col = 0;

           $info_box_contents = array();	
    while ($products = tep_db_fetch_array($products_query)) {
	 if ($products['products_id'] != $_GET['products_id']) {
$products['products_name'] = tep_get_products_name($products['products_id']);

 $p_id = $products['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'], TINY_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)$products['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')));


    $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 ++;
        }
}
}
    new contentBox($info_box_contents);
?>
   <? tep_draw_heading_bottom_3();?>	
  		   </td>
          </tr>
<?php
?>
<!-- similar_products_eof //-->

Thank you in advance,

AE

Posted

you want it to display upto 5 similar products with prioirty given to any product in the exact same category, and then to be filled by the other similar categories with the same parent category.

 

laptops>dell>dell1

dell2

dell3

laptops>acer>acer1

acer2

acer3

If i look at dell 1

 

you want simailr products to be dell2,dell3, acer1,acer2, acer3 correct?

 

I dont have a clue, other than the similar products will have to have some kind of rule saying select from parent category upto 5 sub cat products starting with products from the same sub category.

 

 

can anyone elaborate on the right code for this, or is it one of them things thats overly complicated to get that functionality.

Getting better with mods but no programmer am I.

Posted

you want it to display upto 5 similar products with prioirty given to any product in the exact same category, and then to be filled by the other similar categories with the same parent category.

 

laptops>dell>dell1

dell2

dell3

laptops>acer>acer1

acer2

acer3

If i look at dell 1

 

you want simailr products to be dell2,dell3, acer1,acer2, acer3 correct?

 

I dont have a clue, other than the similar products will have to have some kind of rule saying select from parent category upto 5 sub cat products starting with products from the same sub category.

 

 

can anyone elaborate on the right code for this, or is it one of them things thats overly complicated to get that functionality.

 

hey yea I have it set up to display how x number of products determined by me in the admin area. But assuming there are no products in that same subcategory it displays blank. I know that it needs an if statement

 

if products in same subcategory are >=5 display them else display some from subcategory and the rest from another. The second part is the confusing part because it has to do with the query string. the query string that I have only takes products from that one subcategory. how do I change it to make it first take products form the same subcategory then move on. thats my question reall.y

 

Anyways thanks for the reply, you seem very kind to atleast reply without knowing the answer. At least someone cares. :)

Thank you in advance,

AE

Posted

If you want related products shown, assign the related products for each product. If you only assign one, then only one is displayed. Assign 6, then 6 are displayed.

 

The contribution works as it is designed. It just takes the admin some time to pick related products. If I was going to do anything, I would try to merge this contribution with it:

 

http://addons.oscommerce.com/info/3410

 

Merging random products would ensure every product has optional products in the product info

 

 

 

Chris

Archived

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

×
×
  • Create New...