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

Skye

  • Beginner
  • *
  • Posts: 13
Re: Filter product category by manufacturer
« Reply #30 on: July 31, 2007, 19:36:33 pm »
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?

I know this was relegated to another discussion, but felt that I should respond none the less.  I also was having an EXTREMELY hard time trying to find how to do this.

I have used the code that Pisu has above, and I made all of my manufacturers be the information I needed included.  In other words, create manufacturer Used, and New and assign them to each of your products.  You can then have it show up in the list.

In my case, I needed to allow the users to be able to choose a college, nfl, or mlb team once they had the browse results, with this code, it worked excellently.  Of course I don't have the ability to list manufacturers now, but we do have to trade off every now and then.  :)

Pisu

  • Contributing Developer
  • Jr. Member
  • *
  • Posts: 451
  • ..still looking for..
    • Blog di Stefano Bagnatica
Re: Filter product category by manufacturer
« Reply #31 on: September 11, 2007, 10:00:49 am »
If someone is interested, I updated the package, updating the files to VirtueMart version 1.0.12.

ZIP file in first post.
http://forum.virtuemart.net/index.php?topic=24349.msg64328#msg64328
Pisu - Team VMItalia (Supporto Italiano VirtueMart)
www.stefanobagnatica.it | www.vmitalia.net

Cat

  • Beginner
  • *
  • Posts: 17
Re: Filter product category by manufacturer
« Reply #32 on: September 11, 2007, 13:10:12 pm »
Man, you rule! This thing that you created is really an option VM was missing.
Thanks a lot, buddy, fantastic job.

Regards,
Adam

Anthony C.

  • Jr. Member
  • **
  • Posts: 286
Re: Filter product category by manufacturer
« Reply #33 on: September 12, 2007, 00:14:29 am »
Yeah that is right..

the mod is in this post.

^^ Glad you found it.

Anthony c.

eloo

  • Beginner
  • *
  • Posts: 8
Re: Filter product category by manufacturer
« Reply #34 on: October 29, 2007, 11:58:25 am »
hello
i m trying to adapt your hack to filter product categories by product_type

I adapted your code like this :

