Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
Can I use Chameleon to Show/Hide Shipment Methods in Vituemart.
Can I use Chameleon to Show/Hide Shipment Methods in Vituemart.
Shipment methods are attached to shopper groups in VM
I would like to use Chameleon to identify a custom shopper field in VM and if it's "true" add or remove a shopper group from the list of shopper groups the customer is attached to.
The purpose is to show hide shipment methods in VM cart based on shopper group.
Client has two shipping options:
1. Ship with customer's courier (We gather courier name and account number)
2. Handle shipping for customer
These choices are captured as custom shopper fields in VM
Can i use Chameleon PHP to identify them? Can I then use Chameleon to attach or remove a shopper group and hence show hide choices in cart?
Thoughts?
Re: Can I use Chameleon to Show/Hide Shipment Methods in Vituemart.
Hi,
Can you explain a bit more about the "custom shopper field in VM"? e.g. how did you create it, what sort of values does it contain, and how (& when) do these values get populated? I need this info to know how to retrieve the value.
With respect to setting shopper groups: yes this will probably work. At present, the GUI-based shopper group setting in Chameleon replaces the previously set group with the new group (rather than adding it to the list). However you can easily do it as an "add" using PHP:
$shopper_group = 11; // set the s.g. id here
$session = JFactory::getSession ();
$session->set ('vm_shoppergroups_add', $shopper_group, 'vm');
// bust the cache:
$usermodel = VmModel::getModel('user');
$usermodel->_id = -1; // invalidate so the getUser does not return previous cached value
$currentVMuser = $usermodel->getUser();
Cheers
Stephen
Re: Can I use Chameleon to Show/Hide Shipment Methods in Vituemart.
metamodguy wrote:
Can you explain a bit more about the "custom shopper field in VM"? e.g. how did you create it, what sort of values does it contain, and how (& when) do these values get populated?
Custom shopper field is a VM shopper field that is created apart from the standard set of VM shopper fields
It is created by VM admin in VM Shopper Fields
It is populated when shopper enters their account information (Address, name, instructions, etc)
In database, it is in: table: jos_virtuemart_userfields"
The options are 1: Please handle shipping for me, or 2: Please use my shipper
Re: Can I use Chameleon to Show/Hide Shipment Methods in Vituemart.
Try this. I set up my test so that the field name is "ShipSelect". Adjust the code below to reflect the name of your field.
Code:
JomGeniusClassVirtuemart::loadVmConfig();
$userModel = VmModel::getModel('user');
$userDetails = $userModel->getCurrentUser();
$userInfo = $userDetails->userInfo;
$session = JFactory::getSession ();
if (count($userInfo)) {
if (reset($userInfo)->ShipSelect == 1
or end($userInfo)->ShipSelect == 1) {
$shopper_group = 11; // set the s.g. id here
$session->set ('vm_shoppergroups_add', $shopper_group, 'vm');
$userModel->_id = -1; // invalidate so the getUser does not return previous cached value
$currentVMuser = $userModel->getUser();
}
if (reset($userInfo)->ShipSelect == 2
or end($userInfo)->ShipSelect == 2) {
$shopper_group = 12; // set the s.g. id here
$session->set ('vm_shoppergroups_add', $shopper_group, 'vm');
$userModel->_id = -1; // invalidate so the getUser does not return previous cached value
$currentVMuser = $userModel->getUser();
}
}
This combines a condition with an action, in the PHP tab of Chameleon. It's a little unusual (but ok) to do this. The code as presented needs to be edited to match 2 things:
1 - the name of your field (in my case it was ShipSelect)
2 - the shopper group to ADD for each ShipSelect field. In my case I used shopper groups 11 and 12.
Re: Can I use Chameleon to Show/Hide Shipment Methods in Vituemart.
I'd put in in the main PHP tab.
You *could* put it in the Succeed action if you want to – generally you might do that if there are other conditions that you want to check BEFORE you want to execute the code. You might do that if the code was computationally expensive and should only run on a certain page or other conditions.
Re: Can I use Chameleon to Show/Hide Shipment Methods in Vituemart.
Ok I've installed it and I've got it tentatively working but its not adding to shopper group lists, its replacing all of the shopper groups.
I am using chameleon to assign various shopper groups on visit by IP or on registration by city and state. All of these work and add shopper groups to the shopper.
The above code seems to replace all of the shopper groups that still need to be assigned.
Any thoughts
Re: Can I use Chameleon to Show/Hide Shipment Methods in Vituemart.
Hmmm, just make sure you AREN'T using the dropdown in the Succeed action to set the shopper groups - just use the code above. If you can confirm that you are not using the dropdown but are using the code, and are still getting the error, then I will go back and double check everything.
Cheers
Stephen
Re: Can I use Chameleon to Show/Hide Shipment Methods in Vituemart.
There is nothing in my succeed action at all
I have adjusted the code thus:
JomGeniusClassVirtuemart::loadVmConfig();
$userModel = VmModel::getModel('user');
$userDetails = $userModel->getCurrentUser();
$userInfo = $userDetails->userInfo;
$session = JFactory::getSession ();
if (count($userInfo)) {
if (reset($userInfo)-> ShippingOptions == 1
or end($userInfo)-> ShippingOptions == 1) {
$shopper_group = 33; // set the s.g. id here
$session->set ('vm_shoppergroups_add', $shopper_group, 'vm');
$userModel->_id = -1; // invalidate so the getUser does not return previous cached value
$currentVMuser = $userModel->getUser();
}
if (reset($userInfo)-> ShippingOptions == 2
or end($userInfo)-> ShippingOptions == 2) {
$shopper_group = 31; // set the s.g. id here
$session->set ('vm_shoppergroups_add', $shopper_group, 'vm');
$userModel->_id = -1; // invalidate so the getUser does not return previous cached value
$currentVMuser = $userModel->getUser();
}
}
Default PHP return value is true (Not sure if that makes a difference
Rule is set for all menu items on site
Re: Can I use Chameleon to Show/Hide Shipment Methods in Vituemart.
A thousand apologies, you're right that doesn't work. I am working on this, digging deep into VM to see what's going on. Hope to be able to give you a solution in the next 24 hours.
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Total Posts Today:
- 1
- User Info:
- Total Users:
- 7624
- Newest User:
- borger3298
- Members Online:
- 1
- Guests Online:
- 110
- Online:
- borger3298
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked