Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

"similar" & "Others also bought" infobox don't display special price but regular price.


aelalfy1989

Recommended Posts

Posted

Hi,

 

I was wondering if someone can help me solve this issue, my "similar products" & "Others also bought" infobox don't display special price but regular price. I want the price displayed in these boxes to be the special price that I made. I'll put both codes as well as my code for my "top seller", which have the special price in it and its working.

 

OTHERS ALSO BOUGHT CODE:

 

<?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, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_ORDERS_PRODUCTS . " opa, " . TABLE_ORDERS_PRODUCTS . " opb, " . TABLE_ORDERS . " o, " . TABLE_PRODUCTS . " p, " . TABLE_SPECIALS . " s 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 = $products['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')));

       $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
   }
 }
?>

 

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


// 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
                                 );



?>
<!-- similar_products //-->
          <tr>
               <td>
<?php 
           	    $info_box_contents = array();
    $info_box_contents[] = array('text' => '<strong>'. BOX_HEADING_SIMILAR_PRODUCTS .'</strong>');

    new contentBoxHeading($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 //-->

 

TOP SELLER CODE:

 

<?php
/*
 $Id: best_sellers.php 1739 2007-12-20 00:52:16Z hpdl $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 if (isset($current_category_id) && ($current_category_id > 0)) {
   $best_sellers_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price, pd.products_name 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_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and '" . (int)$current_category_id . "' in (c.categories_id, c.parent_id) order by p.products_ordered desc, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);
 } else {
   $best_sellers_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price, pd.products_name from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' order by p.products_ordered desc, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);
 }

 if (tep_db_num_rows($best_sellers_query) >= MIN_DISPLAY_BESTSELLERS) {
?>

<!-- best_sellers //-->
         <tr>
           <td>

<?php

   $info_box_contents = array();
   $info_box_contents[] = array('text' => BOX_HEADING_BESTSELLERS);
  new infoBoxHeading($info_box_contents);


?>
<? tep_draw_heading_top_3();?>	
<?php

	$row = 0;
     $col = 0;

 $info_box_contents = array();	  
      while ($best_sellers = tep_db_fetch_array($best_sellers_query)) {
$best_sellers['products_name'] = tep_get_products_name($best_sellers['products_id']);

$p_id = $product['products_id'];	

 $p_pic = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $best_sellers['products_image'], $best_sellers['products_name'], TINYL_IMAGE_WIDTH, TINY_IMAGE_HEIGHT) . '</a>';

 $p_name = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id']) . '">' . $best_sellers['products_name']. '</a>';

 $p_price = '<span class="productSpecialPrice">' . $currencies->display_price($best_sellers['products_price'], tep_get_tax_rate($best_sellers['products_tax_class_id'])) . '</span>';


  $best_sellers_reviews_query = tep_db_query("select r.reviews_rating from " . TABLE_REVIEWS . " r, " . TABLE_PRODUCTS . " p where r.products_id = " . (int)$best_sellers['products_id'] . "");
         $best_sellers_reviews = tep_db_fetch_array($best_sellers_reviews_query);
         $best_sellers_reviews_rating = (($best_sellers_reviews['reviews_rating'] >= '1') ? tep_image(DIR_WS_IMAGES . 'stars_' . $best_sellers_reviews['reviews_rating'] . '.gif' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $best_sellers_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=' . $best_sellers["products_id"]) . '">' . tep_image(DIR_WS_IMAGES . $best_sellers['products_image'], $best_sellers['products_name'], TINY_IMAGE_WIDTH, TINY_IMAGE_HEIGHT) . '<br>' . $best_sellers['products_name'] . '<br>' . $best_sellers_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>
<!-- best_sellers_eof //-->

<?php
 }
?>

Thank you in advance,

AE

Posted

Ahmed,

 

I have been reading your posts, and although every questions is important..it seems like you're trying to re-invent the wheel.

 

The Matching Products and X-sell Contributions have been in use for a long time and work really well. The additional info box contribution also works really well.

 

So, my question is...............why not just use those instead of posting for help to change the code on your site to do something that has already been done.

 

 

My apologies if I am reading your posts wrong, 34 posts and most are on code changes that are already realized.

 

 

Chris

Posted

Ahmed,

 

I have been reading your posts, and although every questions is important..it seems like you're trying to re-invent the wheel.

 

The Matching Products and X-sell Contributions have been in use for a long time and work really well. The additional info box contribution also works really well.

 

So, my question is...............why not just use those instead of posting for help to change the code on your site to do something that has already been done.

 

 

My apologies if I am reading your posts wrong, 34 posts and most are on code changes that are already realized.

 

 

Chris

 

Hey Chris,

 

I have searched for contributions and have downloaded some contributions and worked with them to figure this issue but they don't seem to work fine. I'm almost done all my problems and with the help of other members i was able to excel in producing proper infoboxes. thanks to them I was able to create a "top sellers" box which at the same time helped me fix my others also bought, similar products and specials box. So In conclusion, contributions only give me general solutions i used those along with help of members here to achieve what I need. All I'm looking for now is what I need to do to fix my price issue. what do you suggest for me to do? Download contributions? i read about it and didn't find a solution for that. what do you suggest, sir?

 

Thanks

Thank you in advance,

AE

Posted

Ahmed,

 

I am sorry if my questions offended you. I agree that there is not a contribution tailor made to everyone's needs, however, MOST offer the basis to build on and customize to suit your needs.

 

 

Chris

Posted

Hi,

 

I was wondering if someone can help me solve this issue, my "similar products" & "Others also bought" infobox don't display special price but regular price. I want the price displayed in these boxes to be the special price that I made. I'll put both codes as well as my code for my "top seller", which have the special price in it and its working.

Examine the query strings in the top sellers box and see how can modify the other query strings to make it work. This is a good practice for you to learn from.

Posted

Ahmed,

 

I am sorry if my questions offended you. I agree that there is not a contribution tailor made to everyone's needs, however, MOST offer the basis to build on and customize to suit your needs.

 

 

Chris

 

Hey no offence taken at all. You last post clearly address what I have been doing. I have taken contributions from best sellers and similar products and edit them to change the appearance as well as the code to adjust font and so on. Yet no contirbution can help me with the issue that I'm facing, and since i'm new to OSC and programming, its hard for me to do the changes. I have tried to change the code many times to address my issue with no success. Anyways no offence taken.

 

 

Examine the query strings in the top sellers box and see how can modify the other query strings to make it work. This is a good practice for you to learn from.

 

 

Hey, thanks for your reply first of all. I know its the query string that needs to be adjusted, I have tried this

 

	$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,  
				 " . TABLE_SPECIALS . " s,
                                        " . 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

 

instead of

 

 $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

 

But didn't work. I know it has to do with the specials table. But I don't know how to write it properly. As I mentioned above, I'm not a programmer. I can do tr, td, table stuff rearranging things but no php if statements or such.

Thank you in advance,

AE

Posted

What about this is different?

p.products_tax_class_id,                                   if(s.status, s.specials_new_products_price, p.products_price) as products_price,                                    from " . TABLE_PRODUCTS . " p,                                           " . TABLE_SPECIALS . " s,

Posted

What about this is different?

p.products_tax_class_id,                                   if(s.status, s.specials_new_products_price, p.products_price) as products_price,                                    from " . TABLE_PRODUCTS . " p,                                           " . TABLE_SPECIALS . " s,

 

 

Hey sorry im not following that part. I don't get the point. Is this organized by order? maybe I have to switch the table specials with the table products? Sorry i don't understand this part of the code at all. I'm just trying to notice pattern so i can work with something

Thank you in advance,

AE

Posted

This is part of the query from your top sellers

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,

This is what you tried to do that failed

p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p, " . TABLE_SPECIALS . " s,

What is different between them?

Posted

This is part of the query from your top sellers

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,

This is what you tried to do that failed

p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price from " . TABLE_PRODUCTS . " p, " . TABLE_SPECIALS . " s,

What is different between them?

 

 

"left join" for instance and on p.products_id = s.products_id. But I dont understand what these are for and therefore didn't include them. I tried to include on p.products_id = s.products_id but I don't think it worked. I didn't include the "left join" because it has to do with the table_products and that was already in my string so I thought it works. also I didn't think I need to change the table_products part. I thought my main thing is to somehow include table_specials. Am I wrong?

Thank you in advance,

AE

Posted

"left join" for instance and on p.products_id = s.products_id. But I dont understand what these are for and therefore didn't include them. I tried to include on p.products_id = s.products_id but I don't think it worked. I didn't include the "left join" because it has to do with the table_products and that was already in my string so I thought it works. also I didn't think I need to change the table_products part. I thought my main thing is to somehow include table_specials. Am I wrong?

I see a lot of think and thought in there. Did it ever occur to you to think about trying it?

Posted

Hi,

 

Thanks for the help I finally made it work for both infoboxes. now the question is and thats my final concern. I notice that for these info boxes, the query string is all that work really. cuz everything else is just for appearance mainly. so the query string is what determines what the infobox will do and how it will do it. I'm starting to understand the query string itself. I can write the intial part. to get the product id, product name, image and so on. But I want to make my infobox get the most popular products from one category how would I do that? so in summary, its called "popular accessories" infobox and it basically gets the most popoluar accessories from my accessories category and its subcategories. Do you know what I mean?

 

So this is how I would start my query,

 

$products_query = tep_db_query("select p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price, pd.products_name from " . TABLE_PRODUCTS . " p left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd,

 

This will generate all the images, names, prices, and so on but how do i tell it to generate all the products from one category?

 

Here is what I would write above that string:

 

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

 

Which wil find the category but I don't know how to tell it to just use a specific category lets say #3.

 

thanks in advance for the tips you may give me.

Thank you in advance,

AE

Posted

You are doing far too much work something that is already done. Your top sellers or best sellers does this. When you go into a category/subcategory it pulls the best sellers from that category.

 

Why are you trying to recreate it?

Posted

You are doing far too much work something that is already done. Your top sellers or best sellers does this. When you go into a category/subcategory it pulls the best sellers from that category.

 

Why are you trying to recreate it?

 

Hey I noticed that too, I wanted to use that code. But i want to create the "popular accessories" infobox on my main page (store front), and have it access my "accessories" category and its subcategories and get the most popular accessories. Based on most viewed, most bought. most reviewed, etc...

Thank you in advance,

AE

Posted

Well if you want to get products from just 1 category then you will need to get that category_id and use that to search the database. If that category has subcats then you search for the main category_id and the parent_id. example category Hardware has an id of 1. Keyboards has an id of 8. Keyboards parent_id is 1.

 

Doing it this means it will only search the category you add to the query string. It will not change no matter what you click on. Am I understanding you correctly?

Posted

Well if you want to get products from just 1 category then you will need to get that category_id and use that to search the database. If that category has subcats then you search for the main category_id and the parent_id. example category Hardware has an id of 1. Keyboards has an id of 8. Keyboards parent_id is 1.

 

Doing it this means it will only search the category you add to the query string. It will not change no matter what you click on. Am I understanding you correctly?

 

Yea I want it to get products from one category and all its subcategories. assuming I know the Id of that category. How would the string be ? My old web designer wrote a whole code for this infobox which I don't get whatsoever. He didn't make it work though. Here is the code. If you can help me write the string or help me make that code work that would be great. So either the code below or the string will work. If you can help me write a string, I can write the rest of the code for the infobox.

 

Here is the code he did:

 

<?php	

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = $current_category_id and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by cd.categories_name ASC, RAND(1000), sort_order, cd.categories_name");

$categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '0' and c.categories_id = 5 and c.categories_id = cd.categories_id and cd.language_id='" . (int)$languages_id ."' order by cd.categories_name ASC, RAND(1000), sort_order, cd.categories_name");

 	while ($categories = tep_db_fetch_array($categories_query)) {
	$rows = 0;
	$p_cnt = tep_db_query("SELECT COUNT(*) AS total FROM products_to_categories AS pc, products_description AS pd WHERE pc.categories_id = ".$categories['categories_id']." AND pc.products_id = pd.products_id AND pd.language_id = 1");
	$getSize = tep_db_fetch_array($p_cnt);

	if($getSize['total'] <= 0) 
		continue;
	$p_load = tep_db_query("SELECT pc.products_id, pd.products_name FROM products_to_categories AS pc, products_description AS pd WHERE pc.categories_id = ".$categories['categories_id']." AND pc.products_id = pd.products_id AND pd.language_id = 1");

?>

<!-- best_sellers //-->
	 <tr>
           <td valign="top">
<?php            		
	$info_box_contents = array();
   	$info_box_contents[] = array('text' => '<strong>Popular Accessories</strong>');
	new infoBoxHeading($info_box_contents, false, false);
	tep_draw_heading_top_3();


   	$bestsellers_list = '<ul>';		
	while($best_sellers = tep_db_fetch_array($p_load)) {

		$rows++;

		if ($count ==0 ) 
			$kk=' class="prod_new_box" style="line-height:20px"'; 
		else 
			$kk=' class="prod_new_box" style="line-height:20px"'; 

		if ($kk!='') {
			$bestsellers_list .= '<li'.$kk.'><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id']) . '">' . substr($best_sellers['products_name'], 0, MAX_DESCR_BESTS) . '</a></li>';
		}
		else {
			$bestsellers_list .= '<li'.$kk.'><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $best_sellers['products_id']) . '">' . substr($best_sellers['products_name'],0,MAX_DESCR_BESTS) . '</a></li>';
		}

	}
	$bestsellers_list .= '</ul>'; 

	$info_box_contents = array();
   	$info_box_contents[] = array('text' => $bestsellers_list);
	new infoBox($info_box_contents);

	tep_draw_heading_bottom_3();
?>
	</td>
         </tr>
      		<tr><td>  </td></tr>
<!-- best_sellers_eof //-->
<?php		
}
?>

 

THANKS IN ADVANCE

Thank you in advance,

AE

Posted

Try this. Your category_id for accessories is 18.

<?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
*/

// category_id to use
/*
 To find the category_id do one of the following
 Stock OSC Install
   Click on the main category you want.
In the address bar look for cPath=1 or whatever number.
 With SEO installed
   Click on the main category you want.
In the address bar look for hardware-c-1 or whatever number.

 Put that number below. Any subcategories will be added in the query string.
*/
 $sim_cat_id = '18';

// Select products in the desired category/subcategory
 $products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price, pd.products_name 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_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and '" . (int)$sim_cat_id . "' in (c.categories_id, c.parent_id) order by p.products_ordered desc, pd.products_name limit " . MAX_DISPLAY_BESTSELLERS);
?>
<!-- similar_products //-->
         <tr>
           <td>
<?php 
 $info_box_contents = array();
 $info_box_contents[] = array('text' => '<strong>'. BOX_HEADING_SIMILAR_PRODUCTS .'</strong>');

 new contentBoxHeading($info_box_contents);

 echo tep_draw_heading_top_3(); 

 $rows = 0;
 $info_box_contents = array(); 
 while ($products = tep_db_fetch_array($products_query)) {
   if ($products['products_id'] != $_GET['products_id']) {
     $p_price = '<span class="productSpecialPrice">'.$currencies->display_price($products['products_price'], tep_get_tax_rate($products['products_tax_class_id'])).'</span>';
// Get products reviews rating 
     $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')));

     $rows++;
     $info_box_contents[] = 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']) . '<br>' . $products['products_name'] . '<br>' . $products_reviews_rating . '<br>'.$p_price.'</a>');
   }
 }

 new contentBox($info_box_contents);

 echo tep_draw_heading_bottom_3();
?>
           </td>
         </tr>
<!-- similar_products_eof //-->

Posted

Forget that last post. It should be

<?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
*/

// category_id to use
/*
 To find the category_id do one of the following
 Stock OSC Install
   Click on the main category you want.
In the address bar look for cPath=1 or whatever number.
 With SEO installed
   Click on the main category you want.
In the address bar look for hardware-c-1 or whatever number.

 Put that number below. Any subcategories will be added in the query string.
*/
 $sim_cat_id = '18';

// Select products in the desired category/subcategory
 $products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price, pd.products_name 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_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and '" . (int)$sim_cat_id . "' in (c.categories_id, c.parent_id) order by p.products_ordered desc, pd.products_name limit " . MAX_SIMILAR_PRODUCTS);

 if (tep_db_num_rows($products_query) >= MAX_SIMILAR_PRODUCTS) {
?>
<!-- similar_products //-->
         <tr>
           <td>
<?php 
   $info_box_contents = array();
   $info_box_contents[] = array('text' => '<strong>'. BOX_HEADING_SIMILAR_PRODUCTS .'</strong>');

   new contentBoxHeading($info_box_contents);

   echo tep_draw_heading_top_3(); 

   $rows = 0;
   $info_box_contents = array(); 
   while ($products = tep_db_fetch_array($products_query)) {
     if ($products['products_id'] != $_GET['products_id']) {
       $p_price = '<span class="productSpecialPrice">'.$currencies->display_price($products['products_price'], tep_get_tax_rate($products['products_tax_class_id'])).'</span>';
// Get products reviews rating 
       $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')));

       $rows++;
       $info_box_contents[] = 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']) . '<br>' . $products['products_name'] . '<br>' . $products_reviews_rating . '<br>'.$p_price.'</a>');
     }
   }

   new contentBox($info_box_contents);

   echo tep_draw_heading_bottom_3();
?>
           </td>
         </tr>
<!-- similar_products_eof //-->
<?php
 }
?>

Posted

Hey,

 

The code doesn't generate anything. Its the same thing that happened when I tried the code he wrote for me. It just leaves a blank space between my reviews infobox and my currency infobox. I dunno why tho. I'll include the code you gave me but with what I changed in attempt to make it work with no success (and yes of course i ran your code first but didn't work) and the left column code which is where the popular accessories infobox is. The left column code is a little weird coded. It looks unclean but it works so its fine.

 

<?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
*/

// category_id to use
/*
 To find the category_id do one of the following
 Stock OSC Install
   Click on the main category you want.
       In the address bar look for cPath=1 or whatever number.
 With SEO installed
   Click on the main category you want.
       In the address bar look for hardware-c-1 or whatever number.

 Put that number below. Any subcategories will be added in the query string.
*/
 $sim_cat_id = '18';

// Select products in the desired category/subcategory
 $products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price, pd.products_name 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_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and '" . (int)$sim_cat_id . "' in (c.categories_id, c.parent_id) order by p.products_ordered desc, pd.products_name limit " . MAX_SIMILAR_PRODUCTS);

 if (tep_db_num_rows($products_query) >= MAX_SIMILAR_PRODUCTS) {
?>
<!-- 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

   $rows = 0;
   $info_box_contents = array(); 
   while ($products = tep_db_fetch_array($products_query)) {
     if ($products['products_id'] != $_GET['products_id']) {
       $p_price = '<span class="productSpecialPrice">'.$currencies->display_price($products['products_price'], tep_get_tax_rate($products['products_tax_class_id'])).'</span>';
// Get products reviews rating 
       $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')));

       $rows++;
       $info_box_contents[] = 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']) . '<br>' . $products['products_name'] . '<br>' . $products_reviews_rating . '<br>'.$p_price.'</a>');
     }
   }

   new contentBox($info_box_contents);

   echo tep_draw_heading_bottom_3();
?>
           </td>
         </tr>
<!-- similar_products_eof //-->
<?php
 }
?>

 

 

LEFT COLUMN CODE:

 

<?php
/*
 $Id: column_left.php,v 1.15 2003/07/01 14:34:54 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/
?>
<table border="0"cellspacing="0" cellpadding="0" class="box_width_left">
<tr><td width="100%">
	<table border="0" cellspacing="0" cellpadding="0">
<?php
 if ((USE_CACHE == 'true') && empty($SID)) {
   echo tep_cache_categories_box();
 } else {
   include(DIR_WS_BOXES . 'categories_custom.php');
 }

?>
<tr><td height="9"></td></tr>
<tr><td>
<?php 

// -------------------------------------------------
 require(DIR_WS_BOXES . 'reviews.php');  

// -------------------------------------------------
 ?></td></tr>
<tr><td height="9"></td></tr>
<?php
// -------------------------------------------------
if (tep_session_is_registered('customer_id')) include(DIR_WS_BOXES . 'order_history.php'); 
?>
<tr><td height="9"></td></tr>
<tr><td><?php include(DIR_WS_BOXES . 'popular_accessories.php'); ?></td></tr>
<tr><td height="9"></td></tr>
<tr><td><?php
include(DIR_WS_BOXES . 'currencies.php');
?></td></tr>
<tr><td height="9"></td></tr>
<tr><td><?php
include(DIR_WS_BOXES . 'tell_a_friend.php');
?></td></tr>



	</table>
</td>
</tr>
</table>

Thank you in advance,

AE

Posted

Are you sure that is the right column_left.php? If you look at this page, click here, you will see that it works.

 

According to the code you posted your others also box is not listed in there. Looking at the source code you kinda have a mess going on.

Posted

Are you sure that is the right column_left.php? If you look at this page, click here, you will see that it works.

 

According to the code you posted your others also box is not listed in there. Looking at the source code you kinda have a mess going on.

 

 

No no no you are mixing it. The "similar" infobox that you saw on the products page, is from a different left column. I have a left column for the main page and a left column for the product page. And the similar products that you see is in reality the similar products in that same subcategory. Anyways the code i gave you is for the left column on the main page, and thats where the popular accessories is going to be. You think because you made the if statement >= MAX_SIMILAR_PRODUCTS that it doesn't work? but I thought atleast the header will show. let me try doing something. I changed the header code for that infobox.

 

from this:

 

 

$info_box_contents = array();

$info_box_contents[] = array('text' => '<strong>'. BOX_HEADING_SIMILAR_PRODUCTS .'</strong>');

new infoBoxHeading($info_box_contents);

 

to this:

 

$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:12px; font-weight:bold;">Popular Accessories</span>', strftime('%B')));

new infoBoxHeading($info_box_contents);

 

That way you don't get confused with the similar products on my products page. And below is the code with my changes.

 

ALSO I HAVE A FEELING THAT ITS NOT THE CODE ITS SOMETHING WITH THE COLUMN LEFT 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
*/

// category_id to use
/*
 To find the category_id do one of the following
 Stock OSC Install
   Click on the main category you want.
       In the address bar look for cPath=1 or whatever number.
 With SEO installed
   Click on the main category you want.
       In the address bar look for hardware-c-1 or whatever number.

 Put that number below. Any subcategories will be added in the query string.
*/
 $sim_cat_id = '18';

// Select products in the desired category/subcategory
 $products_query = tep_db_query("select distinct p.products_id, p.products_image, p.products_tax_class_id, if(s.status, s.specials_new_products_price, p.products_price) as products_price, pd.products_name 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_status = '1' and p.products_ordered > 0 and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and '" . (int)$sim_cat_id . "' in (c.categories_id, c.parent_id) order by p.products_ordered desc, pd.products_name limit " . MAX_SIMILAR_PRODUCTS);

 if (tep_db_num_rows($products_query) >= 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:12px; font-weight:bold;">Popular Accessories</span>', strftime('%B')));
new infoBoxHeading($info_box_contents);

?>
<? tep_draw_heading_top_3();?>	
<?php

   $rows = 0;
   $info_box_contents = array(); 
   while ($products = tep_db_fetch_array($products_query)) {
     if ($products['products_id'] != $_GET['products_id']) {
       $p_price = '<span class="productSpecialPrice">'.$currencies->display_price($products['products_price'], tep_get_tax_rate($products['products_tax_class_id'])).'</span>';
// Get products reviews rating 
       $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')));

       $rows++;
       $info_box_contents[] = 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']) . '<br>' . $products['products_name'] . '<br>' . $products_reviews_rating . '<br>'.$p_price.'</a>');
     }
   }

   new contentBox($info_box_contents);

   echo tep_draw_heading_bottom_3();
?>
           </td>
         </tr>
<!-- similar_products_eof //-->
<?php
 }
?>

Thank you in advance,

AE

Posted

But i want to create the "popular accessories" infobox on my main page (store front), and have it access my "accessories" category and its subcategories

 

 

No no no you are mixing it. The "similar" infobox that you saw on the products page, is from a different left column. I have a left column for the main page and a left column for the product page. And the similar products that you see is in reality the similar products in that same subcategory. Anyways the code i gave you is for the left column on the main page, and thats where the popular accessories is going to be.

Well obviously I have no clue what you are trying to do since you don't either.

 

If you want that on your main page, add it to that left column.

 

When you can clearly state exactly what it is you want let me know.

 

You think because you made the if statement >= MAX_SIMILAR_PRODUCTS that it doesn't work? but I thought atleast the header will show.

There you go thinking again. You really need to stop that.

 

The reason for that if statement is so that box shows ONLY if there are products to show. Or do you really want an empty box showing on your page?????

Posted

Well obviously I have no clue what you are trying to do since you don't either.

 

If you want that on your main page, add it to that left column.

 

When you can clearly state exactly what it is you want let me know.

 

 

There you go thinking again. You really need to stop that.

 

The reason for that if statement is so that box shows ONLY if there are products to show. Or do you really want an empty box showing on your page?????

 

 

Ok, I really don't know if you are on your period, but read all your replies to me, they are rude and non sense. I clearly stated a million times. I WANT AN INFOBOX that gets the most popular products from my accessories category. YES its the right left column and yes its good to think sometimes. I asked a question and wanted a nice reply. If you think you are smart and have the right to be rude, whatever I don't need your help. holy shit people need to stop being asses just because you know how to do something, doesn't give you the right. All I wanted was help, minus your rudeness and thinking you are smart. You don't want me thinking, as if you know me or own me. Are you crazy? I can think all I want. Plus when you told me to figure our the string you asked me to think. HAHA you are funny, you acually think you own me just because you know something I don't. Anyways Thanks for the above help. And I don't want any of your help anymore.

Thank you in advance,

AE

Archived

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

×
×
  • Create New...