|
Shop_BundleHelper class
Provides methods which help in developing front-end pages and partials for displaying and managing product bundle items.
See AlsoPublic methods
Method details¶ get_bundle_item_product() methodpublic static Shop_Product get_bundle_item_product(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_product=NULL)
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() methodpublic static Shop_BundleItemProduct get_bundle_item_product_item(Shop_ProductBundleItem $bundle_item)
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() methodpublic static string get_item_hidden_fields(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_product)
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() methodpublic static string get_product_control_name(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_product, string $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() methodpublic static integer get_product_quantity(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_product=NULL, integer $product_id=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
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() methodpublic static string get_product_selector_name(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $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 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() methodpublic static string get_product_selector_value(Shop_BundleItemProduct $bundle_item_product)
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() methodpublic static array get_selected_options(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_product)
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() methodpublic static boolean is_item_product_selected(Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $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 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() methodpublic static boolean is_product_extra_option_selected(Shop_ExtraOption $option, Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $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.
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() methodpublic static boolean is_product_option_selected(Shop_CustomAttribute $option, string $value, Shop_ProductBundleItem $bundle_item, Shop_BundleItemProduct $bundle_item_pr
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> |