Multi Carts don't work from front-end

  • Posts: 113
  • Thank you received: 18
12 years 1 month ago #71283

Experimenting with multi-carts, interesting concept, but creating a second cart from the front-end doesn't work. A message is displayed indicating the cart will be visible when products are added, but any newly added items go to the original cart.

The wishlists feature suffers from the same flaw. It works if you create new cart / wishlist from the back-end, but customers can't create more than one wishlist or cart.

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

  • Posts: 13201
  • Thank you received: 2322
12 years 1 month ago #71451

Hi,

In the file: "yourSite\administrator\component\com_hikashop\classes\cart.php" in the function "loadCart()" is the code:

if($app->getUserState(HIKASHOP_COMPONENT.'.'.$this->cart_type.'_new', '0') == '0'){
Commented ? If yes, just uncomment it and dont forget the "}" too.

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

  • Posts: 113
  • Thank you received: 18
12 years 1 month ago #71482

It isn't commented.
The described functionality doesn't work on your demo site either.

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

  • Posts: 13201
  • Thank you received: 2322
12 years 1 month ago #71584

Hi,

I tried on my end and this functionality is working fine, the correction will be in the next release which will arrive before the end of the month.

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

  • Posts: 24
  • Thank you received: 1
12 years 3 weeks ago #73505

I'm having the exact same problem. I thought, I just didn't get how to use the MultiCart/Wishlist feature, but reading the preceding posts I think this is a bug.
I can confirm that this isn't working on your demo page, either. (at least for Google Chrome 22.0.1229.79 - Windows 7)

In addition, this if statement you referred to:

Xavier wrote:

if($app->getUserState(HIKASHOP_COMPONENT.'.'.$this->cart_type.'_new', '0') == '0'){

does not even exist in my version (Business 1.6.0)

Last edit: 12 years 3 weeks ago by nik.mess. Reason: linking quote to post

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

  • Posts: 82867
  • Thank you received: 13374
  • MODERATOR
12 years 3 weeks ago #73688

As Xavier said, this has been corrected on our end and will be available in next version of HikaShop.
You can try the beta already here:
www.hikashop.com/en/forum/2-general-talk...ikashop-20-beta.html

The demo website doesn't have yet HikaShop 2.0 since it is still a beta, so it's normal that it doesn't work there.

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

  • Posts: 24
  • Thank you received: 1
12 years 3 weeks ago #73860

In that case, I misunderstood Xavier, sorry. I thought by "working on our end" he meant "should be working on yours, as well.

Thanks for your reply, I'm looking forward to Ver2!

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

  • Posts: 69
  • Thank you received: 11
12 years 3 weeks ago #74099

Hi,

I needed this working by tomorrow as it was presented to my client in a previous version ( we upgraded last week )

After some hour of testing, I did the following:

1. Add the given code line to the loadCart() method of the cart class: (and the closing bracket)

if($app->getUserState(HIKASHOP_COMPONENT.'.'.$this->cart_type.'_new', '0') == '0'){ 

2. Around line 74 of the cart controller, I changed:

From:
$app->setUserState(HIKASHOP_COMPONENT.'.'.$cart_type.'_new', '0');

To:
$app->setUserState(HIKASHOP_COMPONENT.'.'.$cart_type.'_new', '1');

This makes the userstate var be 1 until something else resets it to 0. This causes the loadCart() method to not load any cart.

3. In the same Cart controller file, in the addtocart() method, around line 130, there is a line for resetting the userState var to 0, but it is set after the class is instanced, so the class creates another new cart.

The only way to make it stop was by moving line 136 to line 118, to set the userState before the new call to the cart class. (line numbers may vary)

Like this-> screencast.com/t/JrgUlMNb3

It seems to be working for me with those mods. -> screencast.com/t/M5EuQ7Pp6

The only remaining broken thing is that it should mark the current cart as active...


Eduardo Chongkan - Likan Development
http://likandevelopment.com
The following user(s) said Thank You: nicolas

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

  • Posts: 24
  • Thank you received: 1
12 years 2 weeks ago #74403

Now, after installing HikaShop 2.0, I still couldn't get MultiCarts working properly.

Firstly, I got an error when trying to access "Show the carts" from the customer account page:
Fatal error: Call to a member function get() on a non-object in /var/www/components/com_hikashop/views/cart/view.html.php on line 248 (and 49 respectively)
I resolved this by commenting out the according lines in the view, since I don't intend to use wishlists anyway. Otherwise, this would probably pose another problem.

Secondly, HikaShop doesn't seem to load the current cart after user login. This might actually be a feature rather than a bug - maybe you don't want this stuff back anyway. However, I need to rely on the loaded cart having the same contents as the cart marked current in the MySQL table to manipulate these contents with ajax requests. I managed to write a module, that does this loading on login for me, but I fear that this will run into other problems sooner or later...1)
TL;DR: This script loads the last modified cart, makes it current and redirects to the index.php of your page

<?php
// This script loads sets the last modified cart as the current cart and redirects to /index.php
// I use this as a module, but it shouldn't matter how you execute this.
// You could even override a HikaShop View with it.
// You'll probably have to adjust a few things if you want to implement it (the ajax request URL, for example)

// Niklaus Messerli, Nov 2012

//don't allow other scripts to grab and execute our file
defined('_JEXEC') or die('Direct Access to this location is not allowed.');

if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){
	echo 'This module can not work without the Hikashop Component';
	return;
};

$myDatabase = JFactory::getDBO();

// get the id of the last modified cart for the current user
$query = "SELECT * FROM #__hikashop_cart WHERE `user_id`='".hikashop_loadUser(1)->id."' AND cart_modified=(SELECT MAX(cart_modified) FROM #__hikashop_cart)";
$myDatabase->setQuery($query);
$result = $myDatabase->query();
$cartId = $myDatabase->loadObject()->cart_id;
?>
<script type="text/javascript">
document.body.onload = function(){
	loadCart();
}

function loadCart(){
	<?php /* sends ajax request to load the right cart */ ?>
	document.getElementsByClassName('contentLayout')[0].innerHTML = '<h1 style="text-align:center !important;">Your login was successful. Please wait while you\'re being redirected.<h1>';
	var xmlHttp = null;
	try {
	    xmlHttp = new XMLHttpRequest();
	} catch(e) {
	    try {
	        xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch(e) {
	        try {
	            xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
	        } catch(e) {
	            xmlHttp  = null;
	        }
	    }
	}
	if (xmlHttp) {
	    xmlHttp.open('GET', '<?php JURI::base() ?>/index.php?option=com_hikashop&ctrl=cart&task=setcurrent&cart_id=<?php echo $cartId; ?>&cart_type=cart&Itemid=25', true);
	    xmlHttp.onreadystatechange = function () {
	        if (xmlHttp.readyState == 4) { 
				window.location = '<?php 
					if($_GET['redirectto'])	echo base64_decode($_GET['redirectto']);
					else { 
						JURI::base();
						echo "/index.php";
					}
				?>';
			}
	    };
	    xmlHttp.send(null);
	}
}
</script>
1)And it already did: This won't work, of course, if you log in through any "You must log in first" page rather than the original login page2)
2)Managed to get around that as well - by hacking the Joomla core though. I made the /components/com_user/controller.php redirect eeevery login to my module and pass the actual redirection url as a GET argument (base64 encoded). I added the ensuing decoding and redirecting to the code above.

