Author Topic: Hack to use randomprod module for multiple categories  (Read 6112 times)

flora01

  • Beginner
  • *
  • Posts: 23
    • Flora Organica
Hack to use randomprod module for multiple categories
« 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

Live Smart, Eat Smart,
Flora Organica http://www.flora-organica.com

the Joomla/Virtuemart links that made my day
"checkout redirects to index.php"? read this: http://forum.virtuemart.net/index.php?topic=34989.msg170542#msg170542

nd

  • Beginner
  • *
  • Posts: 9
Re: Hack to use randomprod module for multiple categories
« Reply #1 on: December 23, 2010, 03:48:36 am »
This worked PERFECTLY. Thanks!

flora01

  • Beginner
  • *
  • Posts: 23
    • Flora Organica
Re: Hack to use randomprod module for multiple categories
« Reply #2 on: December 23, 2010, 07:59:22 am »
u're welcome :) I'm glad it helped someone :)
Live Smart, Eat Smart,
Flora Organica http://www.flora-organica.com

the Joomla/Virtuemart links that made my day
"checkout redirects to index.php"? read this: http://forum.virtuemart.net/index.php?topic=34989.msg170542#msg170542

joseugs

  • Beginner
  • *
  • Posts: 3
Re: Hack to use randomprod module for multiple categories
« Reply #3 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.

oceanb702

  • Beginner
  • *
  • Posts: 10
Re: Hack to use randomprod module for multiple categories
« Reply #4 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.

lipes

  • Sr. Member
  • ****
  • Posts: 720
Re: Hack to use randomprod module for multiple categories
« Reply #5 on: April 23, 2013, 21:48:42 pm »
did someone find a solution to virtuemart 2 ?
VM V. online: J2.5.14 | VM 2.0.20a | SQL 5.1.70 | PHP 5.3.25