LemonStand Documentation

Shop_BundleHelper

The Shop_BundleHelper provides methods which help in developing front-end pages and partials for displaying and managing product bundle items. All methods of this class are static.

Class methods

  • is_item_product_selected($bundle_item, $bundle_item_product) - returns TRUE if a specified bundle item product is selected. Use this method to determine whether a bundle item product drop-down option, a radio button or a checkbox is selected. Pass a bundle item object (Shop_ProductBundleItem) to the first parameter and bundle item product object (Shop_BundleItemProduct) to the second parameter. Example:
    <select ...>
      <? foreach ($item->item_products as $item_product): ?>
        <option 
          ...
          <?= option_state(Shop_BundleHelper::is_item_product_selected($item, $item_product), true) ?>>
            <?= h($item_product->product->name) ?>
        </option>
      <? endforeach ?>
    </select>
  • get_product_quantity($bundle_item, $bundle_item_product = null) - returns Quantity field value for a specified bundle item product. Use this method to output value for the Quantity field "value" attribute. Pass a bundle item object (Shop_ProductBundleItem) to the first parameter and bundle item product object (Shop_BundleItemProduct) to the second parameter. Example:
    <input
      class="text"
      type="text" 
      name="<?= Shop_BundleHelper::get_product_control_name($item, $item_product, 'quantity') ?>" 
      value="<?= Shop_BundleHelper::get_product_quantity($item, $item_product) ?>"/>
  • is_product_option_selected($option, $value, $bundle_item, $bundle_item_product) - returns TRUE if a specified bundle item product option is selected. Use this method in the bundle product options partial to determine whether a specific product option is selected. First two parameters are Shop_CustomAttribute (product option object) and option value you are testing. Last two parameters are - bundle item object (Shop_ProductBundleItem) and bundle item product object (Shop_BundleItemProduct). Example:
    <select ...>
      <?
        $values = $option->list_values();
        foreach ($values as $value):      
          $is_selected = Shop_BundleHelper::is_product_option_selected($option, $value, $item, $item_product);
      ?>
        <option <?= option_state($is_selected, true) ?> value="<?= h($value) ?>"><?= h($value) ?></option>
      <? endforeach ?>
    </select>
  • is_product_extra_option_selected($option, $bundle_item, $bundle_item_product = null) - returns TRUE if a specified bundle item product extra option is selected. Use this method in the bundle product extra options partial to determine whether a specific product extra option is selected. First parameter is Shop_ExtraOption object. Second parameter is the bundle item object (Shop_ProductBundleItem) and third parameter is the bundle item product object (Shop_BundleItemProduct). Example:
    <? foreach ($product->extra_options as $option):
      $is_checked = Shop_BundleHelper::is_product_extra_option_selected($option, $item, $item_product);
    ?>
      <input 
        ...
        <?= checkbox_state(Shop_BundleHelper::is_product_extra_option_selected($option, $item, $item_product)) ?> 
        value="1" 
        type="checkbox"/>
    <? endforeach ?>
  • get_bundle_item_product($bundle_item, $bundle_item_product = null) - returns a bundle item product (Shop_Product) selected by visitor. If the visitor has not selected any product yet, the method can return a default product for this bundle item (if any), or first product in the list for drop-down and radio button type bundle items. Pass a bundle item object (Shop_ProductBundleItem) to the first parameter and bundle item product object (Shop_BundleItemProduct) to the second parameter.
  • get_bundle_item_product_item($bundle_item) - returns a bundle item product object (Shop_BundleItemProduct) corresponding a product selected by visitor. This method is required only for drop-down type bundle items. The parameter value should be a bundle item object (Shop_ProductBundleItem).
  • get_product_selector_name($bundle_item, $bundle_item_product) - returns a name for a bundle item product selector input element (drop-down menu, checkbox or radio button). Input element names are different for different bundle item control types and this method simplifies generating the input element names. Pass a bundle item object (Shop_ProductBundleItem) to the first parameter and bundle item product object (Shop_BundleItemProduct) to the second parameter. Example:
    <? if ($item->control_type == 'dropdown'): ?>
      <select 
        ...
        name="<?= Shop_BundleHelper::get_product_selector_name($item, $selected_item_product) ?>"
      ...
    <? elseif ($item->control_type == 'checkbox'): ?>
      <? foreach ($item->item_products as $item_product): ?>
        <input 
          type="checkbox" 
          name="<?= Shop_BundleHelper::get_product_selector_name($item, $item_product) ?>" 
          value="<?= Shop_BundleHelper::get_product_selector_value($item_product) ?>"
          ...
        />
      ...
    <? else: ?> 
      <? foreach ($item->item_products as $item_product): ?>
        <input 
          type="radio" 
          name="<?= Shop_BundleHelper::get_product_selector_name($item, $selected_product) ?>" 
          value="<?= Shop_BundleHelper::get_product_selector_value($item_product) ?>"
          ...
        />
      ...
    <? endif ?>
  • get_product_selector_value($bundle_item_product) - returns a value for a bundle item product selector input element (drop-down menu option, checkbox or radio button). Pass the bundle item product object (Shop_BundleItemProduct) to the second parameter. See example for checkboxes and radio buttons above. Example for drop-down control type:
    <select ...>
      <? foreach ($item->item_products as $item_product): ?>
        <option 
          value="<?= Shop_BundleHelper::get_product_selector_value($item_product) ?>" 
          ...
        >
          <?= h($item_product->product->name) ?>
        </option>
      <? endforeach ?>
    </select>
  • get_product_control_name($bundle_item, $bundle_item_product, $control_name) - returns a name for bundle item product configuration control (options, extra options or grouped product selector). This is an universal method which can be used for generating names for any supported bundle item product controls. Pass the bundle item product object (Shop_BundleItemProduct) to the second parameter. The third parameter is a string representing the control name. Possible values for this parameter are: 'quantity', 'options', 'extra_options' or 'grouped_product'. Example:
    <input
      class="text"
      type="text" 
      name="<?= Shop_BundleHelper::get_product_control_name($item, $item_product, 'quantity') ?>" 
      value="<?= Shop_BundleHelper::get_product_quantity($item, $item_product) ?>"/>
  • get_item_hidden_fields($bundle_item, $bundle_item_product) - returns a string containing hidden fields declarations for a bundle item. Hidden fields are required only for drop-down type bundle items. Pass the bundle item product object (Shop_BundleItemProduct) to the second parameter. Example: 
    <?= Shop_BundleHelper::get_item_hidden_fields($item, $selected_item_product) ?>

Next: Shop_Cart
Previous: Shop_BundleItemProduct
Return to Reference