How To Create a snippet that will display 8 random products.
How To Create a snippet that will display 8 random products.
I am trying to create a snippet along the lines of homenewproducts or homefeaturesproducts, that will display 8 random products.
Can anyone help me?
Thank You
Can anyone help me?
Thank You
-
- Posts: 744
- Joined: Thu Jun 18, 2009 8:59 am
Re: How To Create a snippet that will display 8 random products.
Copy and rename HomeFeaturedProducts.php to HomeRandomProducts.php, open it up, find
This may work right away (lol, fingers crossed!!) - but will likely need some tweaking.
All that has been done is removing the requirement that a product is featured for it to be shown, and setting the limit of products to 8 (this bit should work I hope)
Good luck, let us know how you get on
change to$query = "
SELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, pi.*, ".GetProdCustomerGroupPriceSQL()."
FROM [|PREFIX|]products p
LEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid AND pi.imageisthumb=1)
WHERE p.prodfeatured = '1' AND p.prodvisible='1'
".GetProdCustomerGroupPermissionsSQL()."
ORDER BY RAND()
";
$query .= $GLOBALS['ISC_CLASS_DB']->AddLimit(0, GetConfig('HomeFeaturedProducts'));
Then copy /templates/_master/panels/HomeFeaturedProducts.html to /templates/YOUR TEMPLATE/panels/HomeRandomProducts.html, and call as you would any another panel.$query = "
SELECT p.*, FLOOR(prodratingtotal/prodnumratings) AS prodavgrating, pi.*, ".GetProdCustomerGroupPriceSQL()."
FROM [|PREFIX|]products p
LEFT JOIN [|PREFIX|]product_images pi ON (p.productid=pi.imageprodid AND pi.imageisthumb=1)
WHERE p.prodvisible='1'
".GetProdCustomerGroupPermissionsSQL()."
ORDER BY RAND()
";
$query .= $GLOBALS['ISC_CLASS_DB']->AddLimit(0, 8);
This may work right away (lol, fingers crossed!!) - but will likely need some tweaking.
All that has been done is removing the requirement that a product is featured for it to be shown, and setting the limit of products to 8 (this bit should work I hope)
Good luck, let us know how you get on

Re: How To Create a snippet that will display 8 random products.
Hi Tony
I want to add to left panel menu and display 2 items one of this is New added products with pagination and view all products with pagination how can i do this ?
Thank you
I want to add to left panel menu and display 2 items one of this is New added products with pagination and view all products with pagination how can i do this ?
Thank you
Re: How To Create a snippet that will display 8 random products.
Thanks for the help;
I tied it and it does not work.
Your code works, because when I modify the original file it displays it properly, but when I duplicate and rename everything where necessary (filenames, and in the files) It does not pull up the info. It is almost as if it does not run the file from the includes\display.
Thanks
I tied it and it does not work.
Your code works, because when I modify the original file it displays it properly, but when I duplicate and rename everything where necessary (filenames, and in the files) It does not pull up the info. It is almost as if it does not run the file from the includes\display.
Thanks
-
- Posts: 744
- Joined: Thu Jun 18, 2009 8:59 am
Re: How To Create a snippet that will display 8 random products.
That's going to be quite a hack dwrs, not something I could do quickly I don't think...?
So called HomeRandomProducts.php in includes/display, and /templates/YOUR TEMPLATE/panels/HomeRandomProducts.html?
So called HomeRandomProducts.php in includes/display, and /templates/YOUR TEMPLATE/panels/HomeRandomProducts.html?
Re: How To Create a snippet that will display 8 random products.
How do you call it?
By just having it in the folder? I tried that but it doesnt work.
THanks
By just having it in the folder? I tried that but it doesnt work.
THanks
-
- Posts: 744
- Joined: Thu Jun 18, 2009 8:59 am
Re: How To Create a snippet that will display 8 random products.
Right, roll sleeves up and actually do the hack time...
Step 1. Copy includes/display/HomeFeaturedProducts.php to includes/display/HomeRandomProducts.php
Step 2. Open includes/display/HomeRandomProducts.php and do a find/replace - Featured for Random (in line 3 I'd keep it all as caps - ISC_HOMERANDOMPRODUCTS_PANEL - may be impotrant, I don't know)
Step 3. Remove
Step 4. Open config/config.php, go to line 60, insert
Step 5. Copy /templates/_master/panels/HomeFeaturedProducts.html to /templates/YOUR TEMPLATE/panels/HomeRandomProducts.html
Step 6. Open /templates/YOUR TEMPLATE/panels/HomeRandomProducts.html, do a find/replace - Featured for Random
Step 7. Copy /templates/_master/snippets/HomeFeaturedProductsItem.html to /templates/YOUR TEMPLATE/snippets/HomeRandomProductsItem.html
Step 8. Open /templates/YOUR TEMPLATE/snippets/HomeRandomProductsItem.html, do a find/replace - Featured for Random
Step 9. Open up /templates/YOUR TEMPLATE/default.html, and add in
You should now have a configurable (via config) random products panel that can be moved about in design view
Step 1. Copy includes/display/HomeFeaturedProducts.php to includes/display/HomeRandomProducts.php
Step 2. Open includes/display/HomeRandomProducts.php and do a find/replace - Featured for Random (in line 3 I'd keep it all as caps - ISC_HOMERANDOMPRODUCTS_PANEL - may be impotrant, I don't know)
Step 3. Remove
from line 19p.prodfeatured = '1' AND
Step 4. Open config/config.php, go to line 60, insert
- swap to 8 if you want 8 products there$GLOBALS['ISC_CFG']["HomeRandomProducts"] = 4;
Step 5. Copy /templates/_master/panels/HomeFeaturedProducts.html to /templates/YOUR TEMPLATE/panels/HomeRandomProducts.html
Step 6. Open /templates/YOUR TEMPLATE/panels/HomeRandomProducts.html, do a find/replace - Featured for Random
Step 7. Copy /templates/_master/snippets/HomeFeaturedProductsItem.html to /templates/YOUR TEMPLATE/snippets/HomeRandomProductsItem.html
Step 8. Open /templates/YOUR TEMPLATE/snippets/HomeRandomProductsItem.html, do a find/replace - Featured for Random
Step 9. Open up /templates/YOUR TEMPLATE/default.html, and add in
where you want it to be called up%%Panel.HomeRandomProducts%%
You should now have a configurable (via config) random products panel that can be moved about in design view

