Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Products_viewed in product listing problem


Shuen

Recommended Posts

Posted

Hello, I'm totally new on PHP and I want to show the products_viewed counter under the buy now button in product_listing.php,

and It should sum the products_viewed value of all the language.

but when I add a sum(pd.products_viewed) as products_viewed in the $listing_sql,

The product_listing only shows one product, and sum all the products_viewed value of every product.

 

If I only add pd.products_viewed without sum(), The product listing looks fine, It seems work but It only shows the products_viewed value of the current language.

How can I make it calculate the products_viewed value of all languages?

 

I did a search for my problem but there are no any related result...

 

here is what i did:

in index.php around ln153

// We show them all

$listing_sql = "select " . $select_column_list . " sum(pd.products_viewed) as products_viewed, p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";

 

in product_listing.php

case 'PRODUCT_LIST_BUY_NOW':

$prod_list_contents .= '<br />' . tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id'])).

'<br /> Viewed : '$listing['products_viewed'] 'times';

break;

 

Any help will be appreciate~~and sorry for my bad english.

Posted

I can't help with the code but how about you try and do this for one product e.g. on the product page and when you get it working there you can try the product listing?

Posted

Actually I already tried this : http://addons.oscommerce.com/info/7579

It works in product_info.php for single item but i have no idea how to compound this function in product_listing.php

here is what I tried:

$listing_sql = "select " . $select_column_list . " sum(pd.products_viewed) as products_viewed from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and p2c.categories_id = '" . (int)$current_category_id . ", p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "'";

 

It just shows error...

Posted

what error is displayed???

 

Here it is:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and ' at line 1
select count(p.products_id) as total from products_description pd, products p left join manufacturers m on p.manufacturers_id = m.manufacturers_id left join specials s on p.products_id = s.products_id, products_to_categories p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and p2c.categories_id = '22, p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from products_description pd, products p left join manufacturers m on p.manufacturers_id = m.manufacturers_id left join specials s on p.products_id = s.products_id, products_to_categories p2c where p.products_status = '1' and p.products_id = p2c.products_id and pd.products_id = p2c.products_id and pd.language_id = '1' and p2c.categories_id = '22'

Posted

By any chance is the product it is showing the first product? or the last one?

If I only add sum(pd.products_viewed) as products_viewed, It only show for the first product ID. but it sum all the products_viewed value of every product.(If I have 10 products and have 1 products_viewed on each, It will show 10)

Archived

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

×
×
  • Create New...