Author Topic: HOWTO: Automatically Assign Shopper Group During Registration (Checkout)  (Read 12975 times)

Inquisitor

  • Beginner
  • *
  • Posts: 1
Just would like to share a quick hack to get your registration form to automatically assign shopper group to the user.

In my case we needed to differentiate whether the user is a Travel Agent or not.
I had a bit of trouble finding the right answers, hence the post to help others.

Step 1: Add the checkbox in Manage User Fields




Step 2: Modify the file *Root*/administrator/components/com_virtuemart/classes/ps_shopper.php on line #419

Replace:

Code: [Select]
$d['shopper_group_id'] = $db->f("shopper_group_id");

I simply tested if the checkbox is set, but I don't think it will be too hard to test any other form element (note the field name from before):

Code: [Select]
if (isset($_POST['vm_travelagent']))
$shoppergroup = 7;
else
$shoppergroup = 5;

$d['shopper_group_id'] = $shoppergroup;




Now anyone who checks the box gets automatically assigned to the Travel Agent shopper group.

stavguru

  • Beginner
  • *
  • Posts: 2
Re: HOWTO: Automatically Assign Shopper Group During Registration (Checkout)
« Reply #1 on: January 09, 2011, 12:46:35 pm »
Hi Inquisitor,

I wanted just to comment on your post...

It is very good, it worked for me, and is very clean code!

Thanks for helping in general people to find solutions!!!

Nice one m8!!

lrossy

  • Beginner
  • *
  • Posts: 15
Re: HOWTO: Automatically Assign Shopper Group During Registration (Checkout)
« Reply #2 on: February 09, 2011, 17:43:42 pm »
Which files would you need to edit to make it assign to shopper group when modifing account information, after the account was already created?

lrossy

  • Beginner
  • *
  • Posts: 15
Re: HOWTO: Automatically Assign Shopper Group During Registration (Checkout)
« Reply #3 on: February 09, 2011, 18:42:09 pm »
Found the solution, open the

*Root*/administrator/components/com_virtuemart/classes/ps_shopper.php on line #748
after this code
      
Code: [Select]
if (!$db->num_rows()) {
//add

$shopper_db = new ps_DB;
// get the default shopper group
$q =  "SELECT shopper_group_id from #__{vm}_shopper_group WHERE ";
$q .= "`default`='1'";
$shopper_db->query($q);
if (!$shopper_db->num_rows()) {  // when there is no "default", take the first in the table
$q =  "SELECT shopper_group_id from #__{vm}_shopper_group";
$shopper_db->query($q);
}

$shopper_db->next_record();
$my_shopper_group_id = $shopper_db->f("shopper_group_id");
if (empty($d['customer_number'])) {
$d['customer_number'] = "";
}

$q  = "INSERT INTO #__{vm}_shopper_vendor_xref ";
$q .= "(user_id,vendor_id,shopper_group_id) ";
$q .= "VALUES ('";
$q .= $_SESSION['auth']['user_id'] . "','";
$q .= $_SESSION['ps_vendor_id'] . "','";
$q .= $my_shopper_group_id. "')";
$db->query($q);
}
Add this
      
Code: [Select]
//Start hack to update shopper group


else{
//enter your condition here
if (strlen($fields['vm_customfieldname']) >= 5)
//enter your shopper group to update to here if true
$shoppergroupUpdate = 8;
else
//enter shopper group id if false
$shoppergroupUpdate = 5;

$shopper_group_id = $shoppergroupUpdate;
$q2 = "UPDATE #__{vm}_shopper_vendor_xref ";
$q2 .= "SET shopper_group_id ='$shopper_group_id' ";
$q2 .= "WHERE user_id = '".$user_id."'";
$db->query($q2);
}
//End hack

C.Davis

  • Beginner
  • *
  • Posts: 9
Thanks so much; it works!

One thing I'm noticing though...

Our products will be having two prices: one for retail customers and one for wholesale customers. The customer is unable to see the wholesale price unless they have signed up as a wholesaler. However, I've discovered that if somebody is just viewing the products as a retail customer, the price is showing up as the total of the retail price and wholesale price. For example, a product is sold at $2 to a retail customer and $1 to a wholesale customer. The price shows up as $3 when viewing products as a retail customer or somebody who has yet to register. Is there a way around this, do you know? A round-about solution would be to just subtract the wholesale price from the retail price, so that when it adds the two together, it will be the correct retail price... Not having to do that would be ideal though. Any input on this matter is greatly appreciated.

Thanks so much for you help!


C.Davis

thomasdorman

  • Beginner
  • *
  • Posts: 1
I'm not a particularly experienced Joomla user: A quick note to others in my position.

Do not confuse the shopper group id with the number that is shown next to a group in the list of shopper groups.

Click on the user group and the id will appear in the URL of the resultant page. I just lost an afternoon of my life to this.

Idiot.

ledimeo

  • Beginner
  • *
  • Posts: 1
Hi, it works great, but not when user informations are updated.
I hacked as the 15th post shows, but without results..
What I've made wrong? Here is the code:
Code: [Select]
if (!$db->num_rows()) {
//add

$shopper_db = new ps_DB;
// get the default shopper group
$q =  "SELECT shopper_group_id from #__{vm}_shopper_group WHERE ";
$q .= "`default`='1'";
$shopper_db->query($q);
if (!$shopper_db->num_rows()) {  // when there is no "default", take the first in the table
$q =  "SELECT shopper_group_id from #__{vm}_shopper_group";
$shopper_db->query($q);
}

$shopper_db->next_record();
$my_shopper_group_id = $shopper_db->f("shopper_group_id");
if (empty($d['customer_number'])) {
$d['customer_number'] = "";
}

$q  = "INSERT INTO #__{vm}_shopper_vendor_xref ";
$q .= "(user_id,vendor_id,shopper_group_id) ";
$q .= "VALUES ('";
$q .= $_SESSION['auth']['user_id'] . "','";
$q .= $_SESSION['ps_vendor_id'] . "','";
$q .= $my_shopper_group_id. "')";
$db->query($q);
}

//Start hack to update shopper group
else {
//enter your condition here
if (strlen($fields['vm_herbalife']) > 5) {
//enter your shopper group to update to here if true
$shoppergroupUpdate = 6;
}
else {
//enter shopper group id if false
$shoppergroupUpdate = 5;
}
$shopper_group_id = $shoppergroupUpdate;
$q2 = "UPDATE #__{vm}_shopper_vendor_xref ";
$q2 .= "SET shopper_group_id ='$shopper_group_id' ";
$q2 .= "WHERE user_id = '".$user_id."'";
$db->query($q2);
}
//End hack

Please help me to solve this!!