Old cart items are still showing up

  • Posts: 14
  • Thank you received: 0
9 years 1 month ago #217218

-- HikaShop version -- : 2.3.5
-- Joomla version -- : 3.3.6
-- PHP version -- : 5.5.15
-- Error-message(debug-mod must be tuned on) -- : Old cart items are still showing up

Old cart items are still showing up even after a successful order checkout, Below are steps to reproduce the scenario

1) A registered user, who is logged in, adds some items to their cart.
2) Then that user logs out or system Auto log out that User after they have been inactive for 15 minutes.
3) The user again add few items in the cart without loggin in and goes till that login step of checkout.
4) The user logs in and complete all the payment. Orders get confirmed.
5) Ideally the cart should get empty, but somehow those items which he added first time when he logged in, appears in cart.

Is there any way i can clear all the old cart items on successful payment?

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

  • Posts: 82909
  • Thank you received: 13379
  • MODERATOR
9 years 1 month ago #217252

Hi,

HikaShop supports multiple carts. So it keeps track of all the carts of the user and the user can manage them via his user control panel.
If you don't want that, try to add the code:

$config = hikashop_config();
			//delete old carts when a new cart is present and that the multicart mode is deactivated
			if( $app->isAdmin() && !$config->get('enable_multicart') && !empty($user['user_id']) ){
				$db = JFactory::getDBO();
				$db->setQuery('SELECT cart_id FROM #__hikashop_cart WHERE user_id='.(int)$user['user_id']);
				$ids = $db->loadObjectList('cart_id');
				if(isset($ids[$this->cart]))
					unset($ids[$this->cart]);
				if(count($ids)){
					foreach($ids as $id){
						$cartClass->delete($id,'old');
					}
				}
			}
after the code:
if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;
			$cartClass = hikashop_get('class.cart');
			$cartClass->initCart();
in the file plugins/system/hikashopuser.php and make sure that the "multiple cart" setting of the HikaShop configuration is turned off.

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

  • Posts: 14
  • Thank you received: 0
9 years 1 month ago #217296

Hi Nicolas,

Thank you for replying back.
I made the changes in the file plugins/system/hikashopuser.php and turned off the "multiple cart" setting of the HikaShop configuration.

function restoreSession(){
		$app = JFactory::getApplication();
			$cart = $app->getUserState('com_hikashop.cart_id');
		if(empty($cart) && !empty($this->cart)){
			$app->setUserState('com_hikashop.cart_id',$this->cart);
			if(!defined('DS'))
				define('DS', DIRECTORY_SEPARATOR);
			if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;
			$cartClass = hikashop_get('class.cart');
			$cartClass->initCart();
			$config = hikashop_config();
			//delete old carts when a new cart is present and that the multicart mode is deactivated
			if( $app->isAdmin() && !$config->get('enable_multicart') && !empty($user['user_id']) ){
				$db = JFactory::getDBO();
				$db->setQuery('SELECT cart_id FROM #__hikashop_cart WHERE user_id='.(int)$user['user_id']);
				$ids = $db->loadObjectList('cart_id');
				if(isset($ids[$this->cart]))
					unset($ids[$this->cart]);
				if(count($ids)){
					foreach($ids as $id){
						$cartClass->delete($id,'old');
					}
				}
			}
		}

But the old cart items still appeared after the successful order. I also tried to debug the code and added an echo exit in the

if(empty($cart) && !empty($this->cart)){

condition, it does not go inside this condition on order completion. Maybe i'm doing something wrong.

Last edit: 9 years 1 month ago by blacknine.

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

  • Posts: 13201
  • Thank you received: 2322
9 years 1 month ago #217420

Hi,

Please replace the current function "restoreSession()" by:

	function restoreSession(&$user_id){
		$app = JFactory::getApplication();
		$cart = $app->getUserState('com_hikashop.cart_id');
		//it's really important to check on $cart, otherwise, it doesn't work with the normal joomla login
		if(empty($cart) && !empty($this->cart)){
			$app->setUserState('com_hikashop.cart_id',$this->cart);
			if(!defined('DS'))
				define('DS', DIRECTORY_SEPARATOR);
			if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;
			$cartClass = hikashop_get('class.cart');
			$cartClass->initCart();
		}

		if(!empty($cart) || !empty($this->cart)){
			$config = hikashop_config();
			//delete old carts when a new cart is present and that the multicart mode is deactivated
			if( !$app->isAdmin() && !$config->get('enable_multicart') && !empty($user_id) ){
				$db = JFactory::getDBO();
				$db->setQuery('SELECT cart_id FROM #__hikashop_cart WHERE user_id='.(int)$user_id).' AND cart_type = '.$db->Quote('cart');
				$ids = $db->loadObjectList('cart_id');
				if(isset($ids[$this->cart]))
					unset($ids[$this->cart]);
				if(count($ids)){
					$cartClass = hikashop_get('class.cart');
					foreach($ids as $id){
						$cartClass->delete($id->cart_id,'old');
					}
				}
			}
		}

		$wishlist = $app->getUserState('com_hikashop.wishlist_id');
		//it's really important to check on $wishlist, otherwise, it doesn't work with the normal joomla login
		if(empty($wishlist) && !empty($this->wishlist)){
			$app->setUserState('com_hikashop.wishlist_id',$this->wishlist);
			if(!defined('DS'))
				define('DS', DIRECTORY_SEPARATOR);
			if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;
			$cartClass = hikashop_get('class.cart');
			$cart_type = JRequest::getString('cart_type','cart');
			JRequest::setVar('cart_type','wishlist');
			$cartClass->initCart();
			JRequest::setVar('cart_type',$cart_type);
		}
		$entries = $app->getUserState('com_hikashop.entries_fields');
		if(empty($entries) && !empty($this->entries)){
			$app->setUserState('com_hikashop.entries_fields',$this->entries);
		}
		$currency = $app->getUserState('com_hikashop.currency_id');
		if(empty($currency) && !empty($this->currency)){
			$app->setUserState('com_hikashop.currency_id',$this->currency);
		}
		$checkout_fields_ok = $app->getUserState('com_hikashop.checkout_fields_ok');
		if(empty($checkout_fields_ok) && !empty($this->checkout_fields_ok)){
			$app->setUserState('com_hikashop.checkout_fields_ok',$this->checkout_fields_ok);
		}
		$checkout_fields = $app->getUserState('com_hikashop.checkout_fields');
		if(empty($checkout_fields) && !empty($this->checkout_fields)){
			$app->setUserState('com_hikashop.checkout_fields',$this->checkout_fields);
		}
		//on some servers with some osbcure config, we really need to force the fields value in the POST/REQUEST as the checkout tries to get them from there after the login
		if(!empty($this->checkout_fields)){
			foreach($this->checkout_fields as $k =>$v){
				if(!isset($_REQUEST['data']['order'][$k])){
					$_POST['data']['order'][$k] = $_REQUEST['data']['order'][$k] = $v;
				}
			}
		}
	}

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

  • Posts: 14
  • Thank you received: 0
9 years 1 month ago #217430

Thank you for replying back.

Unfortunately i'm getting an error

Fatal error: Call to undefined function hikashop_config() in /****/****/public_html/plugins/system/hikashopuser/hikashopuser.php on line 107

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

  • Posts: 14
  • Thank you received: 0
9 years 1 month ago #217433

I somehow fixed that fatal error by pasting

function restoreSession($user){
		$app = JFactory::getApplication();
			$cart = $app->getUserState('com_hikashop.cart_id');
		if(empty($cart) && !empty($this->cart)){
			$app->setUserState('com_hikashop.cart_id',$this->cart);
			if(!defined('DS'))
				define('DS', DIRECTORY_SEPARATOR);
			if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;
			$cartClass = hikashop_get('class.cart');
			$cartClass->initCart();
		}
		if(!defined('DS'))
				define('DS', DIRECTORY_SEPARATOR);
			if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;

		if(!empty($cart) || !empty($this->cart)){
			$config = hikashop_config();
			//delete old carts when a new cart is present and that the multicart mode is deactivated
			if( !$app->isAdmin() && !$config->get('enable_multicart') && !empty($user['id']) ){
				$db = JFactory::getDBO();
				$query = $db->getQuery(true);
				$query->setQuery('SELECT cart_id FROM #__hikashop_cart WHERE user_id='.(int)$user['id']).' AND cart_type = '.$db->Quote('cart');
				$db->setQuery($query);
				$ids = $db->loadObjectList('cart_id');
				if(isset($ids[$this->cart]))
					unset($ids[$this->cart]);
				if(count($ids)){
					$cartClass = hikashop_get('class.cart');
					foreach($ids as $id){
						$cartClass->delete($id->cart_id,'old');
					}
				}
			}
		}

		$wishlist = $app->getUserState('com_hikashop.wishlist_id');
		if(empty($wishlist) && !empty($this->wishlist)){
			$app->setUserState('com_hikashop.wishlist_id',$this->wishlist);
			if(!defined('DS'))
				define('DS', DIRECTORY_SEPARATOR);
			if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true;
			$cartClass = hikashop_get('class.cart');
			$cart_type = JRequest::getString('cart_type','cart');
			JRequest::setVar('cart_type','wishlist');
			$cartClass->initCart();
			JRequest::setVar('cart_type',$cart_type);
		}
		$entries = $app->getUserState('com_hikashop.entries_fields');
		if(empty($entries) && !empty($this->entries)){
			$app->setUserState('com_hikashop.entries_fields',$this->entries);
		}
		$currency = $app->getUserState('com_hikashop.currency_id');
		if(empty($currency) && !empty($this->currency)){
			$app->setUserState('com_hikashop.currency_id',$this->currency);
		}
		$checkout_fields_ok = $app->getUserState('com_hikashop.checkout_fields_ok');
		if(empty($checkout_fields_ok) && !empty($this->checkout_fields_ok)){
			$app->setUserState('com_hikashop.checkout_fields_ok',$this->checkout_fields_ok);
		}
		$checkout_fields = $app->getUserState('com_hikashop.checkout_fields');
		if(empty($checkout_fields) && !empty($this->checkout_fields)){
			$app->setUserState('com_hikashop.checkout_fields',$this->checkout_fields);
		}
		if(!empty($this->checkout_fields)){
			foreach($this->checkout_fields as $k =>$v){
				if(!isset($_REQUEST['data']['order'][$k])){
					$_POST['data']['order'][$k] = $_REQUEST['data']['order'][$k] = $v;
				}
			}
		}
	}

But still that does not solve my problem. Old items still appeared in my cart when i completed an order.

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

  • Posts: 82909
  • Thank you received: 13379
  • MODERATOR
9 years 1 month ago #217531

Note that Xavier is not here until Monday. So he'll look at that then as he is the specialist on that matter. Sorry for the delay

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

  • Posts: 13201
  • Thank you received: 2322
9 years 1 month ago #217692

Hi,

There was some code to edit in the function "onLoginUser()" too, but I forgot to mention it in the previous post, my bad.
So please install this attached plugin, this will replace the current one and will solve you issue.

File Attachment:

File Name: plg_system...user.zip
File Size:5 KB


Please give us a feedback about this patch, based on your feedback, we will integrate it in the next release.

Attachments:
Last edit: 9 years 1 month ago by Xavier.

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

Time to create page: 0.094 seconds
Powered by Kunena Forum