VirtueMart Forum

VirtueMart 1.1.x [ Old version - no longer supported ] => Frontend Modules VM 1.1 => Topic started by: flora01 on October 15, 2010, 17:01:33 pm

Title: Hack to use randomprod module for multiple categories
Post by: flora01 on October 15, 2010, 17:01:33 pm
Hello,
This tip is inspired from this post:
http://forum.virtuemart.net/index.php?topic=21242.0

I decided to repost it because with a little mod (suggested in the topic as well), it works on VM 1.1.2,
i tried it as well, and it works in vm 1.1.5

if you want randomprod to fetch its items from many categories at once
or,
(in my case)if a parent category does not have products directly,
but its children categories have products,
and we want to show these in the random prod, (i filled them manually one by one using this hack,by the way. but it would be still better than nothing!)

then:
go to this file:
/modules/mod_virtuemart_randomprod/mod_virtuemart_randomprod.php

line 33,
and remove the "(int)" (without blockquotes)from the following:
Quote
Code: [Select]
$category_id = (int)$params->get( 'category_id', 0 );
it should be on line 33.
then
Quote
find the line:

Code: [Select]
$q .= "AND #__{vm}_category.category_id='$category_id'";
and replace with


Code: [Select]
$category_id_mod = "'".str_replace(",","','", $category_id)."'";
$q .= "AND #__{vm}_category.category_id IN ($category_id_mod)";


In the Random Product Module, be sure to separate your category IDs with commas for example:
Code:

1,2


so here's what this hack does:
instead of considering the "category id" as 1 number,
it retrieves it as a text,
and picks the categories from the text (provided you have already separated them with commas)
and makes the module choose the randproduct -->IN<-- those numbers

many thanks to canreo and zdjl505 for the hack

Regards

Title: Re: Hack to use randomprod module for multiple categories
Post by: nd on December 23, 2010, 03:48:36 am
This worked PERFECTLY. Thanks!
Title: Re: Hack to use randomprod module for multiple categories
Post by: flora01 on December 23, 2010, 07:59:22 am
u're welcome :) I'm glad it helped someone :)
Title: Re: Hack to use randomprod module for multiple categories
Post by: joseugs on February 07, 2012, 23:12:39 pm
Good lookin' flora01, thanks for the good tip. I was about to start writing some recursive scripts, etc. etc. using a single parent ID. This one does the job as well.
Title: Re: Hack to use randomprod module for multiple categories
Post by: oceanb702 on February 09, 2012, 18:26:34 pm
hi,

i solved my problem by using your code.

http://forum.virtuemart.net/index.php?topic=97795.0

I edited latest product module. Somehow, they works.
Title: Re: Hack to use randomprod module for multiple categories
Post by: lipes on April 23, 2013, 21:48:42 pm
did someone find a solution to virtuemart 2 ?