![]() |
Random Image or Random Products - Category Specific
Ok, I have been reading through all the threads concerning random images and it seems that over time there has been a request for that and/or random products - so here is a freebie.
This Mod searches the product database for products that are relevant to the current situation. This means that it is not only category specific but also user or membership specific. It will pick preset number of products in random order. This number is set within Admin under General Settings -> Modules Options. There is also a template that will take the number of random products returned and pick one to display a random product image. This image is also linked to the product page for that product. INSTALL INSTRUCTONS: Within Patch/Upgrade section of X-Cart or within SQL Admin run this query: Code:
INSERT INTO `xcart_modules` ( `moduleid` , `module_name` , `module_descr` , `active` ) Next create a new directory under /modules/ named "Random_Products" and a directory under /skin1/modules/ named "Random_Products". Within /modules/Random_Products create a file named "random.php" with this content: Code:
<?php Next create two files under /skin1/modules/Random_Products/ named "random.tpl" and "random_image.tpl" with the contents as: random.tpl Code:
{capture name=dialog} random_image.tpl Code:
{assign var="rand" value="0"|mt_rand:"`$config.Modules.number_of_randomproducts-1`"} Now, edit your home.php file in root directory and add the following lines under the section that loads the Best Sellers module: Code:
if($active_modules["Random_Products"]) ** New Step ** This is a new step that you will need to do to make the single random image work on most systems (since that code is using a PHP modifier and not a Smarty modifier). If the single random image is working for you already then you do not need to perform this step. Open the file /Smarty-2.x.x/Smarty.class.php for editing. On or around line 234 you will see the code: Code:
'MODIFIER_FUNCS' => array('count') This need to be change to read Code:
'MODIFIER_FUNCS' => array('count', 'mt_rand') Now, where ever you want to display random products, just add this code in the template Code:
{include file="modules/Random_Products/random.tpl"} Code:
{include file="modules/Random_Products/random_image.tpl"} The template that displays the random products feeds into the template that you are using to display the product listings site wide. So, if you have your store set to display products 3 per row, then the random products will also display that way. The initial settings in Admin are that the module is enabled and the number of random products are 3. You can disable the module at the same location that all other modules are enabled or disabled. If you find this Mod useful, donations are welcome :D |
Nice one :)
|
Hi, I get this error. What is it?
Code:
Warning: Smarty error: math ``x/y'' in ``customer/home.tpl'': parameter ``y'' is empty in W:\www\xcart\Smarty-2.6.9\Smarty.class.php on line 1088 |
OK - well - I guess I need to rewrite that query (or the template that is used to display the products). It seems that the function "func_search_products" does not load up the minimum and low-stock ammounts (among other things).
Those errors are part of the math functions in the product templates and the buy-now button template. |
This was exactly what I wanted...but it doesn't appear to be working for me either, although I don't get the error that micromedia gets. I added the referencing code:
Code:
{include file="modules/Random_Products/random.tpl"} to skin1/customer/main/product.tpl, but all that shows up is a box with a yellow border - here's a sample page http://www.vidaville.com/store/product.php?productid=250&cat=1&page=1. You'll see the empty box near the bottom of the page below the area called "You may also like...". What I want to be able to do is only show products from certain categories within that area. Is that the goal of this mod? I thought it was, but I could be wrong. :wink: Thanks! |
Actually the goal was to display within a category listing not necessarily on the product page. This is a consideration though. I will see if I can change that to make it work that way.
|
Same error message with smarty and x/y here:( But where is the mistake, anybody know ?
|
I have made a small change to the random.php file that will clear up some issues that some people are having - specifically the issue of not getting an error message, but not getting any images either.
I have also added an extra step that you may need to do if the single random image is not working for you. |
The random products are working great.
Thanks for this great mod. |
Got a question about the random images. Is it also possible to include the product title above the random image? And maybe the product price. That would be very nice.
|
NightFire 50% Answer
Quote:
As for the title, that's an easy one... Go to random_image.tpl and add the following line above (or within) the a href= tag... Code:
... Just guessing, but I assumed the rand was returning outside the bounds of $config.Modules.number_of_randomproducts Sure enough, this occurred as I had expected. $config.Modules.number_of_randomproducts was set to 3, and occassionaly $rand resulted as 3, but arrays are an option base 0, so 3 is outside of the boundaries. To modify my above temporary fix, I account for this, and subtract 1 if necessary, resulting in the following: Code:
{assign var="rand" value="0"|mt_rand:$config.Modules.number_of_randomproducts} |
You are correct about the array and sometimes it will generate a random number outside the array limits. I corrected my post. All that was necessary was to change the assign to :
Code:
{assign var="rand" value="0"|mt_rand:"`$config.Modules.number_of_randomproducts-1`"} Good catch. |
It's working great. Thanks for the fixes.
Another question. The random image is displaying the thumbnail size which is set under the general settings. But is it also possible to change this image size in the random_image.tpl so that it has a custom size? The products wich are displayed in the categories will still have their original size then. Edit: Found a bug in the random image script. I placed the random image script on the homepage. But when you click on the product you'll be redirected to the product page. But the place where the random image script, is displaying no image availlable and it isn't displaying a product title. And it redirects me to this when I click on it: www.shopurl.com/shop/image.php?productid= Hope someone find a solution for this. |
Quote:
NightFire, This is the same error that we were speaking about above (Prev 2 Posts) Please implement the fix to correct this. |
hi, I seem to be having problems with implementing this mod. please visit http://www.digi-quick.com/error_message.php?access_denied&id=33
home.tpl Code:
<?php random.php Code:
<?php random.tpl Code:
{capture name=dialog} random_image.tpl Code:
{assign var="rand" value="0"|mt_rand:"`$config.Modules.number_of_randomproducts-1`"} |
Look at the install instructions again....you have some php referenced in home.tpl when it should be in home.php.
|
thanks balinor, I've got it to work now.
only thing is that it's not really what I was looking for. I was trying to figure out a way adapt the 'Featured Products' tools so that it only shows random products from specified categories. Has such a mod been developed. Thanks for any help. |
That is exatly what this does?
|
What about disabled categories?
TelaFirma,
This is a sweet Mod, Tela! Wanted to point out that another thing that I also noticed is that the random image returned sometimes returns images from DISABLED categores. This is not ideal, at least for our shop. I'm sure I could correct this, but reviewing func_search_products within func.php didn't lead me to any 'smoking gun' right off the bat, anyhow... Don't know if you were aware of this... |
Quote:
Isn't it just a matter of placing this on one of your category pages? Code:
# |
Anyone got a hack to this that will display a totally random product, no matter what page the user is on? Currently I've got this set up in a spot that shows on every page, and when it goes to non-product/category pages it shows up blank....
|
Isn't it just a matter of placing this on one of your category pages?
Code:
# Simply modify the SQL to query the table, but not limiting to $cat .... then, ORDER BY RAND() and LIMIT 1 ...you should be set. LIMIT 3 if you use the random_products.tpl |
I see that thi smod display RANDOM IMG's and Products
I just want mine to display Random Featured Products Do i need to do all of this mod or is there a shorter way of doing it?? |
How to show products from only one category?
I've been able to get this to work great (thanks!) but was wondering if there was something I could modify so that it is:
1. Independent of the category page it is currently being displayed on and instead 2. Shows only random products from a category I specify, for example, I just want it to show products in "Category D" which has a categoryid of 8, no matter what page it's on. I assume I need to edit random.php and the SQL query, but I don't know how. Any help would be appreciated. :) Thank you |
I figured it out!
Sorry, after a few more trials and errors, I figured it out!
In random.php, I simply changed Code:
# Get products data for current category and store it in an array to Code:
# Get products data for current category and store it in an array Where the number 8 above is the categoryid for the category who's products I want to display. Hope this helps someone! |
Re: Random Image or Random Products - Category Specific
This mod is working great I was just wondering if someone could add some functionality I cannot figure out? I would like to have on the home page 4 different specified categorys with 3 random featured products a piece. I would like these to be displayed in a row instead of a column. Is any of this possible?
|
Re: Random Image or Random Products - Category Specific
Great mod - nearly works
I'm now getting an SQL error when I click on my categories.. "INVALID SQL: 1176 : Key 'pam' doesn't exist in table 'xcart_categories' SQL QUERY FAILURE:SELECT categoryid FROM xcart_categories USE INDEX (pam) WHERE categoryid_path LIKE '12/%' AND avail='Y'" Apart from this - the mod is fantastic. Thanks, Ian |
Re: Random Image or Random Products - Category Specific
---don't panic - i've fixed it by switching the INDEX from (pam) to (pa)
Great mod |
Re: Random Image or Random Products - Category Specific
If anyone's still keeping an eye on this thread was there ever a solution for displaying the product price? Product name was solved but..
|
Re: Random Image or Random Products - Category Specific
well the mod sounds great but i'll pose one question before i run off and start implementing something that may not work as needed.
i'd ideally like to be able to display 3-4 random products in a row, with images, with links to the product page obviously, but i only want to do this on certain pages where the layout allows for this. mainly the main page, and some other page that don't contain much information other some text. i know you can call this from where ever you want, but i know there was mention of one random image, and that is was specific to certain categories. the pages i'd want this on have no category, or membership affliation. is this doable? thanks, |
Re: Random Image or Random Products - Category Specific
is there a mod to randomize the featured products? also to only randomize it every 24 hours or so? I hacked my featured products to sort by RAND but each page refresh causes the featured products to randomize. I keep it only b/c it keeps the main page changing.... however, i'd like a more user friendly randomizer for the featured products
|
Re: Random Image or Random Products - Category Specific
Hey you say in the forum that you hacked the random function for the featured products.
How and where is that possible? I want to show random products on the featured products list limited by an number. It may change every time that's no problem tnx |
Re: Random Image or Random Products - Category Specific
There's a problem with this mod. The quantity field is not filled with a number, by default. The user is unable to put the item in the shopping cart from the buy now button.
Any ideas to fix??? |
Re: Random Image or Random Products - Category Specific
I see by your sig that you are using X-Cart version 4.1.x - if you look at the date of the original post, it was in 2005. This was intended for version 4.0.x - not 4.1.x....
Quote:
|
Re: Random Image or Random Products - Category Specific
OK. Sorry. So this mod is unsupported in 4.1.x
It seems to be a simple fix. Since it works in your ver 4.0.x. How hard is it to give the quantity field a number to add the item to the cart from the buy now button. Just exactly how the x-cart team did for the featured products - it should be the same for the random products. |
Re: Random Image or Random Products - Category Specific
Well - I agree but I have not had the time to look through this code again to make it work for 4.1.x.
In giving it a quick look the first thing that you need to look at is the product array that is being built and make sure that the "min_amount" has a value. The buy_now template uses this to determine what to do with qty. If "min_amount" is empty then you will need to look at the function used to do the search. Quote:
|
Re: Random Image or Random Products - Category Specific
The value is already assigned at 1. The featured products uses the same buy now template as the random products.
|
Re: Random Image or Random Products - Category Specific
|
Re: Random Image or Random Products - Category Specific
Hello:
Has anyone gotten this great mod to work in version 4.1x? |
Re: Random Image or Random Products - Category Specific
anyone got this for 4.4.x??? working
oh man i would drool... |
All times are GMT -8. The time now is 07:08 PM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.