Out of Stock items still show

Modules, Add-ons and custom code that's more than just a quick hack or Mod.
Post Reply
marbles
Posts: 10
Joined: Wed Jun 23, 2010 8:16 pm

Out of Stock items still show

Post by marbles »

This place is like...an oasis. Y'know, you wander round the ISC desert for a year or so, getting nowhere, forever lost. Then suddenly out of the haze, and just as you are about to lie down in the sand and perish, along comes this forum! Thank you so much Martin...(and I aint forgotten your Royal Mail module, just need to iron out some shooz 1st to get my shop working)

I tried in the desert for an answer but all I found was sand!

I can't seem to get products to disappear when their stock levels reach 0.
I had a look at the code mentioned in the 'desert' but could not locate the suggested code to change things -

includes/classes/class.category.php

$query = "
SELECT
COUNT(DISTINCT ca.productid) AS numproducts
FROM
[|PREFIX|]categoryassociations ca
INNER JOIN [|PREFIX|]products p USE INDEX (PRIMARY) ON p.productid = ca.productid
WHERE
p.prodvisible = 1 AND
ca.categoryid IN (" . $this->GetProductCategoryIds() . ")
";

I am using version 5.5.4 ultimate.
Could one of you fine chaps offer any clues here?
Interspire cart 5.5.4 Ultimate
Martin
Site Admin
Site Admin
Posts: 1854
Joined: Wed Jun 17, 2009 6:30 pm
Location: South Yorkshire UK
Contact:

Re: Out of Stock items still show

Post by Martin »

Did a very quick reconnoitre into the class.category.php file and if the code you originally suggested is anything to go by, they've broken up the way the SQL is generated into sub-functions.

You might want to try this:
Find (around line 153 - 170)

Code: Select all

		/**
		 * Generate the SQL required to show products from the current category.
		 *
		 * @return string The generated SQL to be piped in to a query to fetch products.
		 */
		private function getProductWhereSQLRestriction()
		{
			$sql = 'p.prodvisible=1 AND ca.categoryid IN ('.$this->GetProductCategoryIds().')';

			if(!empty($_GET['price_min'])) {
				$sql .= " AND p.prodcalculatedprice >= '".(int)$_REQUEST['price_min']."'";
			}

			if(!empty($_GET['price_max'])) {
				$sql .= " AND p.prodcalculatedprice <= '".(int)$_REQUEST['price_max']."'";
			}

			if(!empty($_GET['price_max']) || !empty($_GET['price_min'])) {
				$sql .= ' AND p.prodhideprice=0';
			}

			return $sql;
		}



Replace this line:

Code: Select all

$sql = 'p.prodvisible=1 AND ca.categoryid IN ('.$this->GetProductCategoryIds().')';
with this:

Code: Select all

$sql = 'p.prodvisible=1 AND p.prodcurrentinv > 0 AND ca.categoryid IN ('.$this->GetProductCategoryIds().')';

Think that might do it.
marbles
Posts: 10
Joined: Wed Jun 23, 2010 8:16 pm

Re: Out of Stock items still show

Post by marbles »

Thanks very much for replying to my plea.
I tried that but no joy I'm afraid.
I tried controlling 'inventory by variation' and set all variations (sizes) to 0 also, but apart from the sizing saying unavailable the item still appears on the site.
Again, the only way I can hide the product seems to be to untick the visibility of the product in control panel - view products area. It would be so much easier if it would automatically disappear when stock hits 0.
Interspire cart 5.5.4 Ultimate
Post Reply