Professional Documents
Culture Documents
Important.
o Search by Price
o Parameter search with Trackbar (1 or 2 sliders)
o Color filters
o Short URL support
You do not need to apply this code right away! If you just
bought ChP and you’re not sure whether you will be using these,
then close this Guide. ChP will be fully working without these
steps. The setup of ChP is really simple in fact, you only need
to: 1) install it; 2) publish it. That’s right, leave the config
by default. Then go to Virtuemart and create filters. You can
use this or this guide on how to create Product Types.
2
CONTENTS
i. Search by Price, 4
3
I. Search by Price
Below are a few steps that will help you add a Search by Price
functionality to your store.
If you just installed ChP you might notice a Price Search Form there,
though it’s quite dead right now. If you are not going to use a
Search by Price form—you may disable it by choosing No in the back-
end, and skip this Chapter.
The reason this guide exists is because Virtuemart does not have
ability to search by prices in ranges (From ___ To ___). So our goal
is to add this functionality ourselves—to teach Virtuemart.
4
Files to be edited:
1. administrator\components\com_virtuemart\html\shop_browse_queries.php
2. administrator\components\com_virtuemart\html\shop.browse.php
3. components\com_virtuemart\themes\default\templates\browse\includes\
browse_orderbyform.tpl.php
Step One.
Before we’ve done anything, you already might have entered prices
into fields but the only changes you could see were in ChP itself. So
now we will give the “knowledge” to VM, so it can take part in the
process as well.
1. administrator\components\com_virtuemart\html\shop_browse_queries.php
...
// find default Shopper Groups
$q2 = "SELECT `shopper_group_id` FROM `#__{vm}_shopper_group` WHERE `default` = 1";
$db_browse->query($q2);
while ($db_browse->next_record()) {
$sgq .= $comma.$db_browse->f("shopper_group_id");
$comma=",";
}
$sgq .= "\n )) ";
$where_clause[] = $sgq;
}
}
And paste this tiny bit of code right after the last brace:
5
The final look:
...
// find default Shopper Groups
$q2 = "SELECT `shopper_group_id` FROM `#__{vm}_shopper_group` WHERE `default` =
1";
$db_browse->query($q2);
while ($db_browse->next_record()) {
$sgq .= $comma.$db_browse->f("shopper_group_id");
$comma=",";
}
$sgq .= "\n )) ";
$where_clause[] = $sgq;
}
}
Notice the comment in the code: if you’re using Taxes specify tax
amount here: getVMPriceQuery(1.2);
6
Step Two.
On this step we will make sure that when you go to another page the
prices remain in the link.
2. administrator\components\com_virtuemart\html\shop.browse.php
...
if (!empty($product_type_id)){
foreach($_REQUEST as $key => $value){
if (substr($key, 0,13) == "product_type_"){
$val = vmGet($_REQUEST, $key );
if( is_array( $val )) {
foreach( $val as $var ) {
$search_string .="&".$key."[]=".urlencode($var)
;
}
} else {
$search_string .="&".$key."=".urlencode($val);
}
}
}
}
<- Paste here
}
$tpl->set( 'VM_BROWSE_ORDERBY_FIELDS', $VM_BROWSE_ORDERBY_FIELDS);
...
$low_price=JRequest::getVar("low-price", null);
$high_price=JRequest::getVar("high-price", null);
if($low_price || $high_price){
$search_string.="&low-price=".$low_price."&high-price=".$high_price;
}
7
Final look:
...
if (!empty($product_type_id)){
foreach($_REQUEST as $key => $value){
if (substr($key, 0,13) == "product_type_"){
$val = vmGet($_REQUEST, $key );
if( is_array( $val )) {
foreach( $val as $var ) {
$search_string .="&".$key."[]=".urlencode($var)
;
}
} else {
$search_string .="&".$key."=".urlencode($val);
}
}
}
}
$low_price=JRequest::getVar("low-price", null);
$high_price=JRequest::getVar("high-price", null);
if($low_price || $high_price){
$search_string.="&low-price=".$low_price."&high-price=".$high_price;
}
}
$tpl->set( 'VM_BROWSE_ORDERBY_FIELDS', $VM_BROWSE_ORDERBY_FIELDS);
...
8
Step Three. Final
What if you change the “Order by” when searching by price? Yes, they
(applied filters) will have gone away.
3.components\com_virtuemart\themes\default\templates\
\browse\includes\browse_orderbyform.tpl.php
Here is the final look. Compare your file to how it should be:
...
<input type="hidden" name="Itemid" value="<?php echo $Itemid ?>" />
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="page" value="shop.browse" />
<input type="hidden" name="category_id" value="<?php echo $category_id ?>" />
<?php
// you may have these lines. Let’s comment them, and use our, a bit advanced, code
//if( !empty( $product_type_id )) {
//echo '<input type="hidden" name="product_type_id" value="'.$product_type_id.'" />';
//echo $ps_product_type->get_parameter_form($product_type_id);
//}
// new code
include_once(JPATH_BASE.DS.'modules/mod_vm_cherry_picker/controller.php');
$chp=new chpController();
$chp->getVMOrderByForm();
?>
</form>
Now you should have a full support of Search by Price on your site.
9
II. Parameter search with Trackbar (1 or 2 sliders)
To VM back-end we will add new field Parameter Mode. As you can see
from the image below, it will tell ChP whether this Parameter a
Trackbar (1 or 2 sliders), a Color or default one.
1. Run SQL query, that will add a column to store your selections;
2. Overwrite two files.
So, unzip mod.zip file. Run sql file. Overwrite two files (copy whole
folders, as they are already structured in the right way).
10
The back-end is fully working. Now let’s handle the front-end.
We will edit old files one more time. This is the first one:
1. administrator\components\com_virtuemart\html\shop_browse_queries.php
...
// find default Shopper Groups
$q2 = "SELECT `shopper_group_id` FROM `#__{vm}_shopper_group` WHERE `default` =
1";
$db_browse->query($q2);
while ($db_browse->next_record()) {
$sgq .= $comma.$db_browse->f("shopper_group_id");
$comma=",";
}
$sgq .= "\n )) ";
$where_clause[] = $sgq;
}
}
11
And this:
2. administrator\components\com_virtuemart\html\shop.browse.php
Final look:
...
if (!empty($product_type_id)){
foreach($_REQUEST as $key => $value){
if (substr($key, 0,13) == "product_type_"){
$val = vmGet($_REQUEST, $key );
if( is_array( $val )) {
foreach( $val as $var ) {
$search_string .="&".$key."[]=".urlencode($var)
;
}
} else {
$search_string .="&".$key."=".urlencode($val);
}
}
}
}
$low_price=JRequest::getVar("low-price", null);
$high_price=JRequest::getVar("high-price", null);
if($low_price || $high_price){
$search_string.="&low-price=".$low_price."&high-price=".$high_price;
}
// new
if($g) $search_string.=$g['url'];
}
$tpl->set( 'VM_BROWSE_ORDERBY_FIELDS', $VM_BROWSE_ORDERBY_FIELDS);
...
Please note that you can’t use Trackbar with 2 sliders and Parameter
Type: Multiple Values at the same time.
12
III. Color filters
In the above Chapter we added a new field Parameter Mode where you
can choose Parameter to be a Color type. ChP will create white boxes,
but you’ll need to color them yourself. And here’s how to do that.
You’ll need to add CSS class rules to any CSS file you wish in your
site (you can use ChP’s CSS file). The CLASS_NAME consists of:
.col-FILTER_NAME{}
.col-yellow{background-color:#F9F97F;}
.col-blue{background-color:#9DD5F8;}
.col-red{background-color:#F57272;color:#FFF5F5}
13
IV. Shortened URL format
If you think filters are too large in your URLs, this option is for
you.
http://www.yoursite.com/index.php?option=com_virtuemart&page=shop.browse&I
temid=1&category_id=26&limitstart=0&product_type_id=6&product_type_6_capac
ity_comp=in&product_type_6_capacity[]=4&product_type_6_capacity[]=8&produc
t_type_6_cam_comp=in&product_type_6_cam[]=Yes
And this is how it will look with option enabled for the same
filter selection:
http://www.yoursite.com/index.php?option=com_virtuemart&page=shop.browse&I
temid=1&category_id=26&limitstart=0&capacity=4|8&cam=Yes
Important I
Name your parameters wisely--make sure parameter_names are
unique and do not match any other URL parameters (they appear
in browser address bar) that may be in use by other components
or modules you have installed on the site. For example: option,
section, id, view, layout, Itemid, limitstart, limit, page,
product_id and so on--are to be avoided.
Important II
Some SEF components do not tolerate parameters they don't know
about, and strip them off the URL. For example you may
experience problems with JoomSEF. So you'll have either to
configure your component not to do that, or to use default
links.
14
This option can be enabled in Advanced tab of ChP config:
And if you haven’t already, you’d need to apply two edits to these
two files from Chapter II:
1. administrator\components\com_virtuemart\html\shop_browse_queries.php
2. administrator\components\com_virtuemart\html\shop.browse.php
15
Changes made to this file since the version_1:
16
© Copyright, 2011, by Maksym Stefanchuk
www.galt.md
admin@galt.md
The End.
17