Re: How To Create a snippet that will display 8 random products.
Tahnk you very much i'll try and write the feedback.Again TYVM
Re: How To Create a snippet that will display 8 random produ
I followed to the letter the above instructions to very quickly learn that you MUST also copy HomeFeaturedProductsItem.html to HomeRandomProductsItem.html
_master/Snippiets/HomeFeaturedProductsItem.html
_master/Snippiets/HomeRandomProductsItem.html
Now when you call the panel %%Panel.HomeRandomProducts%% you will see the text header itself needs changing away from ‘Featured products’
Go to /language/YOUR LAN/front_language.ini and below the line - FeaturedProducts = "Featured Products" simply add RandomProducts = "View other Products"
During the process of making admin changes to your site, there Is some strange event taking place in the background that over-writes config.php while backing up the original. This actually means you lose the 'link' made to any mod call placed in config. This is because the config file is recreated entirely based upon a template file: /admin/templates/config.file.tpl. So now you need simply goto the relivant location in the file and add the line $GLOBALS['ISC_CFG']["HomeRandomProducts"] etc. etc. Now, every time config.php is updated, your addition gets included.
This works on 5.5.4 .. http://www.ihost4u.co.uk/xcart2
_master/Snippiets/HomeFeaturedProductsItem.html
_master/Snippiets/HomeRandomProductsItem.html
Now when you call the panel %%Panel.HomeRandomProducts%% you will see the text header itself needs changing away from ‘Featured products’
Go to /language/YOUR LAN/front_language.ini and below the line - FeaturedProducts = "Featured Products" simply add RandomProducts = "View other Products"
During the process of making admin changes to your site, there Is some strange event taking place in the background that over-writes config.php while backing up the original. This actually means you lose the 'link' made to any mod call placed in config. This is because the config file is recreated entirely based upon a template file: /admin/templates/config.file.tpl. So now you need simply goto the relivant location in the file and add the line $GLOBALS['ISC_CFG']["HomeRandomProducts"] etc. etc. Now, every time config.php is updated, your addition gets included.
This works on 5.5.4 .. http://www.ihost4u.co.uk/xcart2
Last edited by Snooper on Fri Sep 03, 2010 7:11 pm, edited 3 times in total.
ISC 5.5.4 Ultimate : Being used here -- http://www.kdklondon.com
-
- Confirmed
- Posts: 413
- Joined: Sun Aug 09, 2009 1:23 pm
Re: How To Create a snippet that will display 8 random produ
Thanks!! This thread guided me to make a slight modification to my "New Products" page.
Instead of showing ALL new products (the default) I modified HomeNewProducts.php to show new AND featured products only.
Changed This
To This
This will help whenever I add dozens of similar items... and I only need to display ONE or TWO of them for customers to get the general idea that I'm now selling a particular line of widgets.
Previously, whenever I added dozens of almost identical items, they would FLOOD the new-products page and push everything else off the page. A true annoyance.
Instead of showing ALL new products (the default) I modified HomeNewProducts.php to show new AND featured products only.
Changed This
Code: Select all
WHERE p.prodvisible='1' AND (imageisthumb=1 OR ISNULL(imageisthumb))
Code: Select all
WHERE p.prodfeatured = '1' AND p.prodvisible='1' AND (imageisthumb=1 OR ISNULL(imageisthumb))
Previously, whenever I added dozens of almost identical items, they would FLOOD the new-products page and push everything else off the page. A true annoyance.
ISC 4.0.7
"... and let's be honest that whole "by design" thing is getting old too."
"... and let's be honest that whole "by design" thing is getting old too."