Last edit: 12 years 2 weeks ago by nik.mess. Reason: resolved redirection issue mentioned in 1)

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

  • Posts: 69
  • Thank you received: 11
12 years 2 weeks ago #74432

I also noticed that carts are not marked as active in the showcarts view.


Eduardo Chongkan - Likan Development
http://likandevelopment.com

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

  • Posts: 24
  • Thank you received: 1
12 years 2 weeks ago #74478

likandev wrote: I also noticed that carts are not marked as active in the showcarts view.

Exactly - and I'm running into further problems with that.
Even though the most recently edited cart is now marked as current on login, you can still just delete the current cart and no cart will be marked current again. If you can just tell me where HikaShop decides which of the remaining carts to load (but not mark current), I could adjust that in my source code.

EDIT: Forgot to mention that I also seem to be unable to clear the cart from the HikaShop cart module ( X linking to index.php?option=com_hikashop&ctrl=product&task=cleancart&Itemid=...)

Last edit: 12 years 2 weeks ago by nik.mess.

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

  • Posts: 24
  • Thank you received: 1
12 years 2 weeks ago #74659

Phew! With the help of vast amounts of coffee, I finally got my stuff working.
For my product/listing_table view I used to look up the current cart in the MySQL database to display the respective quantities from the cart next to each product. Since the actually loaded carts on the front end sometimes don't (or better: hardly ever) correlate to the carts marked current in the MySQL table, this would not work anymore.

By digging around in the HikaShop source, I found out that I could use

$myApp = JFactory::getApplication();
$newCartId = $myApp->getUserState(HIKASHOP_COMPONENT.'.cart_id','0');
to retrieve the cart id of the currently loaded cart (which, in retrospective, I should have done from the beginning anyway).

This does, however, neither solve the issue
- that the current cart and the actually loaded cart may not be the same,
- that, on login, a new (empty) cart is created instead of the last one being loaded (I'm still relying on my module from above),
- nor that I'm still unable to clear a cart from the cart module (Which might be a good thing depending on your perspective - in that case, however, the clear (X) button shouldn't be displayed in the first place)

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

  • Posts: 69
  • Thank you received: 11
12 years 2 weeks ago #74660

Carts are also associated to session IDs. Also, if you are logging in, and if Hikashop doesn't auto load the cart, you shouldn't expect to find the correct cart ID in the session var.

Why don't you just put a cookie with the user's last cart ID and get the ID from there after login?

By using the cart helper class they put as an example in the documentation?


Eduardo Chongkan - Likan Development
http://likandevelopment.com
Last edit: 12 years 2 weeks ago by likandev.

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

  • Posts: 69
  • Thank you received: 11
12 years 2 weeks ago #74661

Nik, add me to skype: chongkan


Eduardo Chongkan - Likan Development
http://likandevelopment.com

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

  • Posts: 24
  • Thank you received: 1
12 years 2 weeks ago #74664

likandev wrote: Carts are also associated to session IDs. Also, if you are logging in, and if Hikashop doesn't auto load the cart, you shouldn't expect to find the correct cart ID in the session var.

That's why, on user login, I look up the last edited cart and set it as current. That way, HikaShop loads it.

Why don't you just put a cookie with the user's last cart ID and get the ID from there after login?

If I did that and the user deleted the currently loaded cart, another cart would be loaded by HikaShop rendering my cookie obsolete.

By using the cart helper class they put as an example in the documentation?

I found this in /components/com_hikashop/controllers/cart.php

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

Time to create page: 0.109 seconds
Powered by Kunena Forum