i addes the variable $producttype_id
Code: [Select]
global $manufacturer_id,$producttype_id,$keyword1,$keyword2,$search_category,$DescOrderBy,$search_limiter,
$search_op,$orderby,$product_type_id, $default, $vmInputFilter, $VM_BROWSE_ORDERBY_FIELDS;
i added  ligne 120 *** NOW START THE PRODUCT LIST ***/
Code: [Select]
/
else {

/* Set Dynamic Page Title */
if( $category_id ) {
$db->query( "SELECT category_id, category_name FROM #__{vm}_category WHERE category_id='$category_id'");
$db->next_record();
$mainframe->setPageTitle( $db->f("category_name") );
}
elseif( $manufacturer_id) {
$db->query( "SELECT manufacturer_id, mf_name FROM #__{vm}_manufacturer WHERE manufacturer_id='$manufacturer_id'");
$db->next_record();
$mainframe->setPageTitle( $db->f("mf_name") );
}
elseif( $producttype_id) {
$db->query( "SELECT product_type_id, product_type_name FROM #__{vm}_product_type WHERE product_type_id='$producttype_id'");
$db->next_record();
$mainframe->setPageTitle( $db->f("product_type_name") );
}
and i added in section  <!-- ORDER BY .... FORM -->
just before  input hidden, i added :
Code: [Select]
$query  = "SELECT distinct a.product_type_id,a.product_type_name FROM #__{vm}_product_type AS a ";
if (!empty( $category_id ) ) {
    $query .= ", #__{vm}_product_category_xref AS d, "
    . " #__{vm}_product AS b, "
    . " #__{vm}_product_product_type_xref AS c "
    . " WHERE d.category_id='$category_id'"
    . " AND d.product_id = b.product_id AND b.product_publish='Y' "
    . " AND b.product_id = c.product_id AND c.product_type_id = a.product_type_id ";
}
$query .= "ORDER BY product_type_name ASC";
$db = new ps_DB;
$db->query( $query );

$res = $db->record;

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


        
?>

        </select>
this code works properly

in shop_browse_queries.php, i added just after /*** GET ALL PUBLISHED PRODUCTS FROM THAT MANUFACTURER ***/

Code: [Select]
/*** GET ALL PUBLISHED PRODUCTS FROM THAT producttype ***/
if (!empty($producttype_id)) {
$table_names .= ',`#__{vm}_product_product_type_xref`';
$where_clause[]  = "product_type_id='".$producttype_id."'";
$where_clause[] = "`#__{vm}_product`.`product_id`=`#__{vm}_product_product_type_xref`.`product_id` ";

}

i forgot something, the results page is empty !

Someone to help me, i'm a beginners ith joomla, virtuemart, and php ! ??

thank you very much

Pisu

  • Contributing Developer
  • Jr. Member
  • *
  • Posts: 451
  • ..still looking for..
    • Blog di Stefano Bagnatica
Re: Filter product category by manufacturer
« Reply #35 on: October 29, 2007, 15:16:26 pm »
I don't know... You should try to catch the final resulting query, and analyse the SQL code... You can do this simply adding, in shop_browse_queries.php, just before the script end, the echo command :

Code: [Select]
echo $q;
// BACK TO shop.browse.php !
?>
Pisu - Team VMItalia (Supporto Italiano VirtueMart)
www.stefanobagnatica.it | www.vmitalia.net

eloo

  • Beginner
  • *
  • Posts: 8
Re: Filter product category by manufacturer
« Reply #36 on: October 30, 2007, 12:59:15 pm »
Thank you for the tip's !

the final resulting query :
Quote
LEFT JOIN `#__{vm}_product_price` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_price`.`product_id` LEFT JOIN `#__{vm}_product_type_6` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_type_6`.`product_id` LEFT JOIN `#__{vm}_product_product_type_xref` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_product_type_xref`.`product_id` WHERE `#__{vm}_product_category_xref`.`product_id`=`#__{vm}_product`.`product_id` AND `#__{vm}_product_category_xref`.`category_id`=`#__{vm}_category`.`category_id` AND `#__{vm}_product_category_xref`.`category_id`=39 AND `#__{vm}_product_product_type_xref`.`product_type_id`=6 AND ((`#__{vm}_product`.`product_id`=`#__{vm}_product_price`.`product_id` AND `#__{vm}_shopper_group`.`shopper_group_id`=`#__{vm}_product_price`.`shopper_group_id`) OR `#__{vm}_product_price`.`product_id` IS NULL) AND `#__{vm}_shopper_group`.`default` = 1 AND `product_parent_id`=0 AND `product_publish`='Y' GROUP BY `#__{vm}_product`.`product_sku` ORDER BY `#__{vm}_product`.`product_name` ASC

i dont know  how i can modify  ???
Quote
LEFT JOIN `#__{vm}_product_type_6` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_type_6`.`product_id` LEFT JOIN `#__{vm}_product_product_type_xref` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_product_type_xref`.`product_id
that seems wrong

i need some help !  :)

[attachment cleanup by admin]

Pisu

  • Contributing Developer
  • Jr. Member
  • *
  • Posts: 451
  • ..still looking for..
    • Blog di Stefano Bagnatica
Re: Filter product category by manufacturer
« Reply #37 on: October 30, 2007, 14:20:50 pm »
Ok so the problem seems to be here...
Quote
#__{vm}_product_type_6
The number id "6" is appended to the table name... That is wrong...
Pisu - Team VMItalia (Supporto Italiano VirtueMart)
www.stefanobagnatica.it | www.vmitalia.net

eloo

  • Beginner
  • *
  • Posts: 8
