shop:product
The shop:product action is designed for creating the Product page. The action loads a product by a product URL name specified in the page address and creates a corresponding PHP variable which you can use in the page code. Please read the Creating the Product page article for examples of the action usage.
Supported form fields
- product_cart_quantity – optional field. Specifies the number of items to add to the cart when a customer clicks the Add To Cart button.
- add_to_cart – the name of the Add To Cart button element. The button name is needed only if you use the regular POST (non AJAX) method.
Generated PHP variables
- $product – a product object. An object of the Shop_Product class. This variable can be NLL if a requested product was not found. Always check whether the variable is NULL and display a "product not found" message instead of a normal product page.
- $product_unavailable - indicates whether the product is out of stock or disabled. Check this variable to generate corresponding messages.
Supported AJAX handlers
- shop:on_addToCart – adds a product to the cart. Use this handler for creating an AJAX Add To Cart button. Example: It is possible to pass an identifier of a specific product to the handler:
<input onclick="return $(this).getForm().sendRequest( 'shop:on_addToCart', {update: {'product_page': 'product_partial'}})" type="button" value="Add to cart"/>The optional parameter no_flash forces LemonStand to not put the "The item has been added to your cart" message to the flash storage. Another optional parameter message allows you to customize the cart message. Please 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: { 'product_id': <?= $product->id ?>, 'no_flash': 1 }, onSuccess: function(){ alert('The product has been added to the cart'); } })" type="button" value="Add to cart"/>LemonStand supports multiple shopping carts. You can specify a name of a cart using the cart_name parameter in order to place a product into a specific shopping cart.<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"/>Also you can redirect a browser to another page after adding a product to the cart. Use the redirect parameter for that. 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"/>See also the Shop_Cart class and shop:cart action.<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"/>
Next: Shop_OrderItem
Previous: radio_state
Return to Reference

