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.

 

Required manual refresh after changing virtuemart shopper group

Required manual refresh after changing virtuemart shopper group

I'm setting virtuemart shopper group based on geo location. Rule is executed only once per session and it works very nice.
I have different prices for GROUP A and for GROUP B.

After entering the page, I see in chameleon debug mode that shopping group is set properly, but on virtuemart there is default price displayed for each product (it should be price from selected shopper group). After manual refreshing the page - price is set propeply (from selected group). Any rule is executing after refreshing (I checked it in debug mode) - all rules has been success executed on the first page load (per session). The issue is on all virtuemart pages: category view, item view, shopping cart etc.

Real life example:
On e-shop there is default price 100 EUR for all customers and there is other price, e.g. 200 USD for customers from USA. Customer from USA enter on the page direct to item description and he will see default (100 EUR) price. If he refresh page (F5) than he will see correct price for his shopper group (200 USD). In Chameleon Debug I can see that shopper group has been set at the beginning - before displaying the page at the first time.

The question is:
Why refreshing page is required and how to fix it?

I'd like to mention then adding another chameleon rule for additional refreshing page does not resolve the problem - still manual user refresh (or change page to other in virtuemart) is required.
Price is only example - the same situation is if I choose product or category availability only for one shopper group.

I have tested it on latest J3.6.5 VM3.0.8 and Chameleon 2.6.3.

rvl
Beginner Modder
ranks
useravatar
Offline
6 Posts
Administrator has disabled public posting

Re: Required manual refresh after changing virtuemart shopper group

Thanks for this bug report. I'm looking at this now. Chameleon changes the shopper group by inserting a variable into the session, which VM picks up and uses the value (a shopper group id) to add to the array of shoppergroups of the current user. It's a sort of API provided by VM for this purpose.

Before I look at it I suspect that there's something in VM that is calculating the pricing for display BEFORE VM picks up the additional shopper group i.e. before Chameleon sets the session variable. It's also possible that a 3rd-party addition to VM may cause this. Do you have any other 3rd-party VM extensions installed?

Ok let's see what I can find...

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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Required manual refresh after changing virtuemart shopper group

Ok I just tested this, on VM 3.0.18 (more up to date than yours - perhaps the problem?)
I used the demo catalog and added a price for the Baseball Cap for £100, and a new shopper group called "GBP".
I set the £100 price for the GBP shopper group, and the €19 price for the default shopper group.
1st test for guest user shows the price as €19.
I added a Chameleon rule to add the GBP shopper group for all users.
2nd test: manually went to the same product page (direct link) and saw the equivalent of £100 in €. Then manually changed the currency and it displays as £100. I didn't need to force a (2nd) page refresh for any of these to happen, they just happened as soon as I navigated to the page.

Next I changed the rule to also set the currency (GBP).
I also created another rule to reverse the effects of the previous rule, setting the shopper group to Default and the currency to EUR.
3rd test: disabled the GBP rule, enabled the "reverse" rule, refreshed the page. Pricing reverts to €19
4th test: enabled the GBP rule, disabled the "reverse" rule, refreshed the page. Pricing changes to £100.

Conclusion:
- in this simple minimal case the currency and shopper group changes work as intended.
Q: Can you attempt a similar minimal setup and see if it works? (does not require GeoIP)
Q: Can you test this on a minimal site with VM3.0.8 and then with VM3.0.18 to see if that makes the difference? e.g. if you do a basic Joomla & VM install on a test site?
Q: What other VM extensions do you have installed?
Q: What's the order of System plugins on your site? Mine is:

System - Remember Me
System - FaLang Database Driver
shlib - Db query cache and programming library
sh404sef - System plugin
sh404sef - System mobile template switcher
System - Chameleon Actions
System - Chameleon
System - MetaMod Pro
etc.

Specifically, I'd be looking for any system plugins which are in order before the Chameleon ones, which might have anything to do with pricing display.

