VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: guardiano78 on September 10, 2015, 17:35:22 PM

Title: product list ordering
Post by: guardiano78 on September 10, 2015, 17:35:22 PM
Hello,
in configuration i set ordering product by stock descending.
i need to add to the query, product_price asc and product_availability asc, simultaneously.
with debug i found this query:

SELECT SQL_CALC_FOUND_ROWS  p.`virtuemart_product_id`
  FROM `jos_virtuemart_products` as p 

  LEFT JOIN `jos_virtuemart_product_shoppergroups` as ps
  ON p.`virtuemart_product_id` = `ps`.`virtuemart_product_id` 

  LEFT JOIN `jos_virtuemart_product_categories` as pc
  ON p.`virtuemart_product_id` = `pc`.`virtuemart_product_id` 

  LEFT JOIN `jos_virtuemart_categories` as c
  ON c.`virtuemart_category_id` = `pc`.`virtuemart_category_id`

  WHERE ( `pc`.`virtuemart_category_id` = 152
  AND  `c`.`published` = 1 
  AND  ( `ps`.`virtuemart_shoppergroup_id`= "108"  OR `ps`.`virtuemart_shoppergroup_id` IS NULL  ) 
  AND  p.`published`="1" )

  group by p.`virtuemart_product_id`

  ORDER BY `p`.product_in_stock  DESC
  LIMIT 0, 10

i hope that this is the right query that i have to modify.
in which file i can do this? and how?

thanks.
Title: Re: product list ordering
Post by: Studio 42 on September 11, 2015, 02:29:21 AM
Yes, but not, if you change this directly in the model, this is applied in all product lists.(random, featured ...)
Title: Re: product list ordering
Post by: guardiano78 on September 11, 2015, 12:39:51 PM
I understand. I would try anyway.
how can I do?
Title: Re: product list ordering
Post by: Milbo on September 13, 2015, 22:09:16 PM
product.php in models folder function sortSearchListQuery

There are switches, you can add it there. You can also write a plugin, to modify the query.
Title: Re: product list ordering
Post by: guardiano78 on September 14, 2015, 12:46:51 PM
This function works for all sorts or just research?

I can not understand what is the line to be changed

thanks.
Title: Re: product list ordering
Post by: GJC Web Design on September 14, 2015, 12:55:17 PM
imho for ALL product by cat displays, searches etc
Title: Re: product list ordering
Post by: guardiano78 on September 14, 2015, 13:01:32 PM
I can not understand what is the line to be changed... sorry
Title: Re: product list ordering
Post by: GJC Web Design on September 14, 2015, 13:37:32 PM
search for the comment 
// special  orders case

in the product.php file
Title: Re: product list ordering
Post by: guardiano78 on September 15, 2015, 10:38:45 AM
please... can you tell me the line specific that i need to modify?
Title: Re: product list ordering
Post by: Studio 42 on September 15, 2015, 11:09:37 AM
Quote from: guardiano78 on September 15, 2015, 10:38:45 AM
please... can you tell me the line specific that i need to modify?
admin/components/virtuemart/models/product.php
Title: Re: product list ordering
Post by: Milbo on September 15, 2015, 11:31:14 AM
Patrick, I told him already, the file and the function.

Quote from: Milbo on September 13, 2015, 22:09:16 PM
product.php in models folder function sortSearchListQuery

There are switches, you can add it there. You can also write a plugin, to modify the query.

guardiano78, There is no line to modify, you must change some more lines of the function, but as I said before, instead of hacking the core, you should write a plugin.
Title: Re: product list ordering
Post by: guardiano78 on September 15, 2015, 11:40:48 AM
now I understand. thank you.  :)