This is the documentation for LemonStand V1, which has been discontinued. You can learn more and upgrade your store here.

LemonStand Version 1 Has Been Discontinued

This documentation is for LemonStand Version 1. LemonStand is now offered as a cloud-based eCommerce platform.
You can try the new LemonStand and learn about upgrading here.

Creating a Shopping Cart Page

The cart page displays a list of items (active and postponed) in the shopping cart and the estimated total order cost. Customers can remove items from the cart or change the quantity of items. 

To create a cart page, start by creating a new page. Assign it a title and URL, for example /cart. The actual URL doesn't matter from LemonStand's point of view. You just need to specify the correct URL of the cart page on other pages.

Next, go to the Action tab and select the shop:cart action from the Action drop-down menu. The shop:cart action processes events such as changing the quantity of itmes ,moving or removing an item to the postponed items list, and deleting items (for consistency).

Creating a cart page

The shopping cart source code is simple. It outputs 2 lists of cart items for active and postponed items respectively. The code uses the same partial for displaying both lists.

<? 
  $active_items = Shop_Cart::list_active_items();
  $postponed_items = Shop_Cart::list_postponed_items();
?>
<?= flash_message() ?>
<? if ($active_items): ?>
  <?= open_form() ?>
    <? $this->render_partial('shop:cart_table', array('items'=>$active_items)) ?>
  
    <h3>Cart Total</h3>
    <p><?= format_currency($cart_total) ?></p>
  
    <h3>Discount</h3>
    <p><?= format_currency($discount) ?></p>

    <h3>Estimated Total</h3>
    <p><?= format_currency($estimated_total) ?></p>

    <p>* Shipping cost, taxes and discounts will be evaluated during the checkout process.</p>
    <label for="coupon_code">Do you have a coupon?</label> 
    <input id="coupon_code" value="<?= h($coupon_code) ?>" type="text" name="coupon"/>
    <input type="submit" value="Apply Changes"/>
  </form>   
<? else: ?>
  <p>Your cart is empty.</p>
<? endif ?>

<? if ($postponed_items): ?>
  <?= open_form() ?>
    <h3>Postponed items</h3>
    <? $this->render_partial('shop:cart_table', array('items'=>$postponed_items, 'postponed'=>true)) ?>
  
    <input type="submit" value="Apply Changes"/>
  </form>
<? endif ?>
{% set active_items = method('Shop_Cart', 'list_active_items') %}
{% set postponed_items = method('Shop_Cart', 'list_postponed_items') %}

{{ flash_message() }}
{% if active_items %}
  {{ open_form() }}
    {{ render_partial('shop:cart_table', {'items': active_items}) }}
  
    <h3>Cart Total</h3>
    <p>{{ cart_total|currency }}</p>
  
    <h3>Discount</h3>
    <p>{{ discount|currency }}</p>

    <h3>Estimated Total</h3>
    <p>{{ estimated_total|currency }}</p>

    <p>* Shipping cost, taxes and discounts will be evaluated during the checkout process.</p>
    <label for="coupon_code">Do you have a coupon?</label> 
    <input id="coupon_code" value="{{ coupon_code }}" type="text" name="coupon"/>
    <input type="submit" value="Apply Changes"/>
  </form>   
{% else %}
  <p>Your cart is empty.</p>
{% endif %}

{% if postponed_items %}
  {{ open_form() }}
    <h3>Postponed items</h3>
    {{ render_partial('shop:cart_table', {'items': postponed_items, 'postponed': true}) }}
    
    <input type="submit" value="Apply Changes"/>
  </form>
{% endif %}

The code fetches the lists of active and postponed cart items using the corresponding methods of the Shop_Cart class. The flash_message function is called to put out possible messages from LemonStand. Then the code checks whether $active_items and $postponed_items arrays have any items. If any items are found, a new FORM element is displayed and the item list is rendered using the shop:cart_table partial. We will explain how to create this partial later in this article. Also, if there are active items in the cart, the estimated total cost of the shopping cart is displayed.

Please note each list is wrapped in a separate html form. The Apply Changes button must be the submit type element.

There are AJAX handlers for all operations required for managing the shopping cart content, including the item deletions and applying changes. Please read the shop:cart action description for details. 

Next: Implementing the Shipping Cost Estimator Feature
Previous: Shopping Cart
Return to Shopping Cart