Using partials instead of flash messages
Each AJAX call in LemonStand can accept the flash_partial POST parameter, which determines which partial LemonStand should render when the request completes. If this parameter is presented, flash_message() function renders a partial instead if displaying the standard flash message. You can use this feature for displaying formatted messages in response of visitor's actions. For example, the "The product has been added to the cart" message could output a link to the cart page.
Example of the Add to Cart button:
<input onclick="return $(this).getForm().sendRequest('shop:on_addToCart', {
extraFields: {
flash_partial: 'add_to_cart_partial'
},
update: {'mini_cart': 'shop:mini_cart', 'product_page': 'product_partial'}})"
type="button" value="Add to cart"/>The add_to_cart_partial partial should exist and should contain a HTML-formatted message to be displayed. Partial example:
<p>The product has been added to the <a href="/cart">cart</a>.</p>
Inside partials rendered using the flash_partial feature, you can access the original flash message text using the $message variable:
<p><?= h($message) ?></p> <p>Proceed to the <a href="/cart">cart</a>.</p>
Next: Implementing the "Ship to the billing address" checkbox on the checkout page
Previous: Automatic customer registration
Return to Tips and Tricks


Comments
Kennedy
Wednesday, September 08, 2010Just want to confirm that where ever "<?= flash_message() ?>" is placed the message will show up.
Regan Shepherd
Wednesday, December 01, 2010Is there a way to work the product name into the message.
<p>Your iPhone has been added to your <a href="/cart"> shopping cart</a>.</p>
Aleksey Bobkov
Wednesday, December 01, 2010@Regan Shepherd
You can try the following. In the partial code, extract the product name from the POST variables:
<p>Your <?= h(post('product_name')) ?> has been added to the <a href="/cart">cart</a>.</p>
In the AJAX request, pass the product_name parameter through the extraFields parameter:
<input onclick="return $(this).getForm().sendRequest('shop:on_addToCart', {
extraFields: {
flash_partial: 'add_to_cart_partial',
product_name: '<?= str_replace("'", "\'", $product->name) ?>'
},
update: {'mini_cart': 'shop:mini_cart', 'product_page': 'product_partial'}})"
type="button" value="Add to cart"/>
Add your comment
Loading form...