Forums / General Questions / Question about hiding products where quantity is 0 from site search and a thank you!

Question about hiding products where quantity is 0 from site search and a thank you!

Views: 3,963

Results 1 to 9 of 9
2 May 2014, 5:55 PM
#1
thjco avatar

thjco

New Zenner

Join Date:
May 2014
Location:
Florida
Posts:
13
Plugin Contributions:
0

Question about hiding products where quantity is 0 from site search and a thank you!

Hi, this forum has been an absolute wealth of information since installing my first Zen Cart. I've been able to get every single bit of information I've needed here and am completely thrilled with the final result of my store.

I've found the last piece of information I need to truly finish it off but its from 2011 and doesn't seem to work on v1.5.1.

Simply put, I want sold items to be hidden from search results on the website but yet have the items remain on the site so they still appear in search results on Google or backlinks from other sites.

The original post with the same concept can be seen here- http://www.zen-cart.com/showthread.php?171530-Hide-sold-out-products-from-category-listings-and-search-without-disabling-product

There also was a solution, posted here- http://www.zen-cart.com/showthread.php?171530-Hide-sold-out-products-from-category-listings-and-search-without-disabling-product&p=979252#post979252

The solution posted was

and add the code around line 27 that is in red above the code in black:

[B] $alpha_sort .= " and p.products_quantity > 0 ";[/B]
if (!isset($select_column_list)) $select_column_list = "";


The line number has changed to 52 and when I insert the code as stated, it does not do the trick. Can someone please provide an update on where or how to implement this to make it functional?

Here is a screenshot of my code and you can see where I have copied that line of code to line 51 which appears to be the same thing as in my quoted post - <http://i.imgur.com/52iuU1P.jpg>

Since I only have 1 of most items, its important to me that links stay active in the Google search results but not on the website for searches. To see an example, you can go to the cart: <http://thehockeyjersey.co/store/> and then search for 'whalers' - I'd like the green jersey which has sold to no longer show up in the search results and future sold items going forward. 

Thank you for this great resource!!!
2 May 2014, 8:04 PM
#2
solo_400 avatar

solo_400

Zen Follower

Join Date:
Aug 2009
Posts:
369
Plugin Contributions:
0

Re: Question about hiding products where quantity is 0 from site search and a thank you!

I did this on my website and I had to change some files and some admin configurations :

  1. Admin/Configuration/Stock/Products status in Catalog when out of stock should be set to 1
    2.includes/index_filters/default_filter.php substitute everywhere p.products_status = 1 with p.products_status = 1 and p.products_quantity > 0
    3./includes/modules/pages/advanced_search_result : $where_str = " WHERE (p.products_status = 1 and p.products_quantity > 0 add condition p.products_quantity > 0
    4./includes/modules/product_prev_next.php : add p.products_quantity >= 1 to the query
    5./includes/pages/products_new/header.php : add p.products_quantity >= 1 to the query

Regarding old products in my case I had to manual update status :

update products set products_status = 1
where products_status = 0
and products_quantity = 0

REMEMBER! test all those changes on test environment first and backup your shop !

2 May 2014, 9:05 PM
#3
thjco avatar

thjco

New Zenner

Join Date:
May 2014
Location:
Florida
Posts:
13
Plugin Contributions:
0

Re: Question about hiding products where quantity is 0 from site search and a thank you!

Absolutely amazing work. I cant thank you enough. Took all of 2 minutes to get this in place.

Here is a link to a sold item - http://thehockeyjersey.co/store/index.php?main_page=product_info&cPath=6&products_id=28

...that you wont be finding in my sites search results any time soon!

And let it be known that I dont know the first thing about php.

Great work and I will be updating that old post with a link here for 1.5 users.

3 May 2014, 3:19 PM
#4
solo_400 avatar

solo_400

Zen Follower

Join Date:
Aug 2009
Posts:
369
Plugin Contributions:
0

Re: Question about hiding products where quantity is 0 from site search and a thank you!

I'm glad you did it and happy to help you :-)

8 Jul 2016, 3:33 PM
#5
mespe avatar

mespe

Zen Follower

Join Date:
Sep 2014
Location:
ohio
Posts:
216
Plugin Contributions:
0

Re: Question about hiding products where quantity is 0 from site search and a thank you!

solo_400:

