Custom popup message for OnBeforeCartSave

  • Posts: 69
  • Thank you received: 3
  • Hikamarket Multivendor
4 days 13 hours ago #315702

Hello,

I have a onBeforeCartSave trigger and check several things to verify if the order is valid.
How can I change the popup message that is showed if the product could not be added to the cart when I set $do false..
I tried with the default joomla messages, but did not work.

if ($status == 'PlaceNotFound') {
$do = false;
$app = JFactory::getApplication();
$app->enqueueMessage( JText::sprintf( 'CUSTOM EROR MESSAGE FOR THE USER', $status));
return false;
}

Thank you and best regards

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

  • Posts: 68132
  • Thank you received: 10158
  • MODERATOR
4 days 7 hours ago #315705

Hi,

The add to cart is done in AJAX (with a call to the server by the javascript on the page without reloading the page). However, to display an error message via the Joomla message system requires a reload of the page.
So to do that, you would have to turn off the AJAX system. So in the view file displaying the add to cart button, you would have to remove the "onclick" attribute and it would fallback to adding the product with a full page reload.

However, I would rather recommend that you use HikaShop notification system to display your error message.
You can do that like this:

$cartClass = hikashop_get('class.cart');
$cartClass->addMessage($cart, array(
					'msg' => JText::sprintf( 'CUSTOM EROR MESSAGE FOR THE USER', $status),
					'product_id' => $product_id,
					'type' => 'error'
				));

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

Time to create page: 0.048 seconds
Powered by Kunena Forum