VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: patbe60 on November 17, 2022, 16:54:02 PM

Title: Product navigation doesn't work no more
Post by: patbe60 on November 17, 2022, 16:54:02 PM
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
Title: Re: Product navigation doesn't work no more
Post by: pinochico on November 18, 2022, 10:54:22 AM
We don't use product navigation, sorry :)
Title: Re: Product navigation doesn't work no more
Post by: patbe60 on November 18, 2022, 16:37:29 PM
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.
Title: Re: Product navigation doesn't work no more
Post by: patbe60 on November 22, 2022, 12:58:36 PM
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.
Title: Re: Product navigation doesn't work no more
Post by: patbe60 on November 23, 2022, 01:07:27 AM
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);
Title: Re: Product navigation doesn't work no more
Post by: patbe60 on December 02, 2022, 13:50:52 PM
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.
Title: Re: Product navigation doesn't work no more
Post by: Milbo on December 02, 2022, 21:04:53 PM
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".
Title: Re: Product navigation doesn't work no more
Post by: philip_sorokin on February 07, 2023, 23:28:55 PM
I confirm: it's still not working.

Joomla ‎4.2.7‎
VM 4.0.12
PHP 8.2