Jump to content

Featured product query


Paul Owen

Recommended Posts

OK, found that which kind of works, shame some of the products have an image that says 'no image available'

 

Is it possible to add to that code to stop it picking from certain categories?

 

Is there a function that will return category id then I could use that I think to stop it picking featured products from certain categories?

Link to comment
Share on other sites

From the statements that you uncommented, this statement:

if($image && !strpos($image,"noimage")) {

is supposed to do the trick.

 

But I now see that this sequence of statements was commented out because it works on the premise that several products could be returned from the query -- only one randomly chosen product is returned from the query. So, re-comment those lines.

 

The two statements following that group of commented statements do the same thing, but has no test for an image. Let's add it.

$image = $this->getProductImage($random_product[0]['product_id']);
if(strpos($image,"noimage") !== false) {
  if ($p < 15) { $p++; $this->_displayRandomProduct($p); } // After 15 tries, it will give up
}
$product = $random_product[0]; // Important to have this statement here.

The thing about recursion into a function, each entry into the function creates a new set of variables used by the function. So, when exiting the function, the prior values of the function are restored. That plays havoc on keeping important values as you regress. So, one more statement to add after the top line:

private function _displayRandomProduct($p=0) {
  static $random_product = null; static $image = null;

"Can CubeCart limit the random selection from arbitrarily selected categories?"

 

No, not as coded.

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.

Guest
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...