Cart will not clear after purchase

  • Posts: 6
  • Thank you received: 0
10 years 3 weeks ago #178163

-- url of the page with the problem -- : localhost
-- HikaShop version -- : 2.3.4
-- Joomla version -- : 3.3.5
-- PHP version -- : 5.4.4
-- Browser(s) name and version -- : safari 7.0.6

Hi, I have created a payment plugin for {forte} payment gateway based on slight changes to the example payment plugin. I have a case where a customer may not be eligible to buy a product if they have not bought a previous product first. I am handling this by returning the user to the cart with an error message if they are attempting to purchase something they are not eligible for. They are prompted to remove the item and continue. This means that the cart can't be cleared until the order is confirmed. I have "clear cart when order is confirmed" selected but the cart never clears during checkout. I can verify in the database that the order has been confirmed. If I set "clear the cart when order is created" then it does clear but way too soon for my purposes. Here is my handler in onPaymentNotification for a approved transaction.

else //If everything's OK, order is validated -> success
{
$this->modifyOrder($order_id, $this->payment_params->verified_status, true, true);
$this->app->enqueueMessage("Your transaction was successful. If you purchased a trip, please submit your forms now. Separate forms must be submitted for each trip.");
$this->app->redirect($return_url);
return true;
}

is there a way to force a clear of the cart in this else block or is there another step I am missing? thanks

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 3 weeks ago #178167

Hi,

I don't know how your plugin is working but in general cases, you can't clear the cart during the notification.
The notification is generally used to get the server notifications, so you can't modify the user cart which is in the user session

The best is to clear it during the trigger onAfterOrderConfirm. using

$this->removeCart = true;

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: 6
  • Thank you received: 0
10 years 2 weeks ago #178518

OK, it seems to be that your answer is advocating cleaning the cart before I have processed a payment. Why would anybody want to do this? I think I am missing something here (and please clarify if I am) but I have a solution which APPEARS to work perfectly.

Could you tell me if I what I am doing is acceptable and will not cause any unforeseen issues. It all seems to work but I would like to confirm that it is not majorly flawed in a way that is not obvious to me right now.

1) I am displaying my payment form from onAfterOrderConfirm. The showpage(‘end’) call at the end of this function is displaying the payment page.
2) My payment page is posting data to onPaymentNotification where the transaction occurs. The reply from the processor is captured here.
3) If the transaction is declined, I redirect back to my payment form with an error message
4) If not, I apply my business logic and then delete the corresponding record from the jos_hikahop_cart table. This clears the cart AFTER I have confirmed that the transaction was successful, which is critical for me.

This is simple and it all seems to work but I don’t know if simply deleting one record is sufficient to completely cleanup after clearing the cart. It clears the cart but I don’t know other remnants are left in flags or session variables or other places that are going to cause me problems later.

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 2 weeks ago #178567

Hi,

If your user go back to the website, you can clean all the cart/checkout using that code

	$cart_id = $app->getUserState( HIKASHOP_COMPONENT.'.cart_id');
	if($cart_id) {
		$class = hikashop_get('class.cart');
		$class->delete($cart_id);
		$app->setUserState( HIKASHOP_COMPONENT.'.cart_id',0);
	}
	$app->setUserState( HIKASHOP_COMPONENT.'.coupon_code', '');
	$app->setUserState( HIKASHOP_COMPONENT.'.cc_number', '');
	$app->setUserState( HIKASHOP_COMPONENT.'.cc_month', '');
	$app->setUserState( HIKASHOP_COMPONENT.'.cc_year', '');
	$app->setUserState( HIKASHOP_COMPONENT.'.cc_CCV', '');
	$app->setUserState( HIKASHOP_COMPONENT.'.cc_type', '');
	$app->setUserState( HIKASHOP_COMPONENT.'.cc_owner', '');
	$app->setUserState( HIKASHOP_COMPONENT.'.cc_valid', 0);
	$app->setUserState( HIKASHOP_COMPONENT.'.checkout_terms', 0);
	$app->setUserState( HIKASHOP_COMPONENT.'.checkout_fields_ok', 0);
	$app->setUserState( HIKASHOP_COMPONENT.'.checkout_fields', null);
	$user = JFactory::getUser();
	if($user->guest) {
		$app->setUserState( HIKASHOP_COMPONENT.'.user_id', 0);
	}
But it requires that the user display a page ; a server notification won't do the trick.

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.

Time to create page: 0.058 seconds
Powered by Kunena Forum