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

Pisu

  • Contributing Developer
  • Jr. Member
  • *
  • Posts: 451
  • ..still looking for..
    • Blog di Stefano Bagnatica
Filter product category by manufacturer
« on: December 22, 2006, 11:10:06 am »
I noticed that in shop browsing, you can browse by category OR by manufacturer (with appropriate module), but not each together. An example: I have a category "Notebook" with various manufacturer (Asus, Toshiba, ...), when I go to Notebook category, I can't filter for view only notebooks of Asus. This was a really need for me, so I made an hack for this.

I'm attaching the pages I hacked: shop.browse.php and shop_browse_queries.php.

I'll try to explain what I made.

1- added SELECT box with list of manuf for that category, in top of the shop browse page; code added just after the sort objects, before hidden fields (line 217 in original shop.browse.php file) (tnx to manufacturer list module):
Code: [Select]
$query  = "SELECT distinct a.manufacturer_id,a.mf_name FROM #__{vm}_manufacturer AS a ";
if (!empty( $category_id ) ) {
    $query .= ", #__{vm}_product_category_xref AS d, "
    . " #__{vm}_product AS b, "
    . " #__{vm}_product_mf_xref AS c "
    . " WHERE d.category_id='$category_id'"
    . " AND d.product_id = b.product_id "
    . " AND b.product_id = c.product_id AND c.manufacturer_id = a.manufacturer_id ";
}
$query .= "ORDER BY mf_name ASC";
$db = new ps_DB;
$db->query( $query );

$res = $db->record;

?>
        <select class="inputbox" name="manufacturer_id" onchange="order.submit()">
            <option value=""><?php echo _CMN_SELECT ?></option>
        <?php  
