How To Create a snippet that will display 8 random products.

Modules, Add-ons and custom code that's more than just a quick hack or Mod.
ghurty
Confirmed
Confirmed
Posts: 7
Joined: Wed Jul 08, 2009 9:17 pm

How To Create a snippet that will display 8 random products.

Post by ghurty »

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
Tony Barnes
Posts: 744
Joined: Thu Jun 18, 2009 8:59 am

Re: How To Create a snippet that will display 8 random products.

Post by Tony Barnes »

Copy and rename HomeFeaturedProducts.php to HomeRandomProducts.php, open it up, find
$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'));
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.prodvisible='1'
".GetProdCustomerGroupPermissionsSQL()."
ORDER BY RAND()
";
$query .= $GLOBALS['ISC_CLASS_DB']->AddLimit(0, 8);
Then copy /templates/_master/panels/HomeFeaturedProducts.html to /templates/YOUR TEMPLATE/panels/HomeRandomProducts.html, and call as you would any another panel.

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 :D
dwrs
Posts: 16
Joined: Wed Feb 03, 2010 5:30 pm

Re: How To Create a snippet that will display 8 random products.

Post by dwrs »

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
ghurty
Confirmed
Confirmed
Posts: 7
Joined: Wed Jul 08, 2009 9:17 pm

Re: How To Create a snippet that will display 8 random products.

Post by ghurty »

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
Tony Barnes
Posts: 744
Joined: Thu Jun 18, 2009 8:59 am

Re: How To Create a snippet that will display 8 random products.

Post by Tony Barnes »

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?
ghurty
Confirmed
Confirmed
Posts: 7
Joined: Wed Jul 08, 2009 9:17 pm

Re: How To Create a snippet that will display 8 random products.

Post by ghurty »

How do you call it?

By just having it in the folder? I tried that but it doesnt work.

THanks
Tony Barnes
Posts: 744
Joined: Thu Jun 18, 2009 8:59 am

Re: How To Create a snippet that will display 8 random products.

Post by Tony Barnes »

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
p.prodfeatured = '1' AND
from line 19

Step 4. Open config/config.php, go to line 60, insert
$GLOBALS['ISC_CFG']["HomeRandomProducts"] = 4;
- swap to 8 if you want 8 products there

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
%%Panel.HomeRandomProducts%%
where you want it to be called up

You should now have a configurable (via config) random products panel that can be moved about in design view :D
dwrs
Posts: 16
Joined: Wed Feb 03, 2010 5:30 pm

Re: How To Create a snippet that will display 8 random products.

Post by dwrs »

Tahnk you very much i'll try and write the feedback.Again TYVM
Snooper
Posts: 264
Joined: Sat Jun 26, 2010 9:22 pm

Re: How To Create a snippet that will display 8 random produ

Post by Snooper »

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
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
CharlieFoxtrot
Confirmed
Confirmed
Posts: 413
Joined: Sun Aug 09, 2009 1:23 pm

Re: How To Create a snippet that will display 8 random produ

Post by CharlieFoxtrot »

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

Code: Select all

WHERE p.prodvisible='1' AND (imageisthumb=1 OR ISNULL(imageisthumb))
To This

Code: Select all

WHERE p.prodfeatured = '1' AND p.prodvisible='1' AND (imageisthumb=1 OR ISNULL(imageisthumb))
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.
ISC 4.0.7

"... and let's be honest that whole "by design" thing is getting old too."
Post Reply