Jump to content

Link to open a random products


Recommended Posts

Well, I think you can go 2 ways:

1- Display a random product link in the first place:

In your hook function, use some query to get a random product link, like

SELECT p.id_product, pl-link_rewrite
FROM '._DB_PREFIX_.'product p
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (p.id_product = pl.id_product)
WHERE id_lang = '.$this->context->language->id. '
ORDER BY RAND()
LIMIT 1'

After that, assign those variables in the template, and call $link->getProductLink as you can see, for example, in the product-lit.tpl file for each product.

 

 

This way, you have a random link

 

2- Randomize the link after it's clicked.

Basically, you re-submit your page, and in the hook, if a certain value (say, getRandom) is submit, you use the same query as before to get those values. Then, instead of assigning them, you use $this->context->link->getProductLink with those params, and finally do a header("location: $productLinkGoesHere").

 

It's up to you to choose ;)

Link to comment
Share on other sites

×
×
  • Create New...