You are on page 1of 17

Cherry Picker

Additional features Guide


Thank you very much for choosing Cherry Picker extension.

Important.

In this Guide we will follow the steps and enable additional


features that Cherry Picker supports:

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.


 
CONTENTS

i. Search by Price, 4

ii. Parameter search with Trackbar (1 or 2 sliders), 10

iii. Color filters, 13

iv. Shortened URL format, 14


 
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.

Important. Even though we make it possible to search products by


prices, the search will not include product’s discounts. This is due
to a complicated price structure in Virtuemart. For instance, if you
have a product which has Original price=$500 but the final Discounted
price is $400, and you search From $0 To $450, this product will not
appear in search results.
The solution here is to redo the way Discounts are managed in VM.
But it’s a pretty comprehensive piece of work and if you have
interest—contact at admin@galt.md for more information.


 
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 these lines (~300):

...
// 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:

// search by price functionality


require_once(JPATH_BASE.'/modules/mod_vm_cherry_picker/controller.php');
$chp=new chpController();
$w=$chp->getVMPriceQuery();
//if you're using taxes, specify the tax here, e.g. 1.2 for 20%
//$w=$chp->getVMPriceQuery(1.2);
if($w)$where_clause[]=$w;


 
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;
}
}

// search by price functionality


require_once(JPATH_BASE.'/modules/mod_vm_cherry_picker/controller.php');
$chp=new chpController();
$w=$chp->getVMPriceQuery();
//if you're using taxes, specify the tax here, e.g. 1.2 for 20%
//$w=$chp->getVMPriceQuery(1.2);
if($w)$where_clause[]=$w;

Notice the comment in the code: if you’re using Taxes specify tax
amount here: getVMPriceQuery(1.2);

The price search is working now. You can give a try.


 
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

Find these lines (~200):

...
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);
... 

And paste this code where the red marker shows:

$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;
}


 
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);
... 

Now you can navigate through the search results.


 
Step Three. Final

What if you change the “Order by” when searching by price? Yes, they
(applied filters) will have gone away.

Let’s fix it.

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 ?>" />

<input type="hidden" name="keyword" value="<?php echo $keyword ?>" />


<input type="hidden" name="keyword1" value="<?php echo $keyword1 ?>" />
<input type="hidden" name="keyword2" value="<?php echo $keyword2 ?>" />

<?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.


 
II. Parameter search with Trackbar (1 or 2 sliders)

Since Virtuemart doesn’t support this kind of search, we’d need to


extend it with our code.

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.

You’ll need to do two things:

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

Here’s 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;
}
}

// search by price functionality


require_once(JPATH_BASE.'/modules/mod_vm_cherry_picker/controller.php');
$chp=new chpController();
$w=$chp->getVMPriceQuery();
//if you're using taxes, specify the tax here, e.g. 1.2 for 20%
//$w=$chp->getVMPriceQuery(1.2);
if($w)$where_clause[]=$w;
//new
$g=$chp->getVMFilters();
if($g){
$where_clause[]=$g['where'];
if($g['join']) $join_array[]=$g['join'];
}

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.

That’s it. Trackbars should be fully working now.

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{}

Let’s have an example. For instance I have a Parameter “Color” with


Possible Values: Yellow;Blue;Red

Then I would add these rules to my CSS file:

.col-yellow{background-color:#F9F97F;}
.col-blue{background-color:#9DD5F8;}
.col-red{background-color:#F57272;color:#FFF5F5}

Use lowercase CLASS Names.

You can open ChP’s CSS file and check it as a reference.

13 
 
IV. Shortened URL format

If you think filters are too large in your URLs, this option is for
you.

For example, this is how URL would look like, if we made a


selection for Capacity: 4Gb and 8Gb, and Camera: Yes (total 3
filters selected) by Default:

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

Where "capacity" and "cam" are parameter_names.

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:

- Version_2: Step One updated; new code for price search in


shop_browse_queries.php.

- Version_3 (current): Search by Price updated. Chapters II, III and


IV added.

16 
 
© Copyright, 2011, by Maksym Stefanchuk

www.galt.md

admin@galt.md

The End. 

17 
 

You might also like