foreach ($res as $manufacturer) { 
$selected '';
if( @$_REQUEST['manufacturer_id'] == $manufacturer->manufacturer_id ) {
$selected 'selected="selected"';      
}
echo "<option value=\"".$manufacturer->manufacturer_id ."\" $selected>"$manufacturer->mf_name ."</option>\n";


        
?>

        </select>

2- commented "manufacturer_id" hidden field (ok you can delete it):
Code: [Select]
<!--<input type="hidden" name="manufacturer_id" value="<?php echo $manufacturer_id ?>" />-->
3- changed $url building, to not add duplicated manufacturer_id variabile (around line 330):
Code: [Select]
        $url = $sess->url( $mm_action_url."index.php?page=shop.product_details&flypage=$flypage&product_id=" . $db_browse->f("product_id") . "&category_id=" . $db_browse->f("category_id"));
if (!empty($manufacturer_id) && $manufacturer_id<>0) {
$url .= "&manufacturer_id=" . $manufacturer_id;
}

4- now let's open shop_browse_queries.php; first problem was that if manufacturer_id was passed, category filter is ignored; so I changed IF condition in line 181:
Code: [Select]
elseif (empty($manufacturer_id) || !empty($category_id)) {
5- in following lines, made a condition, if manufacturer_id is passed, you have to load also vm_product_mf_xref table in FROM of the queries (I decided to not load it always to improve general performances):
Code: [Select]
/*** GET ALL PUBLISHED PRODUCTS ***/
$list  = "SELECT DISTINCT $fieldnames FROM (`#__{vm}_product`, `#__{vm}_category`, `#__{vm}_product_category_xref`,`#__{vm}_shopper_group`) ";
$count  = "SELECT $count_name FROM (`#__{vm}_product`, `#__{vm}_category`, `#__{vm}_product_category_xref`,`#__{vm}_shopper_group`) ";
if ($manufacturer_id) {
$list  = "SELECT DISTINCT $fieldnames FROM (`#__{vm}_product`, `#__{vm}_category`, `#__{vm}_product_category_xref`,`#__{vm}_shopper_group`,`#__{vm}_product_mf_xref`) ";
$count  = "SELECT $count_name FROM (`#__{vm}_product`, `#__{vm}_category`, `#__{vm}_product_category_xref`,`#__{vm}_shopper_group`,`#__{vm}_product_mf_xref`) ";
}

6- around line 208, I added the effective WHERE condition for manufacturer:
Code: [Select]
if ($manufacturer_id) {
$q  .= "\n AND `#__{vm}_product_mf_xref`.manufacturer_id='".$manufacturer_id."' AND #__{vm}_product_mf_xref.product_id=#__{vm}_product.product_id ";
}

Hope this help... for me is very useful!!!!! Comments are appreciated!

Update 11/09/2007: files updated to VirtueMart 1.0.12

[attachment cleanup by admin]
Pisu - Team VMItalia (Supporto Italiano VirtueMart)
www.stefanobagnatica.it | www.vmitalia.net

nhcompi

  • Beginner
  • *
  • Posts: 3
Re: Filter product category by manufacturer
« Reply #1 on: December 22, 2006, 22:37:46 pm »
Hi Pisu!

That's great! I have search for this a long time!

Many Thanks!

Pisu

  • Contributing Developer
  • Jr. Member
  • *
  • Posts: 451
  • ..still looking for..
    • Blog di Stefano Bagnatica
Re: Filter product category by manufacturer
« Reply #2 on: January 02, 2007, 10:07:04 am »
With the release of VirtueMart 1.0.8, I'm attaching the updated pages shop.browse.php and shop_browse_queries.php (put in administrator\components\com_virtuemart\html).

Note that here there are also applied other hacks:

[attachment cleanup by admin]
Pisu - Team VMItalia (Supporto Italiano VirtueMart)
www.stefanobagnatica.it | www.vmitalia.net

addison

  • Jr. Member
  • **
  • Posts: 61
Re: Filter product category by manufacturer
« Reply #3 on: January 02, 2007, 10:15:38 am »
Really nice!

Can you change in Admin section and insert a check box for using this hack?

In Admin -> Configuration -> Site -> Available "Sort-by" fields I would like to add also Manufacturer/Brand

Thanks

Pisu

  • Contributing Developer
  • Jr. Member
  • *
  • Posts: 451
  • ..still looking for..
    • Blog di Stefano Bagnatica
Re: Filter product category by manufacturer
« Reply #4 on: January 02, 2007, 11:30:24 am »
I think this change is to be made in official release.. if developers wish. I already posted feature request in bugtracker: http://virtuemart.net/index.php?option=com_flyspray&Itemid=91&do=details&task_id=1070&option=com_flyspray&Itemid=91
Pisu - Team VMItalia (Supporto Italiano VirtueMart)
www.stefanobagnatica.it | www.vmitalia.net

zbir

  • Beginner
  • *
  • Posts: 3
Re: Filter product category by manufacturer
« Reply #5 on: January 16, 2007, 23:32:24 pm »
Great job, very usefull modification:)

Do you know if there is a similar tool to filter manufacturers by category? The standard function in "mod_virtuemart_manufacturers" (Automatically select Manufacturers) doesn't seem to work - once I select a category it always says that "No manufacturers defined!"...

thanks

Pisu

  • Contributing Developer
  • Jr. Member
  • *
  • Posts: 451
  • ..still looking for..
    • Blog di Stefano Bagnatica
Re: Filter product category by manufacturer
« Reply #6 on: January 17, 2007, 10:41:42 am »
Do you know if there is a similar tool to filter manufacturers by category?

Do you mean categories of products, or categories of manufacturers?
My hack already filter manufacturer list if product category selected. If you mean category of manufacturers, I don't know, I never used that.
Pisu - Team VMItalia (Supporto Italiano VirtueMart)
www.stefanobagnatica.it | www.vmitalia.net

zbir

  • Beginner
  • *
  • Posts: 3
Re: Filter product category by manufacturer
« Reply #7 on: January 17, 2007, 16:15:12 pm »
I ment "filter manufacturers by categories of products", so when client browses a cartain manufacturer he should be able to filter by selected category of products.

'mod_virtuemart_manufacturers' was a bad example, sorry, my mistake, forget about it.

Regards

Tom



Bill Smith

  • Beginner
  • *
  • Posts: 25
Re: Filter product category by manufacturer
« Reply #8 on: January 26, 2007, 12:13:42 pm »
Remove these lines from shop.brose.php as it'll screw up your sef's

if (!empty($manufacturer_id) && $manufacturer_id<>0) {
         $url .= "&manufacturer_id=" . $manufacturer_id;
      }

Removing this block got it back working again.

Kay

  • Beginner
  • *
  • Posts: 26
  • microdesign.nl
    • Webdesign
Re: Filter product category by manufacturer
« Reply #9 on: February 02, 2007, 19:22:13 pm »
Hi there..

Great mod thanks man!!
but for some reason when i changed it he automaticly posts it in my cart?
how is this possible could u guys please help

when i delete my add-to-cart template in browse_5.php

Pisu

  • Contributing Developer
  • Jr. Member
  • *
  • Posts: 451
  • ..still looking for..
    • Blog di Stefano Bagnatica
Re: Filter product category by manufacturer
« Reply #10 on: February 03, 2007, 23:00:25 pm »
Kay, I don't understand what you're meaning.. can I see your site?
Pisu - Team VMItalia (Supporto Italiano VirtueMart)
www.stefanobagnatica.it | www.vmitalia.net

Bill Smith

  • Beginner
  • *
  • Posts: 25
Re: Filter product category by manufacturer
« Reply #11 on: March 01, 2007, 07:44:33 am »
This post is about as close as I can locate for what I need to achieve.

Instead of filtering manufacturers, I have products which can be New or Used.

I'd like a dropdown same as this which will state New, Used or Both.

I've spent 5 hours trying to come up with something however no luck at all. Any assistance?

WoSko

  • Beginner
  • *
  • Posts: 6
Re: Filter product category by manufacturer
« Reply #12 on: March 05, 2007, 17:29:09 pm »
Hi Pisu!
That's great work! I have only one question. On the first place I have "Ustaw", where I need change this. I would like have "Producent".
Enywhere this is this what I looked for.
Many Thanks!
Kindest regards,
Wojtek
www.fulltech.pl

WoSko

  • Beginner
  • *
  • Posts: 6
Re: Filter product category by manufacturer
« Reply #13 on: March 06, 2007, 08:47:57 am »
Hi Pisu.
I found it. And I changed this one as below:
added one line in vm lang, in my situation this was administrator/components/com_virtuemart/language/polish.php:
Code: [Select]
var $_PHPSHOP_MANUFACTURE = 'Producent';and I change in shop.browse.php this:
Code: [Select]
<option value=""><?php echo _CMN_SELECT ?></option>looks this now:
Code: [Select]
<option value=""><?php echo $VM_LANG->_PHPSHOP_MANUFACTURE ?></option>Thank a lot of again.
Kindest regards,
Wojtek
www.fulltech.pl

martin

  • Beginner
  • *
  • Posts: 3
Re: Filter product category by manufacturer
« Reply #14 on: March 12, 2007, 20:59:13 pm »
Is it also possible to filter by price groups ?

It would like to add sort boxes that show all products between 100 and 200 euro.