VM 2.0.22a
Joomla! 2.5.14
I would like to maintain the shopper's choice of sort and sort direction in the Category view when they return from a ProductDetails view (as they click on the 'back-to-category' link).
Nb the changes I suggest in
http://forum.virtuemart.net/index.php?topic=117523.msg399701#msg399701 (http://forum.virtuemart.net/index.php?topic=117523.msg399701#msg399701)
must also be incorporated. (These correct the misbehavior of the Category view sort being ignored when the default sort is re-selected.)
In administrator/components/com_virtuemart/models/product.php
add two functions
public function getLastProductOrderDirection($default = 'ASC'){
$session = JFactory::getSession();
return $session->get('vmlastproductorderdirection', $default, 'vm');
}
public function setLastProductOrderDirection($order){
$session = JFactory::getSession();
return $session->set('vmlastproductorderdirection', (string) $order, 'vm');
}
and at around line 2056
After
$order = JRequest::getWord ('order', 'ASC');
Add
$this->setLastProductOrderDirection($order);
In components/com_virtuemart/views/productdetails/tmpl/default.php or its override
at around line 93
change
<?php // Back To Category Button
if ($this->product->virtuemart_category_id) {
$catURL = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$this->product->virtuemart_category_id, FALSE);
$categoryName = $this->product->category_name ;
} else {
$catURL = JRoute::_('index.php?option=com_virtuemart');
$categoryName = jText::_('COM_VIRTUEMART_SHOP_HOME') ;
}
?>
to
<?php // Back To Category Button
if ($this->product->virtuemart_category_id) {
$filter_orderby = VirtueMartModelProduct::getLastProductOrdering();
if($filter_orderby == "0"){
$filter_orderby =VmConfig::get ('browse_orderby_field');
$filter_orderdir_text = '';
}
else {
$filter_orderdir = VirtueMartModelProduct::getLastProductOrderDirection();
if(($filter_orderdir == "0") || ($filter_orderdir == "ASC")){
$filter_orderdir_text = '';
}
else {
$filter_orderdir_text .= '&order=' . $filter_orderdir;
}
}
$filter_orderby_text = '&orderby='.$filter_orderby;
$catURL = JRoute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$this->product->virtuemart_category_id . $filter_orderby_text . $filter_orderdir_text );
$categoryName = $this->product->category_name ;
} else {
$catURL = JRoute::_('index.php?option=com_virtuemart');
$categoryName = jText::_('COM_VIRTUEMART_SHOP_HOME') ;
}
?>
Many thanks to all the great work!
Until the next update ... :-)
Would be good to have a patch for both issues. Please read http://dev.virtuemart.net/projects/virtuemart/wiki/Setting_up_a_Development_Environment and create a patch for us, for the latest version.
Be aware that the provided link of the svn is for vm2.1.x