Author Topic: [SOLVED]Product navigation completely wrong in VM2, rev 5302  (Read 17112 times)

toonztudio

  • Beginner
  • *
  • Posts: 4
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #30 on: September 17, 2013, 12:23:07 pm »
Hi,

thanks empixmultimedia, it's works  ;)

BenClay

  • Beginner
  • *
  • Posts: 11
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #31 on: October 14, 2013, 11:28:42 am »
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.

Code: [Select]
// 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

  • Jr. Member
  • **
  • Posts: 65
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #32 on: October 30, 2013, 00:22:46 am »
On 2.0.24 the neighbors are still out of order when using for example 'creation date' as a sort option  :P

Robert_ITMan

  • Jr. Member
  • **
  • Posts: 115
    • websites developed and managed @ ourfingertips.com
  • VirtueMart Version: 3.2.12 and 3.2.15
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #33 on: November 04, 2013, 19:59:11 pm »
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.
www.ourfingertips.com - websites developed and managed @ ourfingertips

Let me help you make the most of the technology at our fingertips

Peter Pillen

  • Jr. Member
  • **
  • Posts: 223
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #34 on: November 08, 2013, 01:37:50 am »
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

Code: [Select]
<?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

  • Beginner
  • *
  • Posts: 28
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #35 on: April 23, 2014, 11:04:52 am »
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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9856
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #36 on: April 24, 2014, 12:17:31 pm »
Piombo the code is completly different now. It takes the same sql as for browsing. Just use the original files and everything should work.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Piombo

  • Beginner
  • *
  • Posts: 28
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #37 on: April 24, 2014, 13:22:28 pm »
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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9856
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #38 on: April 24, 2014, 14:30:25 pm »
You did not modify it? so which ordering does not work then? It depends on the ordering.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Piombo

  • Beginner
  • *
  • Posts: 28
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #39 on: April 28, 2014, 14:51:59 pm »
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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9856
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #40 on: April 29, 2014, 11:56:48 am »
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!
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Piombo

  • Beginner
  • *
  • Posts: 28
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #41 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

TeeJay.net

  • Beginner
  • *
  • Posts: 22
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #42 on: August 12, 2014, 09:58:43 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

  • Jr. Member
  • **
  • Posts: 77
Re: [SOLVED]Product navigation completely wrong in VM2, rev 5302
« Reply #43 on: September 08, 2014, 17:41:45 pm »
Somebody solve this problem? I'm using VM 2.6.6 and the only way it works is using Order by Name.