default product order is by id
on the category page, products are correctly ordered
on the product details page, however, previous and next link to semi-random products.
for one category which includes 16 products, id# 2-7 and 9-18, clicking on "next" starting from #2 leads to the sequence:
2 - 5 - 4 - 16 - 6 - 7 - 11 - 14 - 17 - 18
clicking "previous" starting from 18 gets the same (reversed) order.
starting from #3 gets the sequence
3 - 10 - 9 - 12 - 15 - 2
#2 correctly has no "previous" link and #18 no "next" link, but #13 has no "previous" link, and its "next" link is #3
for a given product, previous and next are always the same (wrong) products
I use a template override for this view, but as far as I can tell the links are correct, here's the code I use for "previous" and "next" (only arrows are displayed on the page, no product name), and in j1.7.3/vm2.0.0 the product order was correct.
<div class="product-neighbours">
<?php
if (! empty ( $this->product->neighbours ['previous'][0] )) {
$prev_link = JRoute::_ ( 'index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->neighbours ['previous'][0] ['virtuemart_product_id'] . '&virtuemart_category_id=' . $this->product->virtuemart_category_id );
echo JHTML::_ ( 'link', $prev_link, /*$this->product->neighbours ['previous'] ['product_name']*/ '', array ('class' => 'previous-page' ) );
}
?>
</div>
<div class="product-neighbours">
<?php
if (! empty ( $this->product->neighbours ['next'][0] )) {
$next_link = JRoute::_ ( 'index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $this->product->neighbours ['next'][0] ['virtuemart_product_id'] . '&virtuemart_category_id=' . $this->product->virtuemart_category_id );
echo JHTML::_ ( 'link', $next_link, /*$this->product->neighbours ['next'] ['product_name']*/ '', array ('class' => 'next-page' ) );
}
?>
</div>
has anybody else noticed something similar?
ok the problem is the sorting key in the getProductNeighbors function is hard-coded. In 2.0.0 it was the product id, in 2.0.2 it's the slug.
If a category's sorting key is the same as the function's, everything goes well, but if it's different there are problems.
the function should use the category's sorting key instead of "slug" or "virtuemart_product_id".
I don't know how this parameter is stored, however, maybe something like $product->category->sort_order ?
at first glance the rewrite is pretty straightforward.
Hello i Solved this problem with the following changes to the query made by Product Model (in administration->components->com_virtuemart->models->poduct.php)
$q = 'SELECT `l`.`virtuemart_product_id`, `l`.`product_name`
FROM `#__virtuemart_products` as `p`
JOIN `#__virtuemart_products_' . VMLANG . '` as `l` using (`virtuemart_product_id`)
JOIN `#__virtuemart_product_categories` as `pc` using (`virtuemart_product_id`)';
if ($app->isSite ()) {
$q .= ' LEFT JOIN `#__virtuemart_product_shoppergroups` as `psgr` on (`psgr`.`virtuemart_product_id`=`l`.`virtuemart_product_id`)';
}
if ($app->isSite ()) {
if (!class_exists ('shopFunctionsF'))
require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopFunctionsF.php');
$lastId = shopFunctionsF::getLastVisitedCategoryId();
if(empty($lastId)){
$lastId = (int)$product->virtuemart_category_id;
}
$q .= ' WHERE `virtuemart_category_id` = ' . $lastId;
} else {
$q .= ' WHERE `virtuemart_category_id` = ' . (int)$product->virtuemart_category_id;
}
$q .= ' and `product_name` ' . $op . ' "' . $product->product_name . '" ';
if ($app->isSite ()) {
if (is_array ($virtuemart_shoppergroup_ids)) {
$sgrgroups = array();
foreach ($virtuemart_shoppergroup_ids as $key => $virtuemart_shoppergroup_id) {
$sgrgroups[] = 'psgr.`virtuemart_shoppergroup_id`= "' . (int)$virtuemart_shoppergroup_id . '" ';
}
$sgrgroups[] = 'psgr.`virtuemart_shoppergroup_id` IS NULL ';
$q .= " AND ( " . implode (' OR ', $sgrgroups) . " ) ";
}
}
// $q .= ' AND (`psgr`.`virtuemart_shoppergroup_id` IS NULL OR `psgr`.`virtuemart_shoppergroup_id`= "'..'" ';
if ($onlyPublished) {
$q .= ' AND p.`published`= 1';
}
$q .= ' ORDER BY `product_name` ' . $direction . ' LIMIT 0,' . (int)$max;
Changed basically the "slug" with product_name.
Of course this is a huge hack in core files..I would like to have a better solution but I not really expert in Joomla. Can someone tell me if there is a way to "hook" or make this change in a Update safe way?
Best regards,
Joao Garin
Please check version 2.0.15 F http://forum.virtuemart.net/index.php?topic=110743.0