Author Topic: A "Customers who bought this product also bought" hack for Virtuemart.  (Read 30615 times)

marty_tennison

  • Beginner
  • *
  • Posts: 25
Hi,

I've just finished a hack that automatically builds and displays ordered item relation information.  ie, "customers who bought this product also bought..." type of thing.

The script requires manual install (not to hard to do) and allows you to place a new tag on your flypage to display the information.  It's not a module or component, it's a modification and addition to shop.product_details.php.

See the README.txt file for all the gory details.

All feedback welcome.  I'm a recent convert from another shopping cart system (based on PERL) and this is my first php hack.  This can, of course, be inclued in the core if found to be useful.

-- Marty

[attachment cleanup by admin]

Shibumi

  • ** on hiatus **
  • Full Member
  • ***
  • Posts: 591
  • if it aint broke, there must be something wrong
    • Shibumi Design Studios
  • VirtueMart Version: 2.0.20b
Hey Marty, This is pretty cool... have you looked into module creation? there are a few pointers around the forums (How to, Tips boards)  You could easily build a module to use in conjunction with this mod, passing your config vars to the script fetched from the module settings set in its admin page.

Take a look at some of the existing modules to see how they interact with your code... should be fairly easy, havent really made any modules yet myself, but with each passing day of using VM, I have done quite a few hacks myself and worked with modifying modules and the process looks pretty simple.

Line numbers are not always a good thing as many people already have many modifications to their code, or using different verions - it's always best to put in your instructions something like:
Quote
look for this code around line number(s) - (code_sippet) and insert after this
Sometimes, your line numbers could be in the middle of someone elses function.

Anyways, cool idea, I'm sure a lot of people could find this very useful.  If you need any help with module creation let me know.  If I come up with anything, I will definitely post it here.

Cheers
Jeff
=================================================
Scionergy.com - www.Scionergy.com
Scion Owners Club of Ottawa - www.ScionOwnersClubOttawa.ca
Capital Door Service - www.CapitalDoorService.com - VM2.0.20b, Joomla 2.5.11 PHP5.2.11 powered site

marty_tennison

  • Beginner
  • *
  • Posts: 25
Hi CiPHeR,

Thanks for the pointers.  I'll make sure to use your advice on finding correct line numbers on my next mod.

Actually, I really wanted to do this as a module because that would make install simple and keep things separate form the core code base.  And I was headed down that road but I hit a roadblock.  But maybe you have the answer I need so that I can do it as a mod.  My roadblock goes something like this.

I want to display the output of a module (pick a module, any module) in the content section of my flypage.  In other words, I've only been able to use modules in the pre-defined "module positions" as defined by Joomla.  But what I really need is to be able to edit my flypage.php file and insert a call to a module anywhere in the page. 

So if you have the answer to that I'd be oodles and oodles grateful.   :)

If that is not possible then I think the next best thing is probably a Mambot.  Kinda like {product_snapshot}.  But I have not looked at the Mambot examples yet so I'm not sure what's involved. I've got a lot of custom code I have to write and I'm still searching for the easiest way to keep custom changes separate from core data.

Thanks again for your help and suggestions.

===============
figured out how to do this.

Just modify your site template (usually index.php) and insert something like this...

<?php mosLoadModules('some_position', -1);  ?>

You can also put conditionals in there to only load sometimes.  Like th is

<?php if ( ereg ("flypage", $QUERY_STRING) ) { mosLoadModules('flyopr', -1); } ?>

Now, we are starting to get some flexability.  :)

marty_tennison

  • Beginner
  • *
  • Posts: 25
I've turned this hack into a module.  I'm not sure how many people will find it useful.  It has a few special requirements to work properly so you've got to modify your site template to recognize the flypage and only call this module when the flypage is loaded.  See the readme file for more info.

Feedback welcome. This is my first module, still figuring things out.

Enjoy.  ;D

[attachment cleanup by admin]

sorian

  • Jr. Member
  • **
  • Posts: 88
I would love it if it would show pictures of the products instead of just text links. Any way of doing that?

Shibumi

  • ** on hiatus **
  • Full Member
  • ***
  • Posts: 591
  • if it aint broke, there must be something wrong
    • Shibumi Design Studios
  • VirtueMart Version: 2.0.20b
you could try making it use the ps_product->show_snapshot() function?

Marty, any ideas on this implementation?  You can take a look at my extended featured products module I did - posted in the forums somewhere... ah, here it is: http://virtuemart.net/index.php?option=com_smf&Itemid=71&topic=18285.msg42991#msg42991
Jeff
=================================================
Scionergy.com - www.Scionergy.com
Scion Owners Club of Ottawa - www.ScionOwnersClubOttawa.ca
Capital Door Service - www.CapitalDoorService.com - VM2.0.20b, Joomla 2.5.11 PHP5.2.11 powered site

