This is the API docs for LemonStand V1, which has been discontinued. LemonStand is now a cloud based platform, available at lemonstand.com.

LemonStand API

Shop_BundleHelper class

Defined in /modules/shop/helpers/shop_bundlehelper.php, lines 13-587
Author LemonStand eCommerce Inc.
Provides methods which help in developing front-end pages and partials for displaying and managing product bundle items.

Public methods

Method Description Defined By
get_bundle_item_product() returns a bundle item product selected by visitor. Shop_BundleHelper
get_bundle_item_product_item() returns a bundle item product object corresponding a product selected by visitor. Shop_BundleHelper
get_item_hidden_fields() returns a string containing hidden field declarations for a bundle item. Shop_BundleHelper
get_product_control_name() returns a name for bundle item product configuration control (options, extra options or grouped product selector). Shop_BundleHelper
get_product_quantity() returns Quantity field value for a specified bundle item product. Shop_BundleHelper
get_product_selector_name() returns a name for a bundle item product selector input element (drop-down menu, checkbox or radio button). Shop_BundleHelper
get_product_selector_value() returns a value for a bundle item product selector input element (drop-down menu option, checkbox or radio button). Shop_BundleHelper
get_selected_options() returns an array of selected bundle item product options. Shop_BundleHelper
is_item_product_selected() returns TRUE if a specified bundle item product is selected. Shop_BundleHelper
is_product_extra_option_selected() returns TRUE if a specified bundle item product extra option is selected. Shop_BundleHelper
is_product_option_selected() returns TRUE if a specified bundle item product option is selected. Shop_BundleHelper

Method details

get_bundle_item_product() method

public static Shop_Product get_bundle_item_product(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_product=NULL)
$bundle_item Shop_ProductBundleItem specifies the bundle item object.
$bundle_item_product Shop_BundleItemProduct specifies the bundle item product object, optional.
{return} Shop_Product returns the selected product object.
Returns a bundle item product selected by visitor. If the visitor has not selected any product yet, the method would return a default product for this bundle item (if any), or a first product in the list for drop-down and radio button type bundle items.

get_bundle_item_product_item() method

public static Shop_BundleItemProduct get_bundle_item_product_item(Shop_ProductBundleItem $bundle_item)
$bundle_item Shop_ProductBundleItem specifies the bundle item object.
{return} Shop_BundleItemProduct returns the bundle item product object or NULL.
Returns a bundle item product object corresponding a product selected by visitor. This method is required only for drop-down type bundle items.

get_item_hidden_fields() method

public static string get_item_hidden_fields(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_product)
$bundle_item Shop_ProductBundleItem specifies the bundle item object.
$bundle_item_product Shop_BundleItemProduct specifies the bundle item product object.
{return} string returns HTML string containing the hidden field declarations.
Returns a string containing hidden field declarations for a bundle item. Hidden fields are required only for drop-down type bundle items.
<?= Shop_BundleHelper::get_item_hidden_fields($item, $selected_item_product) ?>

get_product_control_name() method

public static string get_product_control_name(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_product, string $control_name)
$bundle_item Shop_ProductBundleItem specifies the bundle item object.
$bundle_item_product Shop_BundleItemProduct specifies the bundle item product object.
$control_name string specifies the control name
{return} string returns the the product configuration 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. The $control_name 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_product_quantity() method

public static integer get_product_quantity(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_product=NULL, integer $product_id=NULL)
$bundle_item Shop_ProductBundleItem specifies the bundle item object.
$bundle_item_product Shop_BundleItemProduct specifies the bundle item product object, optional.
$product_id integer specifies Product identifier, optional.
{return} integer returns Quantity field value.
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 to the first parameter and bundle item product object 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) ?>"/>

get_product_selector_name() method

public static string get_product_selector_name(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_product)
$bundle_item Shop_ProductBundleItem specifies the bundle item object.
$bundle_item_product Shop_BundleItemProduct specifies the bundle item product object, optional.
{return} string returns the input element name.
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 element names.
<? 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() method

public static string get_product_selector_value(Shop_BundleItemProduct $bundle_item_product)
$bundle_item_product Shop_BundleItemProduct specifies the bundle item product object.
{return} string returns the input element value.
Returns a value for a bundle item product selector input element (drop-down menu option, checkbox or radio button).
<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_selected_options() method

public static array get_selected_options(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_product)
$bundle_item Shop_ProductBundleItem specifies the bundle item object.
$bundle_item_product Shop_BundleItemProduct specifies the bundle item product object, optional.
{return} array returns a list of selected options in the following format: [option_key=>option value].
Returns an array of selected bundle item product options. The method result is suitable for passing to the Shop_Product::om() and Shop_BundleItemProduct::get_price() methods.
// Load bundle item product images
$selected_options = Shop_BundleHelper::get_selected_options($item, $item_product);
$images = $product->om('images', $selected_options);

// Load bundle item product price
$selected_options = Shop_BundleHelper::get_selected_options($item, $item_product);
Price: <?= format_currency($item_product->get_price($product, $selected_options)) ?>

is_item_product_selected() method

public static boolean is_item_product_selected(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_product)
$bundle_item Shop_ProductBundleItem specifies the bundle item object.
$bundle_item_product Shop_BundleItemProduct specifies the bundle item product object.
{return} boolean returns TRUE if a specified bundle item product is selected. Returns FALSE otherwise.
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 to the first parameter and bundle item product object 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>

is_product_extra_option_selected() method

public static boolean is_product_extra_option_selected(Shop_ExtraOption $option, Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_product=NULL)
$option Shop_ExtraOption specifies the exrta option object being checked.
$bundle_item Shop_ProductBundleItem specifies the bundle item object.
$bundle_item_product Shop_BundleItemProduct specifies the bundle item product object, optional.
{return} boolean returns TRUE if a specified bundle item product extra option is selected. Returns FALSE otherwise.
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. 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 ?>

is_product_option_selected() method

public static boolean is_product_option_selected(Shop_CustomAttribute $option, string $value, Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_pr
$option Shop_CustomAttribute specifies the option object being checked.
$value string specifies the option value to check.
$bundle_item Shop_ProductBundleItem specifies the bundle item object.
$bundle_item_product Shop_BundleItemProduct specifies the bundle item product object, optional.
{return} boolean returns TRUE if a specified bundle item product option is selected. Returns FALSE otherwise.
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. 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>