News:

Support the VirtueMart project and become a member

Main Menu

Customizing sorting options?

Started by EvanGR, December 27, 2018, 13:04:50 PM

Previous topic - Next topic

EvanGR

Hello,

We find the default VM frontend sorting, with the +/- functionality, to be confusing for our purposes. So I would like to override the sorting to offer specific options such as:

- sort by price (low to high)
- sort by price (high to low)
- sort by popularity (product page views)

etc...


a) What are the files I need to override?

b) Any existing code examples for the above functionality?

Thank you

PRO

I have some code examples
I USE The sort by javascript to add additional sort by boxes on my category page.


code here is what i use to manually create the standard sort by box

public static function cSort($free=1,$follow=0){
$jinput = JFactory::getApplication()->input;
$searchnone=$jinput->get('keyword',0);
$ccat = $jinput->getInt('virtuemart_category_id', 0);
$item = $jinput->getInt('Itemid', 0);
$requestorder=$jinput->get('orderby',0);
$descorder=$jinput->get('dir',0);
$freefollow=' rel="nofollow"';
if ($follow==1){$freefollow=' ';}
$name='Sort by ';
// modify the name based on current sort
if (!empty($requestorder)){
if ($requestorder=='product_price' && $descorder=='DESC'){$name='Highest Price';
$high=1;
$lowest='';
}
if ($requestorder=='product_price' && empty($descorder)){$name='Lowest Price';
$lowest=1;
$high='';
}
if ($requestorder=='product_weight'){$name='Free Shipping';
$free='';
}
if ($requestorder=='product_sales'){$name='Best Selling';
$best=1;
}


}
$priceurl=JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$ccat.'&Itemid='.$item.'&orderby=product_price');
$highpriceurl=JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$ccat.'&Itemid='.$item.'&dir=DESC&orderby=product_price');
$freeshipurl=JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$ccat.'&Itemid='.$item.'&orderby=product_weight');
$bestsalesurl=JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$ccat.'&Itemid='.$item.'&dir=DESC&orderby=product_sales');
$cathomeurl=JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$ccat.'&Itemid='.$item);
$html = '';
$html.='<div class="orderby-displaynumber width10 min150">';
$html.='   <div class="floatleft vm-order-list">';
$html.='      <div class="orderlistcontainer"><div class="title blue min150 center">'.$name. '<img src="images/down.png" alt="Sort" /></div>';
$html.='      <div class="orderlist min175"><div>';
if (empty($lowest)){
$html.='<div><a rel="nofollow" title="Sort By Lowest Price" href="'.$priceurl.'">Lowest Price</a></div>';}
if (empty($high)){
$html.='<div class="btop"><a rel="nofollow" title="Sort By Highest Price" href="'.$highpriceurl .'">Highest Price</a></div>';}
if ($free==1){
$html.='<div class="btop"><a'.$freefollow.'title="Sort By Free Shipping" href="'.$freeshipurl .'">Free Shipping</a></div>';
}
if (empty($best)){
$html.='<div class="btop"><a rel="nofollow" title="Sort By Best Selling" href="'.$bestsalesurl .'">Best Selling</a></div>';}
$html.='</div></div></div></div></div>';
return $html;
}

Then this below, i use it to convert a comma separated list into a dropdown
The list is separated like
Anchor|Link,Anchor|link


// creates a dropdown like sort etc. from comma separated links Anchor | Link, Anchor | Link
public static function dropSort($sortstring,$title='Sort By',$class=' desktop '){
if (!empty($sortstring) or (!empty($tlink))){
$infolinks= explode(',', $sortstring);
$min=' min150 ';
$width='width10';
if (strlen($title) >=12){$min=' min200 ';
$width=' width10 ';}

$html = '';
$html.='<div class="orderby-displaynumber width8'.$min.$class.'">';
$html.='   <div class="floatleft vm-order-list">';
$html.='<div class="orderlistcontainer"><div class="title blue min150 center">'.$title.' <img src="images/down.png" alt="Sort" /></div>';
$html.='<div class="orderlist"><div>';
$i=1;
foreach ($infolinks as $links){
      $link = strstr($links,"|") ;
      $link=str_replace( '|', '', $link );
      $linkanchor=str_replace( $link, '', $links );
      $linkanchor=str_replace( '|', '', $linkanchor );
      if (!empty($linkanchor)){
   $html.='<div class="i'.$i.' top10"><a title="'.$linkanchor.'" href="'.$link.'">'.$linkanchor.'</a></div>';
      }
      $i++;}
$html.='</div></div></div></div></div>';
return $html;
}
}

EvanGR


EvanGR

Some questions:

1) What are the URL parameters to sort products by 'most recent first'?

2) What are the URL parameters to sort products by 'most viewed first'? (product page vists)

3) Does the URL parameter 'orderby=product_sales' actually sorts products with the highest sales first? Does it work properly?

Thanks

PRO

u can find the urls by turning off SEF and copying them.


I think u will have to add (dir=DESC) like in the link below

$bestsalesurl=JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$ccat.'&Itemid='.$item.'&dir=DESC&orderby=product_sales');

dir=DESC    is  descending order

soura123

#5
Quote from: PRO on December 28, 2018, 02:38:01 AM
I have some code examples
I USE The sort by javascript to add additional sort by boxes on my category page.

hello, can you give an example how to implement this on my category page template?