Write a VERY useful plug in for Virtuemart

I have a project requirement that I just can’t find a way to meet, these are the criteria for a site I’ve been asked to develop:

  1. Need to show one set of prices to non-logged in users and offer to show a ‘discounted prices’ to users prepared to register hand over their email address.

  2. The site will have hundreds of products with multiple prices (not a blanket discount) and those prices need to be updated frequently and easily.

I’ve tried to do this with Joomla (1.5.15) and Virtuemart (1.1.4 stable) but I can meet one criteria or the other not both, because although Virtuemart will allow the different prices to be set up in different ‘shopper groups’, new users are automatically put into the defult shopper group and therefore see the normal prices even though they’re registered. You have to manually add them to the discounted shopper group for them to see the discounted prices and that’s not good enough, it needs to happen automatically.

If there were a way to assign new users to specific shopper groups in Virtuemart the job would be in the bag but it’s really looking like there isn’t a way to do this.

So, can someone either help me figure out how to meet the requirements with shareware plugin type software or any PHP programmers out there who want to write a plugin for Virtuemart that would do this would get a serious amount of downloads I think.

Add a few lines of code to whatever processes the registration form, to go update the database and change the user’s “shopper group”. Whatever Virtuemart does when you manually change someone’s group, you do that yourself directly.

You wouldn’t happen to know how to do that would you?

Is there anyone on SP who could do what Dan suggested? I can post all necessary files or FTP/email them somewhere.

I haven’t used Virtuemart, no. But you can probably figure it out by looking at the database for some kind of column on the user table that corresponds to a group. Or look at the code that the “change shopper group” page runs.

Dan I have no idea what I’m doing with PHP or databases, I really need someone to write the code for me.

Your suggestion did give me the idea to search for a hack (hand’t occured to me to try that) and I found this post on another forum, I busy trying to make sense of it right now

[COLOR=“DarkOliveGreen”]
Would this be suitable:

add a user field (type checkbox for example) to select the group at registration.
Then in the code :

add a test of the checkbox value before inserting the group in database (function add()) :

  if($fields['my_field']=="1")
  {

     $d['shopper_group_id']="my_group_id";
  }
 
 
  $customer_nr = uniqid( rand() );
  // Insert Shopper -ShopperGroup - Relationship
  $q  = "INSERT INTO #__{vm}_shopper_vendor_xref ";

and in the update() function :

// Delete shopper_vendor_xref entries
$q = “DELETE FROM #__{vm}_shopper_vendor_xref where user_id='” . $d[“user_id”] . “'”;
$db->query($q);

  // UPDATE #__{vm}_shopper group relationship
  $q = "SELECT shopper_group_id FROM #__{vm}_shopper_vendor_xref ";


if($fields[‘my_field’]==“1”)
{

     $d['shopper_group_id']="my_group_id";
  }

$q = "INSERT INTO #__{vm}_shopper_vendor_xref ";[/COLOR]

Then you have to purchase a listing in the SitePoint Marketplace. You can’t post hiring requests in the forum.

I don’t want to hire someone, it’s only a couple of lines you said, I’d do it for someone else if I knew how. If I’d realised that I needed to pay for this I’d have gone to elancers but my very ignorance of this area led me to here first.

Since this thread is ranking on the first page of Google for the phrase “virtuemart hack/code assign users to specific shopper groups” and I actually managed to find a solution I thought I’d post it for other people to find in the future. This may not be the only solution but it seems to work and doesn’t seem to break anything else going on in the process.

I’m using Joomla 1.5.15 and Virtuemart 1.1.4 (stable) in ‘Catalogue’ mode but with prices enabled. I don’t know if this would work if VM was configured differently but I don’t see why not, this only should affect that one shopper group.

The problem was one of overiding the assignment of a new user to the default shopper group in virtuemart and instead assign them to one I’d created myself. Virtuemart seems to assign a shopper group ID of ‘7’ to the first custom shopper group created so you need to tell the registration process to assign new users to group 7.

The file that needs to be changed is ps_shopper.php and it can be found in admin/components/com_virtuemart/classes

On line 419, change:

$d[‘shopper_group_id’] = $db->f(“shopper_group_id”) ;

to

$d[‘shopper_group_id’] = ‘7’ ;

Thanks for pointing me in the right direction Dan.

Not that it matters, it will work how you have it, but 7 is an integer so it should technically be written as:


$d['shopper_group_id'] = 7;

Glad you figured it out.

Right, I’ll change it, thanks.