marty_tennison

  • Beginner
  • *
  • Posts: 25
Marty, any ideas on this implementation?

Hi sorian and CiPHeR,

I'll add this to my todo list for the next version.  It's not difficult at all.  I'll see if I can add a templating directive so that you can easily change the format of the output. 

I'm not sure when I'll be able to get to this.  I've got some other projects that I'm currently working on but I'll take a look as soon as I can.

sorian

  • Jr. Member
  • **
  • Posts: 88
I would really appreciate it. This mod is exactly what I am looking for (except for the mentioned changes). Can't wait to see the new version.

marty_tennison

  • Beginner
  • *
  • Posts: 25
BTW...  I'm working on another module for my site and I wonder if it would be of any use to anyone else. It's a module that displays the most recently viewed products.  It stores the information in a cookie so it maintains persistence between sessions. It is used as a "You have recently viewed these products" type of thing. 

Would this be of any use to anyone?

sorian

  • Jr. Member
  • **
  • Posts: 88
Sounds like a nice idea. I would defininitely try it out.

niviche

  • Beginner
  • *
  • Posts: 11
Hello,

Marty, I modified something with your hack. It was still displaying products not in stock or not published. My modification adds a check of the stock and the publication, and spits out only the products which are actually available.

To modifiy this, in the file mod_virtuemart_opr.php, look for the lines:

Code: [Select]
$dbc->query("SELECT product_name FROM #__{vm}_product WHERE product_id = '$key'");
$dbc->next_record();
$c = $dbc->f("product_name");

and add right after them:

Code: [Select]
$dbc->query("SELECT product_in_stock FROM #__{vm}_product  WHERE product_id = '$key'");
$dbc->next_record();
$d = $dbc->f("product_in_stock");

$dbc->query("SELECT product_publish FROM #__{vm}_product  WHERE product_id = '$key'");
$dbc->next_record();
$e = $dbc->f("product_publish");

then, right after the lines:
Code: [Select]
if ( $br_after_link == 1 ) {
$html .= "<br />";

you should add:
Code: [Select]
}

This seems to work fine for me.

Note, however, that this doesn't take the store configuration into account (CHECK_STOCK and PSHOP_SHOW_OUT_OF_STOCK_PRODUCTS). I was not able to add this to your code, but maybe somebody can.

marty_tennison

  • Beginner
  • *
  • Posts: 25
Hi niciche,

Thanks for the info.  I'll incorporate your fix and put it in the next release. 

I'll add the CHECK_STOCK and PSHOP_SHOW_OUT_OF_STOCK_PRODUCTS into the next release also.

Thanks again for the for feedback, it is much appreciated.

onsitenet

  • Beginner
  • *
  • Posts: 23
Re: A "Customers who bought this product also bought" hack for Virtuemart.
« Reply #12 on: August 15, 2006, 03:05:27 am »
Ok, another usefull hack (or mod) but...
What do you mean when you say:
"You'll need to apply some styles to the module to get it
to work. The structure of the output is like this...
<div class="$div_class" id="$div_id">
  <span>$title</span>
  <links> //if you use tables, they will be here
</div>"
in the "readme"

You mean what-where? Didn't get it! ???

Thanks in advance,
George.

Adam Bazaroff

  • Jr. Member
  • **
  • Posts: 90
Re: A "Customers who bought this product also bought" hack for Virtuemart.
« Reply #13 on: August 22, 2006, 03:01:45 am »
Great module! Thanks.
Please release new version with product pictures, and with more detailet info about them - show price, categories, manufacturer. ex.

Customers who bought this product also bought...
CD > Abba > Moscow    $5.00      (Sony Music)
^^    ^^           ^^         ^^           ^^
cat1   cat2       name       price       manufacturer
link     link          link                           link
/Adam'B ... Poor english mode [ON] ;D

kooolkat357

  • Beginner
  • *
  • Posts: 13
Re: A "Customers who bought this product also boug
« Reply #14 on: November 12, 2006, 21:05:15 pm »
Ok, another usefull hack (or mod) but...
What do you mean when you say:
"You'll need to apply some styles to the module to get it
to work. The structure of the output is like this...
<div class="$div_class" id="$div_id">
  <span>$title</span>
  <links> //if you use tables, they will be here
</div>"
in the "readme"

You mean what-where? Didn't get it! ???

Thanks in advance,
George.

I also lookingfor the answer to this....

Kooolkat357