Virtuemart Frontpage menu link, causes 404s to redirect to home page.

Started by sandstorm, July 24, 2015, 17:15:01 PM

Previous topic - Next topic

Studio 42

Hi,
For info:
i fixed haskey and added redirection for missing category.
I wanted add this in category view.html file, but the problem can only in "routing" category, then this is the right place for me.
This is my fix used for sandstorm site:
in  /components/com_virtuemart/router.php
changed :

public function getCategoryId($slug,$virtuemart_category_id ){
$db = JFactory::getDBO();
static $catIds = array();
if(!VmConfig::get('prodOnlyWLang',false) and VmConfig::$defaultLang!=VmConfig::$vmlang and Vmconfig::$langCount>1){
$q = 'SELECT IFNULL(l.`virtuemart_category_id`,ld.`virtuemart_category_id`) as `virtuemart_category_id` ';
$q .= ' FROM `#__virtuemart_categories_'.VmConfig::$defaultLang.'` AS `ld` ';
$q .= ' LEFT JOIN `#__virtuemart_categories_' .VmConfig::$vmlang . '` as l using (`virtuemart_category_id`) ';
$q .= ' WHERE IFNULL(l.`slug`,ld.`slug`) = "'.$db->escape($slug).'" ';
$hash = md5(VmConfig::$defaultLang.$slug.VmConfig::$defaultLang);
} else {
$q = "SELECT `virtuemart_category_id`
FROM  `#__virtuemart_categories_".VmConfig::$vmlang."`
WHERE `slug` = '".$db->escape($slug)."' ";
$hash = md5($slug.VmConfig::$defaultLang);
}

if(!isset($catIds[$hash])){
$db->setQuery($q);
if (!$catIds[$hash] = $db->loadResult()) {
$catIds[$hash] = $virtuemart_category_id;
}
}

return $catIds[$hash] ;
}

To:


public function getCategoryId($slug,$virtuemart_category_id ){
$db = JFactory::getDBO();
static $catIds = array();
$hash = md5(VmConfig::$vmlang.$slug.VmConfig::$defaultLang);
if(!isset($catIds[$hash]) && !empty($slug)){
if(!VmConfig::get('prodOnlyWLang',false) and VmConfig::$defaultLang!=VmConfig::$vmlang and Vmconfig::$langCount>1){
$q = 'SELECT IFNULL(l.`virtuemart_category_id`,ld.`virtuemart_category_id`) as `virtuemart_category_id` ';
$q .= ' FROM `#__virtuemart_categories_'.VmConfig::$defaultLang.'` AS `ld` ';
$q .= ' LEFT JOIN `#__virtuemart_categories_' .VmConfig::$vmlang . '` as l using (`virtuemart_category_id`) ';
$q .= ' WHERE IFNULL(l.`slug`,ld.`slug`) = "'.$db->escape($slug).'" ';
} else {
$q = "SELECT `virtuemart_category_id`
FROM  `#__virtuemart_categories_".VmConfig::$vmlang."`
WHERE `slug` = '".$db->escape($slug)."' ";
}
$db->setQuery($q);
if (!$catIds[$hash] = $db->loadResult()) {
$app = JFactory::getApplication();
$msg = jText::_('JGLOBAL_CATEGORY_NOT_FOUND');
if($virtuemart_category_id) {
$app->enqueueMessage($msg , 'error');
$app->redirect(Jroute::_('index.php?option=com_virtuemart&view=category&virtuemart_category_id='.$virtuemart_category_id.'&error=404', FALSE));
} else {
$app->enqueueMessage($msg , 'error');
$app->redirect(Jroute::_('index.php?option=com_virtuemart&error=404', FALSE));
}
}
} else if(empty($slug)) {
return $virtuemart_category_id;
}

return $catIds[$hash] ;
}


This always redirect when someone try to add manually , or a category do not exist anymore.

I Hope this is Update on next release to do all Virtuemart shops better !

Patrick Kohl

claesbas

This seems to be the same problem I have posted about here: http://forum.virtuemart.net/index.php?topic=136118.0 - it seesm to still not be fixed in 3.0.18
VMuikit - A Virtuemart theme for Yootheme template
https://joomlapro.com/vmuikit

VMonepage - One Page Checkout (Was free - now is €20)
https://joomlapro.com/product/virtuemart-one-page-checkout

VMKCO - Klarna Checkout Enhanced
https://joomlapro.com/product/virtuemart-klarna-checkout

sandstorm

I tested this too with 3.0.18 & confirm the same issue persists.
Would be nice to have this added to VM core so that I can update a few sites & not worry about overwriting this fix/code
J3.6.4 / PHP7.0.12
VM3.0.16