shop:on_addToCart AJAX handler
Defined in |
/modules/shop/classes/shop_actions.php, lines 290-331 |
Author |
LemonStand eCommerce Inc. |
Adds a product to the shopping cart.
This AJAX handler can be used on the Product Details page or on any other page.
The following example demonstrates the simplest use case, when the handler used on the Product Page. In this case
the product identifier ( product_id) field element is not required.
<input onclick="return $(this).getForm().sendRequest(
'shop:on_addToCart',
{update: {'product_page': 'product_partial'}})"
type="button" value="Add to cart"/>
Field |
Type |
Description |
product_id |
integer |
specifies the product identifier. |
no_flash |
boolean |
disables the "The item has been added to your cart" message. |
message |
string |
the confirmation message string. |
product_cart_quantity |
integer |
specifies the number of products to add to the cart. |
cart_name |
string |
specifies the shopping cart name. |
redirect |
string |
optional URL to redirect the browser to. |
Supported form field details
¶
product_id form field
Specifies the product identifier.
This field is not required if the handler used on the Product Details page.
Example:
<input onclick="return $(this).getForm().sendRequest(
'shop:on_addToCart',
{
extraFields: {
'product_id': <?= $product->id ?>
},
onSuccess: function(){ alert('The product has been added to the cart'); }
})" type="button" value="Add to cart"/>
¶
no_flash form field
Disables the "The item has been added to your cart" message.
Possible values: 0, 1. By default the handler puts the message to the flash storage. The message can be displayed with flash_message() function.
¶
message form field
The confirmation message string.
Note that you should use the %s symbol in the message, to indicate a place where the product quantity should be inserted. Example:
<input onclick="return $(this).getForm().sendRequest(
'shop:on_addToCart',
{
extraFields: {message: 'Number of products added to the cart: %s'},
update: {'mini_cart': 'shop:mini_cart', 'product_page': 'product_partial'}})"
type="button" value="Add to cart"/>
¶
product_cart_quantity form field
Specifies the number of products to add to the cart.
The default value is 1.
¶
cart_name form field
Specifies the shopping cart name.
LemonStand support multiple shopping cart. By default the cart named main used.
Example:
<input onclick="return $(this).getForm().sendRequest(
'shop:on_addToCart',
{
extraFields: {
'cart_name': 'second_cart'
},
onSuccess: function(){ alert('The product has been added to the cart'); }
})" type="button" value="Add to cart"/>
¶
redirect form field
Optional URL to redirect the browser to.
Example:
<input onclick="return $(this).getForm().sendRequest(
'shop:on_addToCart',
{
extraFields: {
'redirect': '/checkout'
},
onSuccess: function(){ alert('The product has been added to the cart'); }
})" type="button" value="Add to cart"/>
|