- I checked Chameleon's action for setting the shopper group. It simply sets a session variable "vm_shoppergroups_add". This is referenced in only 1 place in VM 3.0.18: models/shoppergroup.php:mergeSessionSgrps().
This is referenced only from models/shoppergroup.php:appendShopperGroups()
This is used in 2 places:
  helpers/calculationh.php:setShopperGroupIds()
  models/user.php:getUser()

I think 1 possibility might be any VM extension that references a VirtueMartModelUser object and calls getUser() on it. In this case getUser() caches previous data and doesn't check the vm_shoppergroups_add session variable. Instead, it should use getCurrentUser() which recalculates the user data including shopper groups from the session variable. If an extension uses getUser() too soon then it will pick up the new shopper group on the next page load, as it will get it from the session next time!

Anyway that's my educated guess as to what's happening. It may be due to some VM extension, or the outdated VM version, or possibly some particular order of operations that's happening on your site that causes VM to call getUser() too soon.

Please let me know how you get on.

Thanks,
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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Required manual refresh after changing virtuemart shopper group

Dear Stephen,

Thank you for reply.
I prepared you fresh install of Joomla (3.6.5) and VM (3.0.18.6) for tests.

1. I installed Chameleon 2.64 and Akeeba Backup,
2. I set two shopper groups (CUSTOMERS_EU and CUSTOMERS_WORLD)
3. I add new product and set 100 EUR price for CUSTOMERS_EU and 20 EUR price for CUSTOMERS_WORLD
4. I added Chameleon rules:
a. set customers country based on geo location (it set country field in shopping cart billing address)
b. check if customrs country is from EU and set shopper group to CUSTOMERS_EU if YES
c. check if customrs country is NOT from EU and set shopper group to CUSTOMERS_WORLD

Please open this direct link to product in incignito mode of browser (without any cache)
http://test.reveltronics.com/index.php/chameleon-detail

When you open it FIRST time you will not have price ("Call for price" button).
When you refresh page, than you will see price.
When you close tab in browser and you open it one more time - it will be ok (price will be displayed) - so it is important to test it on fresh session (e.g. in incognito mode)

PS. I sent you PM with details for admin login.

rvl
Beginner Modder
ranks
useravatar
Offline
6 Posts
Administrator has disabled public posting

Re: Required manual refresh after changing virtuemart shopper group

Hi,
thanks for the login and example - that's a huge help.
I notice that you are running quite a lot of PHP code in the early rules in order to extract the address from the cart or shopper records. This includes some code that deals with sessions. I think it's likely that this code is somehow initialising the user record with the default shopper groups (from the user record and/or from session variables that are already set), before Chameleon has a chance to set the new session variable with the new shopper group. Therefore when the price is displayed on the 1st page after the Chameleon rule is triggered, it doesn't yet recognise the fact that Chameleon set the new Shopper Group in the session variable.

I'll have a closer look at this tomorrow to see if there's a way Chameleon can invalidate the old user record so that when the prices are displayed it will create a new one, grabbing the current version of the session variable and shopper group.

Stand by... sorry we're in opposite time zones!

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
3329 Posts
User info in posts
Administrator has disabled public posting

Re: Required manual refresh after changing virtuemart shopper group

Yeah we are completly upside-down ;-)

I appreciate your help and I hope that we will find solution. I spent a lot of time on it but I do not have knowledge and experience about J3/VM3 API - maybe there is some workaround for it. I'll keep trying too because it is very important to me. Your Chameleon mod is the only one which meets my requirements (I have a lot of rules but I have limited it to minimum only for demo purpose).

rvl
Beginner Modder
ranks
useravatar
Offline
6 Posts
Administrator has disabled public posting

Re: Required manual refresh after changing virtuemart shopper group

Confirmed: it's this statement that causes the issue:

$cart = VirtueMartCart::getCart();

Now I'm working on how to get the cart object to recalculate the shopper groups in the user object after adding the new shopper group.

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
3329 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1696
Total Polls:
6
Total Posts:
5941
Posts this week:
7
User Info:
 
Total Users:
5418
Newest User:
outsd2
Members Online:
0
Guests Online:
121

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