LemonStand Wiki

Creating the Shipping Method partial

The Shipping Method partial contains a form for selecting a suitable shipping method from the list of available methods. LemonStand prepares the list of available shipping methods basing on the shipping information provided by a customer on a Shipping Information checkout step. The list of available shipping methods is presented by the $shipping_options PHP variable supplied by LemonStand.

Start with creating a new partial. According to the code example in the Checkout Page partial, the name of the Billing Information partial should be shop:checkout_shipping_method. You can use any name for partials in your store.

The $shipping_options variable contains a list of available shipping options. Some shipping methods, like UPS, can provide multiple shipping options - for example UPS Express and UPS Standard. The code which displays the shipping option list must check the multi_option field of each object in the $shipping_options collection in order to create corresponding markup for single option and multi option payment methods.

The following code demonstrates an example of the Shipping Method partial code:

<h3>Shipping Method</h3>
<? if (count($shipping_options)): ?>
  <p>Please select shipping option.</p>
  <? foreach ($shipping_options as $option): ?>
    <? if ($option->multi_option): ?>
    
      <h5><?= h($option->name) ?></h5>
      
      <? if ($option->description): ?>
        <p><?= h($option->description) ?></p>
      <? endif ?>               

      <? foreach ($option->sub_options as $sub_option): ?>
        <input <?= radio_state($option->id == $shipping_method->id && $sub_option->id == $shipping_method->sub_option_id) ?> 
          id="<?= 'option'.$sub_option->id ?>" type="radio" name="shipping_option" value="<?= $sub_option->id ?>"/>
        <label for="<?= 'option'.$sub_option->id ?>">
  <?= h($sub_option->name) ?> - <strong><?= !$sub_option->is_free ? format_currency($sub_option->quote) : 'free!' ?></strong>
        </label><br/>
      <? endforeach ?>
      
    <? else: ?>
    
      <input <?= radio_state($option->id == $shipping_method->id) ?> id="<?= 'option'.$option->id ?>" 
        type="radio" name="shipping_option" value="<?= $option->id ?>"/>
      <label for="<?= 'option'.$option->id ?>">
  <strong><?= h($option->name) ?></strong> - <strong><?= !$option->is_free ? format_currency($option->quote) : 'free!' ?></strong>
        <? if ($option->description): ?>
          <br/><?= h($option->description) ?>
        <? endif ?>
      </label><br/>
      
    <? endif ?>
  <? endforeach ?>  
  <input type="hidden" name="checkout_step" value="<?= $checkout_step ?>"/>
  <input type="image" src="/resources/images/btn_next.gif" alt="Next" onclick="return $(this).getForm().sendRequest(
    'on_action', {update:{'checkout_page': 'checkout_partial'}})"/>
<? else: ?>
  <p>There are no shipping options available for your location.</p>
<? endif ?>

The code checks whether the $shipping_options array contains any shipping options. If there are no shipping options available, the corresponding message is displayed. Otherwise, the foreach PHP loop is used for iterating over the list of shipping options. For each shipping option the code outputs a label and a radio button control. For multiple option shipping method, the method header is displayed before the list of options. The label element contains the shipping option name, shipping quote, and shipping option description. Please note the value of the radio button INPUT element name shipping_option, corresponding to the shipping option identifier.

The checkout_step hidden field should be used in all checkout partials.

See also:

Next: Creating the Payment Method partial
Previous: Creating the Shipping Information partial
Return to AJAX-driven single-page checkout

Comments

No comments posted so far.

Add your comment

Loading form...