Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Joomla user to Virtuemart Shopper Group

Joomla user to Virtuemart Shopper Group

I found a post by you in a thread from a year ago where you said

"You can set up a rule that says ‘Is user in "Premium" user group? If so, put them into "Premium" shopper group’, then set up another similar rule per group.

In this way, RSMembership or other user group components are able to control shopper groups."

this is exactly the behaviour i want, but I cannot seem to figure out how to make it so

what I have tried
A
1) created new rule
2) went to 'users groups' tab selected group 'gold member'
3) went to ACTIONS on succeed column I selected the VM shopper group  'gold member'
saved
B
1) created new rule
2) went to 'users groups' tab selected group 'gold member'
3) went to PHP added
/* rule succeeded: */
return true;
4) went to ACTIONS on succeed column I selected the VM shopper group  'gold member'
saved

not sure what else to try - any suggestions would be greatly appreciated

dsrpmedia
Beginner Modder
ranks
useravatar
Offline
8 Posts
Administrator has disabled public posting

Re: Joomla user to Virtuemart Shopper Group

Hi dsrpmedia,

Your option (A) should work. It maps anyone in the GOLD user group into the GOLD shopper group.
I suggest that you turn on debug mode in the Chameleon Options panel and watch what happens on the front end when someone in the GOLD user group logs in. You should see some messages about detecting the user group and setting the shopper group. It's possible that there may have been other rules before this one (in the rule chain) that prevented this rule from being run? Anyway, that's a good debugging tool. If you see the correct detection and shopper group setting being reported there, but the VM pricing doesn't seem to relate to the GOLD group, then that's obviously a deeper problem and I can help investigate.

Cheers
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Joomla user to Virtuemart Shopper Group

thank you for getting back to me!

I thought when I was doing it that A should work

it is the only rule I have published.

maybe I am misunderstanding how the shopper group correlation works.

I am using this in conjunction with a membership component --> when membership is activated users are placed in the gold user level, and put back into plain 'registered' when membership expires.

I was thinking that chameleon would actually update the virtuemart shopper group of the user when the joomla user group is updated, eg if I change a user to 'gold level' member, then go to virtuemart users / shoppers they should then be listed in the relevant shopper group, but this is not happening.

