Author Topic: Filter product category by manufacturer ( checkbox )  (Read 6824 times)

Linelab

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 452
    • Live Joomla! Template Builder
Filter product category by manufacturer ( checkbox )
« on: July 20, 2011, 14:21:21 pm »
Go to: administrator\com_virtuemart\html\shop.browse.php
Find line 125
Code: [Select]
$tpl->set( 'category_name', $category_name );
Add after

      
Code: [Select]
$query  = "SELECT DISTINCT m.manufacturer_id, m.mf_name
FROM #__{vm}_manufacturer m
LEFT JOIN #__{vm}_product_mf_xref mx ON mx.manufacturer_id = m.manufacturer_id
LEFT JOIN #__{vm}_product p ON p.product_id = mx.product_id
LEFT JOIN #__{vm}_product_category_xref cx ON cx.product_id = p.product_id
WHERE cx.category_id =".(int)$category_id. " AND p.product_publish='Y'";
$query .= " ORDER BY m.mf_name ASC";
$db->query( $query );

$manufacturers_filtering = $vm_mainframe->getUserState( 'manufacturers_filtering_'.$category_id, false );
if ($manufacturers_filtering) {
$manufacturers_checked = $vm_mainframe->getUserState( 'manufacturers_'.$category_id );
}

if ($manufacturers_filtering) {
$checked='';
} else {
$checked='checked="checked"';
}
$manufacturers = array();

while ($db->next_record()) {
if (is_array($manufacturers_checked)) {
if (in_array($db->f("manufacturer_id"), $manufacturers_checked)) {
$checked='checked="checked"';
} else {
$checked='';
}
} else {
$checked='';
}
$manufacturers[]='<input type="checkbox" value="'.$db->f("manufacturer_id").'" name="manufacturers_ids[]" onClick="this.form.manufacturers_all.checked=false;this.form.submit();" '.$checked.' />'.$db->f("mf_name").'&nbsp;&nbsp;';
}
if (count($manufacturers)) {
array_unshift($manufacturers, '<input type="checkbox" value="1" name="manufacturers_all" onClick="this.form.submit();" '.$checked.' />All&nbsp;&nbsp;');
}
$tpl->set( 'manufacturers', $manufacturers );
Go to:
\components\com_virtuemart\...\templates\browse\includes\browse_header_category.tpl.php
Add to end of file

Code: [Select]
<?php
 if (
$manufacturers) :
  if (is_array($manufacturers)) :
?>

<form action="<?php echo JURI::root();?>index.php" method="get" name="manufacturer">
<?php
foreach ($manufacturers as $m) {
echo $m;
}
?>


    <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="manufacturers_filtering" value="1" />
</form>
<?php
endif;
endif;
?>

Go to:
\administrator\com_virtuemart\html\shop_browse_queries.php
Find line 30

Code: [Select]
// These are the names of all fields we fetch data from
Add after:
Code: [Select]
$manufacturers_filtering = intval( vmGet( $_REQUEST, 'manufacturers_filtering', 0 ) );
if ($manufacturers_filtering) {
$manufacturers_checked = vmGet( $_REQUEST, 'manufacturers_ids', array() );
$manufacturers_all = vmGet( $_REQUEST, 'manufacturers_all', 0 );
if ($manufacturers_all) {
$vm_mainframe->setUserState( 'manufacturers_filtering_'.$category_id, false );
$manufacturers_filtering = false;
$manufacturers_checked = null;
$vm_mainframe->setUserState( 'manufacturers_'.$category_id, $manufacturers_checked );
} else {
if (count($manufacturers_checked)) {
$vm_mainframe->setUserState( 'manufacturers_'.$category_id, $manufacturers_checked );
$vm_mainframe->setUserState( 'manufacturers_filtering_'.$category_id, true );
$manufacturers_filtering = true;
} else {
$vm_mainframe->setUserState( 'manufacturers_filtering_'.$category_id, false );
$manufacturers_filtering = false;
$manufacturers_checked = null;
$vm_mainframe->setUserState( 'manufacturers_'.$category_id, $manufacturers_checked );
}
}
} else {
$manufacturers_filtering = $vm_mainframe->getUserState( 'manufacturers_filtering_'.$category_id, false );
if ($manufacturers_filtering) {
$manufacturers_checked = $vm_mainframe->getUserState( 'manufacturers_'.$category_id );
}
}

Find Line 208

Code: [Select]
$where_clause[] = $sgq;
}

}

Add after:

Code: [Select]
if (!empty($manufacturers_filtering)) {
$table_names .= ',`#__{vm}_product_mf_xref`';
$where_clause[]  = "manufacturer_id IN (".join(',',$manufacturers_checked).")";
$where_clause[] = "`#__{vm}_product`.`product_id`=`#__{vm}_product_mf_xref`.`product_id` ";

}

Tested VirtueMart 1.1.9 and Joomla 1.5.23

VirtueMart Extensions: www.linelab.org


[attachment cleanup by admin]

gazustoy

  • Beginner
  • *
  • Posts: 5
Re: Filter product category by manufacturer ( checkbox )
« Reply #1 on: December 26, 2011, 23:42:37 pm »
excellent job I congratulate you, now I will put images to manufacturers.

regards ;D

obyybo

  • Beginner
  • *
  • Posts: 2
Re: Filter product category by manufacturer ( checkbox )
« Reply #2 on: December 28, 2011, 15:00:29 pm »
You did a great job ! Congrats ! I have a question though..  what do you do if you have 150 manufacturers ? :) can you configure a hide menu, something like: "show more" ?

ruslan

  • Beginner
  • *
  • Posts: 1
Re: Filter product category by manufacturer ( checkbox )
« Reply #3 on: December 28, 2011, 19:48:10 pm »
Excellent ! Great job! Thanks

joss_54

  • Beginner
  • *
  • Posts: 7
    • Mundo Innovation Systems
Re: Filter product category by manufacturer ( checkbox )
« Reply #4 on: January 25, 2012, 16:06:50 pm »
Super super job! Thanks!

miniol

  • Beginner
  • *
  • Posts: 1
Re: Filter product category by manufacturer ( checkbox )
« Reply #5 on: July 20, 2012, 14:20:55 pm »
How add this filter to search results?

vladast

  • Beginner
  • *
  • Posts: 41
Re: Filter product category by manufacturer ( checkbox )
« Reply #6 on: May 19, 2013, 19:04:59 pm »
Hm... I know that there is new versions of VM.
I still use VM 1.1.9 on one website, and I need this patch.

Everything working, except that when I select latest manufacturer in row.
Page reload itself, but selected are latest manufacuterer, and ALL option.

If I check first, or second manufacturer (I have them three) everything is ok. Then I can select other manufacuterer, or ALL option.

But if I select latest shown manufacturer, it is selected after reload, but also option ALL is selected...

How can I fix this.

Thanks.