News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

[SOLVED]Product navigation completely wrong in VM2, rev 5302

Started by patrik60, January 21, 2012, 18:02:19 PM

Previous topic - Next topic

toonztudio


BenClay

I still haven't been able to find a fix so I've added a bit of code in my template override to set the 'prev' and 'next' links according to "product ordering" which is what my customer wants. This goes above Product Navigation section and sets new values for $this->product->neighbours.

Yes, yes all very naughty because it breaks the MVC model, bolts in the language, has my quirky indenting, etc but it works.


// Ben's Product Navigation
function cbProductName ($id)
{
// get the name for a product.
// Alert: languare is bolted in!!
$cbDB = JFactory::getDBO() ;
$cbQuery = $cbDB->getQuery(true) ;
$cbQuery = "select product_name from #__virtuemart_products_en_gb where virtuemart_product_id = ".$id ;
$cbDB->setQuery((string)$cbQuery) ;
$cbName = $cbDB->loadResult() ;
return $cbName ;
}
// get the info
$cbProduct =  $this->product->virtuemart_product_id ;
$cbCategory = $this->product->virtuemart_category_id ;
// query the database for the product ids in order (fallback order is product id)
$cbDB = JFactory::getDBO() ;
$cbQuery = $cbDB->getQuery(true) ;
$cbQuery = "select virtuemart_product_id from #__virtuemart_product_categories where virtuemart_category_id = ".$cbCategory." order by ordering,virtuemart_product_id" ;
$cbDB->setQuery((string)$cbQuery) ;
$cbList = $cbDB->loadResultArray() ;
// get prev & next from the list
$cbPosition = array_search ($cbProduct,$cbList) ;
if ($cbPosition === false)
{
$this->product->neighbours ['previous'][0] = '' ;
$this->product->neighbours ['next'][0] = '' ;
}
else
{
$cbPrev = ($cbPosition - 1 + count($cbList)) % count($cbList) ;
$cbNext = ($cbPosition + 1 + count($cbList)) % count($cbList) ;
// insert the results into $this
$this->product->neighbours ['previous'][0]['virtuemart_product_id'] = $cbList[$cbPrev] ;
$this->product->neighbours ['next'][0]['virtuemart_product_id'] = $cbList[$cbNext] ;
$this->product->neighbours ['previous'][0]['product_name'] = cbProductName($cbList[$cbPrev]) ;
$this->product->neighbours ['next'][0]['product_name'] = cbProductName($cbList[$cbNext]);
}


BTW, I'm on VM 2.0.22c and now see there is a 2.00.24. Will the ordering have been fixed in that release? Maybe somebody can answer. If it has you can ignore the above.

Also Joomla 2.5.14 and PHP 5.3.10

e-trader

On 2.0.24 the neighbors are still out of order when using for example 'creation date' as a sort option  :P

Robert_ITMan

This is NOT solved in version 2.0.24 -- looks like there is nothing for sorting by product_sku and no matter what else we choose in admin Configuration > Product Order Settings it will always sort by the product slug (alias).

My WORK AROUND is to set our slug (alias) so that the products sort how we like (currently have it the same as our sku). Looks like administrator/components/com_virtuemart/models/product.php needs a little work to get it sorting as we would expect.

Hope this helps.
WEBSITES @ OURFINGERTIPS
manage > develop > market > repeat

Save a lot of time and money when focused on building a website that works with marketing efforts to get more leads and sales from visitors.

www.ourfingertips.com

Peter Pillen

In the file administrator\components\com_virtuemart\models\product.php replace the function public function getNeighborProducts to this below.

Works in versions from 2.0.24 with every choice of sorting in backend and also when a visitor changes his preference

happy, happy, happy  ;D