Re: Filter product category by manufacturer
« Reply #38 on: October 30, 2007, 16:19:19 pm »
yes you're right.
i modify in original shop_browse_queries.php, the lines :
Code: [Select]
// Filter Products by Product Type
if (!empty($product_type_id)) {
require_once (CLASSPATH."ps_product_type.php");
$ps_product_type = new ps_product_type();

// list parameters:
$q  = "SELECT `parameter_name`, `parameter_type` FROM `#__{vm}_product_type_parameter` WHERE `product_type_id`='$product_type_id'";
$db_browse->query($q);

/*** GET ALL PUBLISHED PRODUCT WHICH MATCH PARAMETERS ***/
$join_array[] = "LEFT JOIN `#__{vm}_product_type_$product_type_id` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_type_$product_type_id`.`product_id` ";
$join_array[] = "LEFT JOIN `#__{vm}_product_product_type_xref` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_product_type_xref`.`product_id` ";
$where_clause[] = "`#__{vm}_product_product_type_xref`.`product_type_id`=$product_type_id ";

with this lines
Code: [Select]
// Filter Products by Product Type
if (!empty($product_type_id)) {
require_once (CLASSPATH."ps_product_type.php");
$ps_product_type = new ps_product_type();

// list parameters:
$q  = "SELECT `parameter_name`, `parameter_type` FROM `#__{vm}_product_type_parameter` WHERE `product_type_id`='$product_type_id'";
$db_browse->query($q);

/*** GET ALL PUBLISHED PRODUCT WHICH MATCH PARAMETERS ***/
$join_array[] = "LEFT JOIN `#__{vm}_product_type` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_type`.`product_id` ";
$join_array[] = "LEFT JOIN `#__{vm}_product_product_type_xref` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_product_type_xref`.`product_id` ";
$where_clause[] = "`#__{vm}_product_product_type_xref`.`product_type_id`=$product_type_id ";

now the final resluting quey is :
Quote
LEFT JOIN `#__{vm}_product_price` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_price`.`product_id` LEFT JOIN `#__{vm}_product_type` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_type`.`product_id` LEFT JOIN `#__{vm}_product_product_type_xref` ON `#__{vm}_product`.`product_id` = `#__{vm}_product_product_type_xref`.`product_id` WHERE `#__{vm}_product_category_xref`.`product_id`=`#__{vm}_product`.`product_id` AND `#__{vm}_product_category_xref`.`category_id`=`#__{vm}_category`.`category_id` AND `#__{vm}_product_category_xref`.`category_id`=39 AND `#__{vm}_product_product_type_xref`.`product_type_id`=19 AND ((`#__{vm}_product`.`product_id`=`#__{vm}_product_price`.`product_id` AND `#__{vm}_shopper_group`.`shopper_group_id`=`#__{vm}_product_price`.`shopper_group_id`) OR `#__{vm}_product_price`.`product_id` IS NULL) AND `#__{vm}_shopper_group`.`default` = 1 AND `product_parent_id`=0 AND `product_publish`='Y' GROUP BY `#__{vm}_product`.`product_sku` ORDER BY `#__{vm}_product`.`product_name` ASC


and no products were found  :-[

Bob Hall

  • Beginner
  • *
  • Posts: 3
Re: Filter product category by manufacturer
« Reply #39 on: December 17, 2007, 17:50:07 pm »
For VM 1.0.13a, can we just use the 1.0.12 files? This sounds like exactly what I need for our new VM shop.

Pisu

  • Contributing Developer
  • Jr. Member
  • *
  • Posts: 451
  • ..still looking for..
    • Blog di Stefano Bagnatica
Re: Filter product category by manufacturer
« Reply #40 on: December 17, 2007, 20:40:00 pm »
Attaching the package updated for VM 1.0.13; in this version, only the file shop.browse.php need to be changed!

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

hussan

  • Beginner
  • *
  • Posts: 16
Re: Filter product category by manufacturer
« Reply #41 on: December 20, 2007, 12:58:29 pm »
Hello

its a great job, bot how i show the manufacturer name with de name of product:

example: TOSHIBA A215-S4697 in my site only show the name(A215-S4697)

can helpme?

h

Pisu

  • Contributing Developer
  • Jr. Member
  • *
  • Posts: 451
  • ..still looking for..
    • Blog di Stefano Bagnatica
Re: Filter product category by manufacturer
« Reply #42 on: December 20, 2007, 13:56:55 pm »
its a great job, bot how i show the manufacturer name with de name of product:
example: TOSHIBA A215-S4697 in my site only show the name(A215-S4697)

In file shop.browse.php, just after this line:
Code: [Select]
$product_cell = str_replace( "{product_sku}", $db_browse->f("product_sku"), $product_cell );
Add this:
Code: [Select]
$product_cell = str_replace( "{manufacturer}", $ps_product->get_mf_name($db_browse->f("product_id")), $product_cell );

Now, you can use the {manufacturer} in templates/browse_1.php, in the position where do you want to see the manufacturer name.
Pisu - Team VMItalia (Supporto Italiano VirtueMart)
www.stefanobagnatica.it | www.vmitalia.net

hussan

  • Beginner
  • *
  • Posts: 16
Re: Filter product category by manufacturer
« Reply #43 on: December 20, 2007, 14:00:52 pm »
tanks a lot!

h2

hussan

  • Beginner
  • *
  • Posts: 16
Re: Filter product category by manufacturer
« Reply #44 on: December 21, 2007, 13:30:20 pm »
Pisu,

how i order my browse page in this order:

manufacturer and product_name

now in my page: www.lojasnoparaguai.net/notebook.html order by name products... i need order by manufacturer, product_name

thanks for your replies

h2