I did this on my website and I had to change some files and some admin configurations :

  1. Admin/Configuration/Stock/Products status in Catalog when out of stock should be set to 1
    2.includes/index_filters/default_filter.php substitute everywhere p.products_status = 1 with p.products_status = 1 and p.products_quantity > 0
    3./includes/modules/pages/advanced_search_result : $where_str = " WHERE (p.products_status = 1 and p.products_quantity > 0 add condition p.products_quantity > 0
    4./includes/modules/product_prev_next.php : add p.products_quantity >= 1 to the query
    5./includes/pages/products_new/header.php : add p.products_quantity >= 1 to the query

Regarding old products in my case I had to manual update status :

update products set products_status = 1
where products_status = 0
and products_quantity = 0

This is what I want to do, but I am not clear as to what to put where in the files,

6 Jul 2020, 4:50 PM
#6
moosesoom avatar

moosesoom

New Zenner

Join Date:
Dec 2008
Location:
Rimini, Italy, Italy
Posts:
67
Plugin Contributions:
0

Re: Question about hiding products where quantity is 0 from site search and a thank you!

Giving life to an old thread....
it seems that's enough for 1.5.1 but not for 1.5.5e :(
Anybody here tried to hide out of stock products from search?
Many thanks, kind regards
Francesco

6 Jul 2020, 5:30 PM
#7
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,729
Plugin Contributions:
56

Re: Question about hiding products where quantity is 0 from site search and a thank you!

Edit
includes/modules/pages/advanced_search_result/header_php.php

There will be a block that starts with this:

$where_str = " WHERE (p.products_status = 1

just change it to

$where_str = " WHERE (p.products_status = 1
AND p.products_quantity > 0

And Bob's your uncle. :)

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

7 Jul 2020, 9:58 AM
#8
moosesoom avatar

moosesoom

New Zenner

Join Date:
Dec 2008
Location:
Rimini, Italy, Italy
Posts:
67
Plugin Contributions:
0

Re: Question about hiding products where quantity is 0 from site search and a thank you!

swguy:

Edit
includes/modules/pages/advanced_search_result/header_php.php

Not that simple....I found the solution by moving a die($where_str) all around the file:
If you installed **Stock_By_Attributes_Combined **plugin (as I did) you have to modify includes/classes/observers/auto.advanced_search_categories_custom_id.php also by adding the red part in following code

   $where_str .= "(p.products_status = 1
                  AND p.products_id = pd.products_id
                  AND pd.language_id = :languagesID
                  AND p.products_id = p2c.products_id
[B]                  AND p.products_quantity > 0
[/B]                  AND p2c.categories_id = c.categories_id
                  ";

And Bob's your uncle. :)

Great,didn't know this sentence.... :)

7 Jul 2020, 2:30 PM
#9
carlwhat avatar

carlwhat

zennedOut

Join Date:
Nov 2005
Location:
los angeles
Posts:
2,973
Plugin Contributions:
8

Re: Question about hiding products where quantity is 0 from site search and a thank you!

this is an issue that i have struggled with in the past. but hiding these items from site search does not really hide the items. google will still find them. your category listings will still show them, if you have a product feed for search engines, they will still be there, and heavens to betsy if those items make it to your best sellers list prior to having a 0 quantity.

from what i remember, v157 now has a facility for setting future date available, and inactivating items until the date comes. which could probably be easily modified to accommodate items that 0 quantity going into and out of stock. i remember looking at that modification, which i think makes use of cron jobs (scheduled jobs) to do its work, and thinking it is a good solution to a royal pain of a problem.

in the past (on live sites), these are some of the files (not all are base ZC files, but most are) i have had to modify to ensure that no items with 0 quantity or a future arrival date show up on a site:

googlefroogle.php
includes/index_filters/default_filter.php
includes/classes/db/mysql/define_queries.php
includes/modules/YOUR_TEMPLATE/new_products.php
includes/modules/YOUR_TEMPLATE/featured_products.php
includes/modules/YOUR_TEMPLATE/specials_index.php
includes/modules/pages/sitemapxml/sitemapxml_products.php
includes/modules/pages/advanced_search_result/header_php.php
includes/modules/pages/products_all/header_php.php
includes/modules/pages/product_info/header_php.php
includes/modules/pages/product_info/main_template_vars.php
includes/modules/pages/products_new/header_php.php
includes/modules/sideboxes/YOUR_TEMPLATE/whats_new.php
includes/modules/sideboxes/YOUR_TEMPLATE/best_sellers.php
includes/modules/product_prev_next.php
includes/functions/functions_lookups.php
includes/functions/functions_prices.php
includes/extra_datafiles/added_sql.php

having a product class would make this so much easier..... i think.....

best.

author of square Webpay, now with Apple Pay and Google Pay.
mXworks
donations: venmo or paypal accepted.
premium consistent excellent support. available for hire.