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

Product navigation doesn't work no more

Started by patbe60, November 17, 2022, 16:54:02 PM

Previous topic - Next topic

patbe60

Hello

Since version 4.0.7.10732 the product navigation in detail view doesn't work no longer. Sometimes  productlinks are shown, but not in alphabetic order, sometimes no productlink is shown.

Tested with J 3.10.11 and J 4.2.5

pinochico

www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

patbe60

The problem could be here:

administrator/components/com_virtuemart/models/product.php

As soon as I replace this file with the product.php prior than 4.0.7.10732 everything works fine.

patbe60

The problem is still not solved with version 4.0.8.10748

I made a fresh install of Joomla 4.2.5 and VM 4.0.8.10748 and then installed the sample data.
Go for instance to Headpeace: Cowboy Hat. You will see then a link to Cap "Baseball" but in the wrong direction (right instead of left). Then click the link. I guides you to Cap "Baseball". No navigation will be visible then.
Go to Safety Helmet. Though it is the last article in this category it shows to links in the navigation: Cowboy hat to the left and Cap "Baseball" to the right.

Either this is a bug or I have missed some important changes in this case.

patbe60

Somewhere in these code lines (2339 -2493) of the file administrator/components/com_virtuemart/models/product.php must be one ore more errors. These changes were made in version 10732 but weren't mentioned in the Repository.
Hope this will be fixed soon.

//$neighbors = array('previous' => '', 'next' => '');
$neighbors = array('next' => '', 'previous' => '');

$oldDir = $this->filter_order_Dir;


if($this->filter_order_Dir=='ASC'){
//$direction = 'DESC';
$op = '<=';
} else {
//$direction = 'ASC';
$op = '>=';
}
$direction = $this->filter_order_Dir;
//$this->filter_order_Dir = $direction;

//We try the method to get exact the next product, the other method would be to get the list of the browse view again and do a match
//with the product id and giving back the neighbours
$this->_onlyQuery = true;
$queryArray =  $this->sortSearchListQuery($onlyPublished,(int)$product->virtuemart_category_id,false,1,array('langFields'=>array('product_name')));
//vmdebug('my query stuff ',$queryArray, $product->getProperties());

if(isset($queryArray[1])){

$selects = array();
$selects['virtuemart_product_id'] = 'p.`virtuemart_product_id`';
$selects['product_name'] = '`l`.`product_name`';

$pos= strpos($queryArray[3],'ORDER BY');
$sp = array();

//$orderByName = '`l`.product_name, virtuemart_product_id';
$whereorderByName = '`l`.product_name';

if($pos){
$orderByName = trim(substr ($queryArray[3],($pos+8)) );


$orderByNameMain = $orderByName;
/*if($cpos = strpos($orderByName,',')!==false){
$t = explode(',',$orderByName);
if(!empty($t[0])){
$orderByNameMain = $t[0];
}
}*/
$orderByName = str_replace(array('DESC','ASC'), '',$orderByName);
$orderByName = trim(str_replace('`','',$orderByName));

if(strpos($orderByName,',')!==false){
$sortByNames = explode(',',$orderByName);
} else {
$sortByNames = array($orderByName);
}

vmdebug('getneighbors ',$sortByNames);
//$selectLang = ', `l`.`product_name`';
$tableLangKeys = array('product_name','product_s_desc','product_desc');
$orderByNames = array();
foreach($sortByNames as $name){
$name =  trim($name);

$sp = array();
if(strpos($name,'.')){
$sp = explode('.',$name);
$name = trim($sp[count($sp)-1]);
$name = trim($name,'`´');
}
$orderByNames['prop'][] = $name;
vmdebug('getneighbors $orderByNames',$name,$product->{$name});
if($name=='product_price'){
if(isset($product->prices['product_price'])){
$product->product_price = $product->prices['product_price'];
} else {
$product->product_price = 0.0;
}
}

if($name=='virtuemart_product_id'){
unset($selects['virtuemart_product_id']);
}
if($name=='product_name'){
unset($selects['product_name']);
}
if(isset($product->{$name})){

if(isset($sp[0])){
$n = '`'.$sp[0].'`.'.$name;

} else if(in_array($name,$tableLangKeys)){
$n = '`l`.'.$name;
} else {
$n = $name;
}
$orderByNames['select'][] = $n;
$selects[] = $n;
}
}
vmdebug('getneighbors $orderByNames',$orderByNames);
//$whereorderByName = '';
if(!empty($orderByNames)){
//$selects = array_merge($selects,$orderByNames);
//$whereorderByName = ', '.implode(', ',$orderByNames['select']);
}

}



$q = 'SELECT '.implode(', ',$selects).' FROM `#__virtuemart_products` as p
';

$joinT = '';
if(is_array($queryArray[1])){
$joinT = implode('',$queryArray[1]);
}

/*if(strpos($orderByName,'virtuemart_product_id')!==false){
$q .= $joinT . ' WHERE (' . implode (' AND ', $queryArray[2]) . ') AND p.`virtuemart_product_id`'.$op.'"'.$product->virtuemart_product_id.'" ';
} else {*/
$q .= $joinT . '
WHERE (' . implode (" AND \n ", $queryArray[2]) . ') AND p.`virtuemart_product_id`!="'.$product->virtuemart_product_id.'" '."\n";
//}


$alreadyFound = '';
foreach ($neighbors as &$neighbor) {

if(!empty($alreadyFound)) $alreadyFound = 'AND p.`virtuemart_product_id`!="'.$alreadyFound.'"';
$qm = $alreadyFound.' AND ';

foreach($orderByNames['prop'] as $k => $name){
$qm .= $orderByNames['select'][$k].' '.$op.' "'.$db->escape($product->{$name}).'" AND ';
vmdebug('getneighbors '.$qm);
}
$qm = substr($qm, 0, -4);
$qm .= '
ORDER BY '.implode(', ', $orderByNames['select']).' '.$direction.' LIMIT 1';

$db->setQuery ($q.$qm);
if($this->debug)vmdebug('getneighbors ',str_replace('#__',$db->getPrefix(),$q.$qm /*$db->getQuery()*/));

if ($result = $db->loadAssocList ()) {
$neighbor = $result;
$alreadyFound = $result[0]['virtuemart_product_id'];
}

if($direction=='ASC'){
$direction = 'DESC';
$op = '<=';

} else {
$direction = 'ASC';
$op = '>=';
}
//$orderByName = str_replace($this->filter_order_Dir,$direction,$orderByName);

patbe60

Today again I made a fresh install of Joomla 3.10.11 and VM 4.0.8.10748. => product navigation is not working unless I replace  the administrator/components/com_virtuemart/models/product.php with this one of version 10731.
Upgrading Joomla to J 4.2.5 the problem remains.

It seems not to be a problem, that the product navigation doesn't work. It's not an important thing in VM. So I will leave it and start to live without activated product navigation in the VM configuration. It's a pitty.

Milbo

Hello Pat,
you have me in skype. If you send me a backup of your store, I will fix it. I just dont have that error.

What happened? If we use a sort order which is not determined, because we just get the same sorting weight, the order of the sql can change anytime. So if we sort for example by Product names, but we have some product variants with the same name, we get different ordering. To avoid that, we need another "order by" to make it fix, most time it is just the id.
So for example, sort first alphabetically, if you get the same weight, sort by id.

But getNeighbour function had to be updated. to be able to work with two "order by".
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

philip_sorokin

I confirm: it's still not working.

Joomla ‎4.2.7‎
VM 4.0.12
PHP 8.2