Author Topic: Reload previously stored cart after login doesn't work properly  (Read 762 times)

Dudebaker

  • Beginner
  • *
  • Posts: 10
Reload previously stored cart after login doesn't work properly
« on: October 22, 2021, 13:53:02 pm »
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
Code: [Select]
if(empty(JFactory::getUser()->guest) and !empty($sessionCart->_guest)){- to
Code: [Select]
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]:
Code: [Select]
//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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10213
  • VM3.9 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Reload previously stored cart after login doesn't work properly
« Reply #1 on: October 25, 2021, 15:45:58 pm »
Thank you for this report. I found a good fix.
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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10213
  • VM3.9 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
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

  • Beginner
  • *
  • Posts: 10
Re: Reload previously stored cart after login doesn't work properly
« Reply #3 on: October 28, 2021, 10:33:01 am »
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:
Code: [Select]
if(VmConfig::isSite() and JFactory::getUser()->guest and (empty($sessionCart) or !empty($sessionCart->_guest)) ){To:
Code: [Select]
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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10213
  • VM3.9 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Reload previously stored cart after login doesn't work properly
« Reply #4 on: October 28, 2021, 11:04:55 am »
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/