<?php
public function 
getNeighborProducts ($product$onlyPublished TRUE$max 1) {

$db JFactory::getDBO ();
$direction $this->filter_order_Dir;
$app JFactory::getApplication();
if ($app->isSite ()) {
$usermodel VmModel::getModel ('user');
$currentVMuser $usermodel->getUser ();
$virtuemart_shoppergroup_ids = (array)$currentVMuser->shopper_groups;
}

if(!empty($this->orderByString)){
$orderBy $this->orderByString;

} else {
$orderBy ' ORDER BY '.$this->filter_order.' ';
}

$joinPrice strpos($orderBy,'product_price');
$joinCat strpos($orderBy,'category_name');

$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 ($joinPrice) {
$q .= ' LEFT JOIN `#__virtuemart_product_prices` as pp ON p.`virtuemart_product_id` = pp.`virtuemart_product_id` ';
}

if ($joinCat) {
$q .= ' LEFT JOIN `#__virtuemart_categories_' VMLANG '` as `c` using (`virtuemart_category_id`) ';
}

$q .= ' WHERE `virtuemart_category_id` = ' . (int)$product->virtuemart_category_id;

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) . " ) ";
}
}

if ($onlyPublished) {
$q .= ' AND p.`published`= 1';
}
$q .=  $orderBy $direction;

$db->setQuery ($q);
if ($result $db->loadAssocList ()) {
$key array_search(array('virtuemart_product_id' => $product->virtuemart_product_id'product_name' => $product->product_name) , $result);
$neighbors = array('previous' => array($result[(int)$key-1]), 'next' => array($result[(int)$key+1]));
}

$err $db->getErrorMsg();
if($err){
vmError('getNeighborProducts '.$err,'getNeighborProducts error');
}

return $neighbors;
}
?>


I left out the slug and ASC/DESC usage ... it now creates an array of all the products in that product's category, sorted according to the settings in the backend config (or set by visitor) and gets the key of the product your currently viewing ... automatically because the list is sorted, the key-1 is the previous record and the key+1 is the next record.

Only one problem left... when choosing a product from viewing the toplevel category, you always go to the sublevel category wherein that product is located. Therefore the productdetailnavigation is limited to that sublevel category.

Piombo

P2 Peter, can you get fix for VM ver. 2.6.0 (Revision: 7816)? In this version I have the same problem, but your code doesn't work. (prev next links are not shown). Thanks!

Milbo

Piombo the code is completly different now. It takes the same sql as for browsing. Just use the original files and everything should work.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Piombo

Milbo, I clearly understand that the code is changed :) But I got the VM ver. 2.6.0 (Revision: 7816) from virtuemart.net - and I have this problem :( Which original files should I use? Thanks!

Milbo

You did not modify it? so which ordering does not work then? It depends on the ordering.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Piombo

In "sort settings" i set "order" the Product Neighbours doesn't work correctly, if i set "sort by sku, name" - everything is working correctly. Thanks!

Milbo

ehrm are you aware that a product can have different ordering PER category, which you only see if you filter for one category.

The ordering which you see in the product edit is for the ordering of the child products!
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Piombo

I'm sorry, I did not understand.

I mean that  -  sreen 1  - "product neighbours" do not work correctly
If i do like this - sreen 2 - "product neighbours" is working fine

TeeJay.net

Quote from: Piombo on April 30, 2014, 09:34:02 AM
I'm sorry, I did not understand.

I mean that  -  sreen 1  - "product neighbours" do not work correctly
If i do like this - sreen 2 - "product neighbours" is working fine

I have almost the same problem.
If I set (in the BE) the default ordering for a category according to "name", product navigation (in the FE) works as expected. It works fine also for "price". I haven't tried all of them.

But with lots of other fields like "ordering" or "sku" (in the BE), the product navigation is wrong, either products are missing in the navigation, or there is the same product on both sides (to the left and right), simply it's not how it is supposed to be.

Maybe it has something to do with SEF URL, I use JoomSEF, this needs a bit more testing I guess.

restodo

Somebody solve this problem? I'm using VM 2.6.6 and the only way it works is using Order by Name.