Shopping Cart Based on Browser Session

  • Posts: 9
  • Thank you received: 0
9 years 5 months ago #204398

-- HikaShop version -- : 1504301217
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.6
-- Browser(s) name and version -- : All

I have multiple clients using the same user / pass for a fundraiser. It's easier to assign one user/pass to the organization to give out to 100 users vs creating 100 accounts. The purpose is to collect all the orders under one user/pass as well as the ability to show/hide specific Joomla menu items based on which organization logs in.

My problem is when I make them a registered user, the Hikacart automatically saves the cart in the database and everyone logged in can see it. For now, I have set the menu item to public so they can shop as a guest and log in at the very end, clearing the cart on purchase. It's a work around, but it prevents us from using the access levels in Joomla and if they click " continue shopping" at the end, then the cart is saved and the problem arises again. I've tried almost every option and I can't figure out a solution.

Is there a way around this, or do you have any suggestions?

Last edit: 9 years 5 months ago by 11Studios. Reason: rewording information

Please Log in or Create an account to join the conversation.

  • Posts: 26159
  • Thank you received: 4028
  • MODERATOR
9 years 5 months ago #204412

Hi,

The cart is based on the session when the user is not logged.
That information is also used for the logged user to retrieve their cart when they were not logged yet.
But when a user is logged, he has just one "current cart" and it will be difficult to change that except by modifying some HikaShop core files.
Maybe using a special "sort" in order to get the cart linked to the current session before the cart linked to the user.
But when the user will finish his order, he will retrieve another cart.. And when a user will log-in with any cart in session he will retrieve an existing cart... So it will be really really hard to say.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 9
  • Thank you received: 0
9 years 5 months ago #205099

Thank you for your response. It would be great to have this ability in future releases. I don't mind creating overrides for Hikashop, I've looked into some of the core files. I'm beginner / intermediate in PHP so some of the code was a little over my head. When you say edit the core, you are referencing I could test trying the following? Which file would I look in to start?

"Maybe using a special "sort" in order to get the cart linked to the current session before the cart linked to the user."

Right now, I have the cart prompt for user login when they go to pay. ( last step ).I wonder if I could edit the core to automatically submit the order and immediately log them out to a thank you page when they click "login". This way it clears the cart, logs them out preventing them from creating a new cart, thus solving the multiple cart issue for now. I can figure out another way to show / hide the links using a custom login separate from Joomla once I solve this.

Please Log in or Create an account to join the conversation.

  • Posts: 82910
  • Thank you received: 13379
  • MODERATOR
9 years 5 months ago #205144

What I would recommend is to modify the function restoreSession in the file plugins/system/hikashopuser/hikashopuser.php
This function is called when the user logs on the website.
You can see at the beginning some the code loading the cart from the anonymous session (before the login).
So you want to keep that.
What you can do is after that, is to check if you have something in $app->getUserState('com_hikashop.cart_id')
If not, it means that the user didn't already had a cart and you can run a query to remove all the carts of the user in the hikashop_cart and hikashop_cart_user tables.
If yes, it means that the user had a cart before logging in, and you can run a query to remove all the carts of the user in the hikashop_cart and hikashop_cart_user tables expect the one with the cart_id from the user state.

That shouldn't be too complex. The problem with this method, is that if you have two persons using the same account at the same time, they could delete one another's cart.

What Jerome suggests is better but way more complex to do. You basically need to modify the file administrator/components/com_hikashop/classes/cart.php in different places. It's not an easy thing and you risk breaking the system.

Please Log in or Create an account to join the conversation.

Time to create page: 0.057 seconds
Powered by Kunena Forum