News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Reload previously stored cart after login doesn't work properly

Started by Dudebaker, October 22, 2021, 13:53:02 PM

Previous topic - Next topic

Dudebaker

The previously stored cart gets only reloaded from the database if the user is on the cart page while he does the login.
If he's on any other page as the cart page, the cart stays empty.

How to reproduce the bug:
1. Install Virtuemart Demo-Installation
2. Create a registered user
3. Add something to the cart and go to the cart (otherwise it will not be saved to the DB, that's another bug I think).
4. Logout
5. Go to the Homepage
6. Login --> no cart loaded in the cart module
7. Logout
8. Go to the Cart-Page
9. Login --> cart loaded in the cart module

I've tested this with the latest Demo-Installation (VirtueMart3.8.8_Joomla_3.9.24-Stable-Full_Package.zip) and even the later beta builds.
Sadly always the same bug.

How to fix the bug (quick and dirty but it does work):
- components/com_virtuemart/helpers/cart.php[line 222]
- change if(empty(JFactory::getUser()->guest) and !empty($sessionCart->_guest)){
- to if(empty(JFactory::getUser()->guest) and (!empty($sessionCart->_guest) || empty(self::$_cart->BT))){


As I saw some lines above this, there is already something a dev has tried [line 169]:
//if(empty($sessionCart->cartProductsData) or ($sessionCart->_guest and $sessionCart->_guest!=JFactory::getUser()->guest)){
I think this goes in the same direction to fix this issue, but wasn't finished


PS:
If you're using a Cart-Module which uses the function cart->prepareCartData() then the cart always gets loaded properly on every page after login where the module is visible.
The one I'm usually using from Virtueplanet does this, but on one customer-shop I have to hide it till the user is logged in (only registered access level).
And in this instance I've noticed the bug and testet it with the Virtuemart-Demo Package.

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Dudebaker

Thanks but now the cart keeps being empty after login, even on the cart page.

I think the line (the same as I did) you've changed is not corret.

Change:
if(VmConfig::isSite() and JFactory::getUser()->guest and (empty($sessionCart) or !empty($sessionCart->_guest)) ){
To:
if(VmConfig::isSite() and empty(JFactory::getUser()->guest) and (empty($sessionCart) or !empty($sessionCart->_guest)) ){

And the cart loads correct again on every page.

Milbo

of course yes. I accidently removed the empty, when I added the check for site.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/