
App::ZofCMS::Plugin::SplitPriceSelect - plugin for generating a <select> for "price range" out of arbitrary range of prices.

In your Main Config File or ZofCMS Template:
plugins => [ qw/SplitPriceSelect/ ],
plug_split_price_select => {
prices => [ 200, 300, 1000, 4000, 5000 ],
},
In your HTML::Template file:
<form...
<label for="plug_split_price_select">Price range: </label>
<tmpl_var name='plug_split_price_select'>
.../form>

The module is a plugin for App::ZofCMS that allows you to give several prices and plugin will create a <select> HTML element with its <option>s containing ranges of prices. The idea is that you'd specify how many options you would want to have and plugin will figure out how to split the prices to generate that many ranges.
This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template

pluginsplugins => [ qw/SplitPriceSelect/ ],
You need to add the plugin in the list of plugins to execute.
plug_split_price_select plug_split_price_select => {
prices => [ qw/foo bar baz/ ],
t_name => 'plug_split_price_select',
options => 3,
name => 'plug_split_price_select',
id => 'plug_split_price_select',
dollar_sign => 1,
}
The plug_split_price_select first-level key takes a hashref as a value. If a certain key in that hashref is specified in both, Main Config File and ZofCMS Template, then the value given in ZofCMS Template will take precedence. Plugin will not run if plug_split_price_select is not specified (or if prices key's arrayref is empty). Possible keys/value of plug_split_price_select hashref are as follows:
pricesprices => [ qw/foo bar baz/ ],
Mandatory. Takes an arrayref as a value, plugin will not run if prices arrayref is empty or prices is set to undef. The arrayref's elements represent the prices for which you wish to generate ranges. All elements must be numeric.
optionsoptions => 3,
Optional. Takes a positive integer as a value. Specifies how many price ranges (i.e. <option>s) you want to have. Note: if there are not enough prices in the prices argument, expect to have ranges with the same price on both sides; with evel smaller dataset, expect to have less than options <option>s generated. Defaults to: 3
t_namet_name => 'plug_split_price_select',
Optional. Plugin will put generated <select> into {t} ZofCMS Template special key, the t_name parameter specifies the name of that key. Defaults to: plug_split_price_select
namename => 'plug_split_price_select',
Optional. Specifies the value of the name="" attribute on the generated <select> element. Defaults to: plug_split_price_select
idid => 'plug_split_price_select',
Optional. Specifies the value of the id="" attribute on the generated <select> element. Defaults to: plug_split_price_select
dollar_signdollar_sign => 1,
Optional. Takes either true or false values. When set to a true value, the <option>s will contain a dollar sign in front of prices when displayed in the browser (the value=""s will still not contain the dollar sign, see PARSING QUERY section below). Defaults to: 1

plug_split_price_select=500-14000
Now, the price ranges are generated and you completed your gorgeous form... how to parse those ranges is the question. The value="" attribute of each of generated <option> element will contain the starting price in the range followed by a - (dash, rather minus sign) followed by the ending price in the range. Note: the price on each end of the range may be the same if there are not enough prices available. Thus you can do something along the lines of:
my ( $start_price, $end_price ) = split /-/, $query->{plug_split_price_select};
my @products_in_which_the_user_is_interested = grep {
$_->{price} >= $start_price and $_->{price} <= $end_price
} @all_of_the_products;

This is what the HTML code generated by the plugin looks like (providing all the optional arguments are left at their default values):
<select id="plug_split_price_select" name="plug_split_price_select">
<option value="200-1000">$200 - $1000</option>
<option value="4000-6000">$4000 - $6000</option>
<option value="7000-7000">$7000 - $7000</option>
</select>

'Zoffix, <'zoffix at cpan.org'> (http://zoffix.com/, http://haslayout.net/, http://zofdesign.com/)

Please report any bugs or feature requests to bug-app-zofcms-plugin-splitpriceselect at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-ZofCMS-Plugin-SplitPriceSelect. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

You can find documentation for this module with the perldoc command.
perldoc App::ZofCMS::Plugin::SplitPriceSelect
You can also look for information at:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-ZofCMS-Plugin-SplitPriceSelect
http://cpanratings.perl.org/d/App-ZofCMS-Plugin-SplitPriceSelect
http://search.cpan.org/dist/App-ZofCMS-Plugin-SplitPriceSelect

Copyright 2008 'Zoffix, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.