Jump to content

Random Prod Mod

Recommended Posts

Guest tbladecki

I want to set up the Featured Prod and the Latest products to only show items that are in stock as my inventory is very come and go. I do not want to have to edit each item sep as I get them in to show in the Latest products, but at the same time and I do not want the "featured products" that are out of stock to come up either. I think it is bad that when a customer clicks on a Latest or featured item it says "out of stock" So here is what I have so far:

I founf the part of the code in the randProd.inc file:

$randProd= $db->select("SELECT name, image, productId FROM ".$glob['dbprefix']."CubeCart_inventory ".$whereClause."ORDER BY RAND(".$seed.") LIMIT 1");

and I thought that I fixed it by changing to this:

$randProd= $db->select("SELECT name, image, productId, stock_level FROM ".$glob['dbprefix']."CubeCart_inventory WHERE stock_level >0 ".$whereClause." ORDER BY RAND(".$seed.") LIMIT 1");

which does part of it.. it limits only the "Featured products" that are in stock to show, but (of course you knew this was coming :D) When you click on a cat to view all items it gives me an SQL error.

I also did somthing similar in the lastest products area and the same result, so I can only assume that this code is used by a number of differnt files and it is where ALL the cat id #'s come from, while viewing the products and cats???

If that is the case I am having some trouble trying to get this to work for me. It really should not be this hard but I have only had 50% luck with making the change.

Please help as this has been a thorn for me for several days now

Link to comment
Share on other sites

Guest tbladecki

I appreciate the reply, however this is not exactly what i am looking for. I am intrested in the coding to simply select items that are in stock and allow them to be listed, and if not in stock just to ignore the item when it comes to teh featured and latest products.

I have all of my items set for the latest items as my inventory in up and down between in/out of stock, so when I get new items back in stock I just want them to appear on the home page.

It should not really be that hard, but i can only get 1/2 of it to work because to is using the SQL for the veiwproduct code as well and this is where the problem is coming from

I am still working on it but i have not solved it, just looking for ideas that i can try to reslove this.

Thank you

Link to comment
Share on other sites

the variable $whereClause in your query statement is indeed a WHERE clause, defined in the section above, as you know. This kicks in when you visit a category, as it checks to see if there are products in that category.

Your problem may be in SQL syntax, since WHERE ... WHERE ... doesn't work :) should be WHERE ... AND WHERE ...

You might try this:

$randProd= $db->select("SELECT name, image, productId, stock_level FROM ".$glob['dbprefix']."CubeCart_inventory WHERE stock_level >0 AND".$whereClause." ORDER BY RAND(".$seed.") LIMIT 1");

Also, remember that it is always useful when you are getting an error, to post the error message.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...