Author Topic: "Latest products" filters doesn't work in my categories  (Read 2143 times)

imudo

  • Beginner
  • *
  • Posts: 5
"Latest products" filters doesn't work in my categories
« on: December 03, 2009, 17:09:41 pm »
Hello everybody,

First, excuse my poor english because I am a french woman and my english is not perfect, but I will try to be clear enough :)

I didn't find the anwser to my question in french joomla forum, and nobody seems to have the answer (or they don't want to give it to me ?), that's why I post a message on this forum.

My problem : when I create a product in my shop, it appears at the bottom of the category, so olders products appears first on my page.

However, in the backoffice, I made this configuration :
Component > Virtuemart > Configuration > Site > Default product sort order : Latest Product
(and there are also "Product name" and "Latest Products" available in "Sort-by" fields)

In the Frontoffice, even if I use the filter "Latest products", latest products still appears in the bottom of the page.. But I would like the contrary !

On french forum, someone told me to modify the file "administrator/component/virtuemart/classes/ps_product.php", and to change

Code: [Select]
function latestProducts($random, $products) {
return "";
}


with


Code: [Select]
function latestProducts($random, $category_id) {
global $VM_LANG;
require_once( CLASSPATH . 'ps_product_attribute.php');
$ps_product_attribute = new ps_product_attribute();
$max_items = 4;
$db = new ps_DB;
$tpl = new $GLOBALS['VM_THEMECLASS']();
$category_id = null;
if($categories) {
$category_id = vmRequest::getInt('category_id');
}
$q = "SELECT DISTINCT product_sku,#__{vm}_product.product_id,
product_name, product_s_desc,product_thumb_image, product_full_image, product_in_stock, product_url FROM #__{vm}_product, #__{vm}_product_category_xref, #__{vm}_category WHERE \n";
$q .= "(#__{vm}_product.product_parent_id='' OR #__{vm}_product.product_parent_id='0') \n";
$q .= "AND #__{vm}_product.product_id=#__{vm}_product_categor y_xref.product_i d \n";
$q .= "AND #__{vm}_category.category_id=#__{vm}_product_categ ory_xref.category_id \n";
if( !empty( $category_id ) ) {
$q .= "AND #__{vm}_category.category_id='$category_id' ";
}
if( CHECK_STOCK && PSHOP_SHOW_OUT_OF_STOCK_PRODUCTS != "1") {
$q .= " AND product_in_stock > 0 ";
}
$q .= "AND #__{vm}_product.product_publish='Y' ";
$q .= "ORDER BY #__{vm}_product.product_id DESC ";
$q .= "LIMIT 0, $max_items ";
$db->query($q);
if( $db->num_rows() > 0 ){
$i = 0;
$latest_products = array();
while($db->next_record() ){
$flypage = $this->get_flypage($db->f("product_id"));
$latest_products[$i]['product_sku'] = $db->f("product_sku");
$latest_products[$i]['product_name'] = $db->f("product_name");
$price = "";
if (_SHOW_PRICES == '1') {
// Show price, but without "including X% tax"
$price = $this->show_price( $db->f("product_id"), false );
}
$latest_products[$i]['product_price'] = $price;
$latest_products[$i]['product_s_desc'] = $db->f("product_s_desc");
$latest_products[$i]['product_url'] = $db->f("product_url");
$latest_products[$i]['product_thumb'] = $db->f("product_thumb_image");
$latest_products[$i]['product_full_image']= $db->f("product_full_image");
$latest_products[$i]['product_id'] = $db->f("product_id");
$latest_products[$i]['flypage'] = $flypage;
$latest_products[$i]['form_addtocart'] = "";
if (USE_AS_CATALOGUE != '1' && $price != ""
&& !stristr( $price, $VM_LANG->_('PHPSHOP_PRODUCT_CALL') )
&& !$this->product_has_attributes( $db->f('product_id'), true )
&& $tpl->get_cfg( 'showAddtocartButtonOnProductList' ) ) {
$tpl->set( 'i', $i );
$tpl->set( 'product_id', $db->f('product_id') );
$tpl->set( 'ps_product_attribute', $ps_product_attribute );
$tpl->set( 'product_in_stock', $db->f('product_in_stock'));
$latest_products[$i]['form_addtocart'] = $tpl->fetch( 'browse/includes/addtocart_form.tpl.php' );
$latest_products[$i]['has_addtocart'] = true;
}
$i++;
}
$tpl->set( 'latest_products', $latest_products );
return $tpl->fetch( 'common/latestProducts.tpl.php');
}
}


I try but it doesn't change anything.
I'm not a developper, only have some concepts, but isn't a very long code for only reverse the products display  ?..

Have someone here already meet this kind of problem ?

Thank you for your answer !



imudo

  • Beginner
  • *
  • Posts: 5
Re: "Latest products" filters doesn't work in my categories
« Reply #1 on: December 03, 2009, 17:12:01 pm »
Oups I didn't see someone just before me asked the same question !

(but he doesn't have any answer too  :/ )

rb

  • Advanced
  • Full Member
  • *****
  • Posts: 1503
Re: "Latest products" filters doesn't work in my categories
« Reply #2 on: December 04, 2009, 01:34:16 am »
The way the filter works with "Latest Products" can be a bit confusing.  See if the attached diagram helps explain a bit.  I know this doesn't resolve your issue - just trying to shed a little light on the problem.


[attachment cleanup by admin]

RannaK

  • Beginner
  • *
  • Posts: 17
Re: "Latest products" filters doesn't work in my categories
« Reply #3 on: December 04, 2009, 07:57:54 am »
I think the answer you want is located here:

http://forum.virtuemart.net/index.php?topic=62491.0

So far it appears to be working form me. This has been driving me crazy forever. It should be DESC by default.

imudo

  • Beginner
  • *
  • Posts: 5
Re: "Latest products" filters doesn't work in my categories
« Reply #4 on: December 04, 2009, 11:25:27 am »
Oh thank you !!!!

That's exactly what I was looking for and it works !!!   :D