Does chameleon actually change the users shpper group or does it just reflect that shopper groups pricing?
If it some how 'virtually' adds to a group without actually adding to the group will things like acymailing work where newsletters are targeted to shopper groups?
------------------------------
one thing I wasn `t clear on, though I have tried it each way with no effect - the radio buttons under 'Next action' come before the virtuemart shpper group drop down - do they come into play for this rule?
I need no special action other than shopper group changing when user group does.

dsrpmedia
Beginner Modder
ranks
useravatar
Offline
8 Posts
Administrator has disabled public posting

Re: Joomla user to Virtuemart Shopper Group

here is the result of the debug when logging in as the user I just set to 'gold member' status
-----------------------------
Message
CHAMELEON DEBUG ON
Current date and time: "2017-08-10 11:56:35am" in timezone "America/Vancouver"
Processing rule id 4 ("Member to Shopper Group")
- Groups: User is a member of a selected group - succeeding
Started SUCCEED action for rule id 4
- VM action: setting shopper group id to 3
Finished SUCCEED action: default template style not changed
Stopped processing as result of SUCCEED action at rule id 4 ("Member to Shopper Group")
Final template style unchanged
-----------
this looks like it was successful?
BUT when I look in the backend the user is still listed as 'default' shopper group instead of 'gold level' shopper group

dsrpmedia
Beginner Modder
ranks
useravatar
Offline
8 Posts
Administrator has disabled public posting

Re: Joomla user to Virtuemart Shopper Group

Hi dsrpmedia:

sorry for dropping the ball on this thread.

You asked:

Does chameleon actually change the users shopper group or does it just reflect that shopper groups pricing?
If it some how 'virtually' adds to a group without actually adding to the group will things like acymailing work where newsletters are targeted to shopper groups?

You've hit the nail on the head: Chameleon only does a "virtual" shopper group switch, so that things like pricing show up according to the given shopper group, for that user in that session. It does not actually switch the shopper group for that user in the database.

There's no reason why this can't be done though. A snippet of PHP in the Succeed action should be enough to change the user's record in the database and add the shopper group there. If you still need this, please let me know and I'll put something together for you.

Best regards,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Joomla user to Virtuemart Shopper Group

I found the same stackiverflow article the previous poster mentioned and would love to be able to add / remove those into or out of vm shopper groups based on chamelon rules.  If you have the time to whip something up, I would definitley put it to use.... smile


All the best,

Adam

amelcher
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Joomla user to Virtuemart Shopper Group

Hi Adam,

I've just tried this out and it seems to work. The challenge was that until the new user is saved to the database, there's nowehere to save the new shopper group ID. Therefore, you have to use both methods at the same time: Chameleon's system of on-the-fly shopper group setting, AND the code below. So, in the Succeed Action, use the dropdown to select the new shopper group, and use the following PHP:

if ($user->id) { // only do the following if there's a user to save
    $sg = 4; // this is the ID of the new shopper group you are going to save in the user's record

    if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/config.php');
    if (!class_exists('VmModel')) require(VMPATH_ADMIN.DS.'helpers'.DS.'vmmodel.php');

    $shoppergroupData = array('virtuemart_user_id'=>$user->id,'virtuemart_shoppergroup_id'=>$sg);
    $userModel = VmModel::getModel('user');
    $user_shoppergroups_table = $userModel->getTable('vmuser_shoppergroups');
    $res = $user_shoppergroups_table -> bindChecknStore($shoppergroupData);
    if(!$res){
        vmError('Set shoppergroup error');
    }
}

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Joomla user to Virtuemart Shopper Group

Awesome! if we manually changed their status back to another user group would this also remove them from the existing usergroup and add them to the new one or would it just add them to the new one without removing them from the first group? Thanks fo much!

amelcher
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: Joomla user to Virtuemart Shopper Group

Hi amelcher,

I've done quite a lot of work on this as it's quite complex. I have things working well (I think) in the case that the user is logged in, so you can use this to add or move shopper groups from the user's record. What I haven't worked on is what happens for a non logged in user. This is because in that case, the shopper group is held in the session instead of the database, and there's a different mechanism for that.

The following code can be used inside the PHP box in the ACTIONS tab of Chameleon rule. It can go in either the Succeed or Fail action.

The line in here that adds a particular group is this:
if (!in_array("5", $sgroups)) $sgroups[] = 5;
i.e. if the user is not already in group 5, add group 5 to the list before saving it.

Have a go at this and see if it works for you smile

Cheers
Stephen


if ($user->id) { // ensure there's a logged in user.
    if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/config.php');
    if (!class_exists('VmModel')) require(VMPATH_ADMIN.DS.'helpers'.DS.'vmmodel.php');

    $session = JFactory::getSession ();
    $session->set ('vm_shoppergroups_add', null, 'vm');
    $session->set ('vm_shoppergroups_remove', null, 'vm');

    $userModel = VmModel::getModel('user');
    $userModel->_data = null; // invalidate so the getUser does not return previous cached value
    $userModel->_id = $user->id;

    $vuser = $userModel->getUser();
    // get the current groups for this user
    $sgroups = $vuser->shopper_groups;
   
    // if they were not already in group 5, add group 5 to the list.
    if (!in_array("5", $sgroups)) $sgroups[] = 5;

    // set the new shopper groups
    $shoppergroupData = array('virtuemart_user_id'=>$user->id,'virtuemart_shoppergroup_id'=>$sgroups);
    $user_shoppergroups_table = $userModel->getTable('vmuser_shoppergroups');
    $res = $user_shoppergroups_table -> bindChecknStore($shoppergroupData);
    if(!$res){
        vmError('Set shoppergroup error');
        $noError = false;
    }
}

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1686
Total Polls:
6
Total Posts:
5933
Total Posts Today:
7
User Info:
 
Total Users:
4432
Newest User:
kinggambling14
Members Online:
0
Guests Online:
150

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked