- Posts: 14
- Thank you received: 0
Old cart items are still showing up
10 years 11 months ago #217218
by blacknine
Old cart items are still showing up was created by blacknine
-- 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?
-- 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.
10 years 11 months ago #217252
by nicolas
Replied by nicolas on topic Old cart items are still showing up
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:
after the code:
in the file plugins/system/hikashopuser.php and make sure that the "multiple cart" setting of the HikaShop configuration is turned off.
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:
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');
}
}
}
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();
Please Log in or Create an account to join the conversation.
10 years 11 months ago - 10 years 11 months ago #217296
by blacknine
Replied by blacknine on topic Old cart items are still showing up
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.
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
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.
Code:
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
condition, it does not go inside this condition on order completion. Maybe i'm doing something wrong.if(empty($cart) && !empty($this->cart)){
Last edit: 10 years 11 months ago by blacknine.
Please Log in or Create an account to join the conversation.
10 years 11 months ago #217420
by Xavier
Replied by Xavier on topic Old cart items are still showing up
Hi,
Please replace the current function "restoreSession()" by:
Please replace the current function "restoreSession()" by:
Code:
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.
10 years 11 months ago #217430
by blacknine
Replied by blacknine on topic Old cart items are still showing up
Thank you for replying back.
Unfortunately i'm getting an error
Unfortunately i'm getting an error
Code:
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.
10 years 11 months ago #217433
by blacknine
Replied by blacknine on topic Old cart items are still showing up
I somehow fixed that fatal error by pasting
But still that does not solve my problem. Old items still appeared in my cart when i completed an order.
Code:
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.
10 years 11 months ago #217531
by nicolas
Replied by nicolas on topic Old cart items are still showing up
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.
10 years 11 months ago - 10 years 11 months ago #217692
by Xavier
Replied by Xavier on topic Old cart items are still showing up
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.
Please give us a feedback about this patch, based on your feedback, we will integrate it in the next release.
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.
This attachment is hidden for guests.
Please log in or register to see it.
Please log in or register to see it.
Please give us a feedback about this patch, based on your feedback, we will integrate it in the next release.
Last edit: 10 years 11 months ago by Xavier.
Please Log in or Create an account to join the conversation.
Time to create page: 0.206 seconds