[Skip to main content](#vessel-content)

#   Custom popup message for OnBeforeCartSave

##

- **[tgdkere2](/forum/user/8136-tgdkere2 "View tgdkere2's Profile")**
- [![tgdkere2's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/8136-tgdkere2 "View tgdkere2's Profile") Topic Author
- [ Offline](/forum/user/8136-tgdkere2)

Less More

- Posts: 82
- Thank you received: 5
-
-

6 years 8 months ago [\#315702](#315702) by [tgdkere2](/forum/user/8136-tgdkere2 "View tgdkere2's Profile")  *[Custom popup message for OnBeforeCartSave](/forum/27-checkout/899192-custom-popup-message-for-onbeforecartsave#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-&gt;enqueueMessage( JText::sprintf( 'CUSTOM EROR MESSAGE FOR THE USER', $status)); return false; }  Thank you and best regards")* was created by *[tgdkere2](/forum/user/8136-tgdkere2 "View tgdkere2's Profile")*

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-&gt;enqueueMessage( JText::sprintf( 'CUSTOM EROR MESSAGE FOR THE USER', $status));
return false;
}

Thank you and best regards

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5OTE5Mi1jdXN0b20tcG9wdXAtbWVzc2FnZS1mb3Itb25iZWZvcmVjYXJ0c2F2ZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86359
- Thank you received: 14296
-
-

6 years 8 months ago [\#315705](#315705) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom popup message for OnBeforeCartSave](/forum/27-checkout/899192-custom-popup-message-for-onbeforecartsave#315705 "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-&gt;enqueueMessage( JText::sprintf( 'CUSTOM EROR MESSAGE FOR THE USER', $status)); return false; }  Thank you and best regards")*

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: Code:

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

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5OTE5Mi1jdXN0b20tcG9wdXAtbWVzc2FnZS1mb3Itb25iZWZvcmVjYXJ0c2F2ZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[tgdkere2](/forum/user/8136-tgdkere2 "View tgdkere2's Profile")**
- [![tgdkere2's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/8136-tgdkere2 "View tgdkere2's Profile") Topic Author
- [ Offline](/forum/user/8136-tgdkere2)

Less More

- Posts: 82
- Thank you received: 5
-
-

6 years 8 months ago [\#316049](#316049) by [tgdkere2](/forum/user/8136-tgdkere2 "View tgdkere2's Profile")  Replied by *[tgdkere2](/forum/user/8136-tgdkere2 "View tgdkere2's Profile")* on topic *[Custom popup message for OnBeforeCartSave](/forum/27-checkout/899192-custom-popup-message-for-onbeforecartsave#316049 "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-&gt;enqueueMessage( JText::sprintf( 'CUSTOM EROR MESSAGE FOR THE USER', $status)); return false; }  Thank you and best regards")*

Many thanks.
This works now.

How can I just get the product that was added to the cart (without looping through the full cart ?)
Can I also find out, why this trigger was called ? E.g. because a product was added or deleted etc ?
I only want to run my code, when a new product was added.

Thank you

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5OTE5Mi1jdXN0b20tcG9wdXAtbWVzc2FnZS1mb3Itb25iZWZvcmVjYXJ0c2F2ZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86359
- Thank you received: 14296
-
-

6 years 8 months ago [\#316051](#316051) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom popup message for OnBeforeCartSave](/forum/27-checkout/899192-custom-popup-message-for-onbeforecartsave#316051 "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-&gt;enqueueMessage( JText::sprintf( 'CUSTOM EROR MESSAGE FOR THE USER', $status)); return false; }  Thank you and best regards")*

Hi,

You have the information of the product_id being added in $_POST. Then, you can just load the product data from the hikashop_product table if you need some data from the product.

The information of what happened can't be known in this trigger.
However, you can use the onBeforeCartSave trigger to store what you have in the cart before in the database and compare it to what you have after.

But if you check the $_POST, you can directly check on the ctrl and task values in it. Code:

If($_POST['ctrl'] == 'product' &amp;&amp; $_POST['task'] == 'updatecart') { // the code in here will only run when a product is being added to the cart }

The cart modifications, deletions, etc will have different values in these variables

The following user(s) said Thank You: [tgdkere2](/forum/user/8136-tgdkere2 "View tgdkere2's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5OTE5Mi1jdXN0b20tcG9wdXAtbWVzc2FnZS1mb3Itb25iZWZvcmVjYXJ0c2F2ZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[tgdkere2](/forum/user/8136-tgdkere2 "View tgdkere2's Profile")**
- [![tgdkere2's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/8136-tgdkere2 "View tgdkere2's Profile") Topic Author
- [ Offline](/forum/user/8136-tgdkere2)

Less More

- Posts: 82
- Thank you received: 5
-
-

6 years 8 months ago [\#316084](#316084) by [tgdkere2](/forum/user/8136-tgdkere2 "View tgdkere2's Profile")  Replied by *[tgdkere2](/forum/user/8136-tgdkere2 "View tgdkere2's Profile")* on topic *[Custom popup message for OnBeforeCartSave](/forum/27-checkout/899192-custom-popup-message-for-onbeforecartsave#316084 "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-&gt;enqueueMessage( JText::sprintf( 'CUSTOM EROR MESSAGE FOR THE USER', $status)); return false; }  Thank you and best regards")*

Thank you, perfect ![:-)](/media/kunena/emoticons/3.png ":-)")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5OTE5Mi1jdXN0b20tcG9wdXAtbWVzc2FnZS1mb3Itb25iZWZvcmVjYXJ0c2F2ZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.056 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
