- Posts: 82
- Thank you received: 5
Custom popup message for OnBeforeCartSave
6 years 7 months ago #315702
by tgdkere2
Custom popup message for OnBeforeCartSave was created by tgdkere2
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
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.
6 years 7 months ago #315705
by nicolas
Replied by nicolas on topic Custom popup message for OnBeforeCartSave
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:
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->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.
6 years 7 months ago #316049
by tgdkere2
Replied by tgdkere2 on topic Custom popup message for OnBeforeCartSave
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
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 or Create an account to join the conversation.
6 years 6 months ago #316051
by nicolas
Replied by nicolas on topic Custom popup message for OnBeforeCartSave
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.
The cart modifications, deletions, etc will have different values in these variables
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' && $_POST['task'] == 'updatecart') {
// the code in here will only run when a product is being added to the cart
}
The following user(s) said Thank You: tgdkere2
Please Log in or Create an account to join the conversation.
6 years 6 months ago #316084
by tgdkere2
Replied by tgdkere2 on topic Custom popup message for OnBeforeCartSave
Thank you, perfect
Please Log in or Create an account to join the conversation.
Time to create page: 0.209 seconds