VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: sandstorm on July 24, 2015, 17:15:01 PM

Title: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: sandstorm on July 24, 2015, 17:15:01 PM
Using;
J3.4.3
VM3.0.8

I have home menu link set to virtuemart frontpage, which only displays "Featured" & "Latest" products.

This works fine and all menu links work OK, but there is a problem.
All 404's or non-menu links just redirect to the homepage instead of showing the 404 error page.

I racked my brains all day, swapping servers, disabling plugins & lots more. Only to find;

changing the home link to not use a virtuemart link, solved my problems.

Is there an issue with using the frontpage menu link, or do I have a setting out of place somewhere within virtuemart.
EDIT;
I also tested with using a virtuemart category link & this too created the problem of no 404 pages, so I guess there is some sort or redirection / routing bug

Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: Studio 42 on July 24, 2015, 23:04:48 PM
Hi,
In vm3 release, a soft 404 as been added i don't know exactly why, some say it's better and not a problem for SEO , perhaps it comes from here.
I have see you can deactivate it in vm config, but don't know if this change something.
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: sandstorm on July 25, 2015, 10:55:25 AM
I saw that too & have tried with "Use Virtuemart 404 error handling" on & off.

You can see this problem here - http://winestore.co.uk/wine
This is link to a category page, where if you add anything at the end of the URL, instaed of showing a 404, it just refreshes the page. ???
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: Studio 42 on July 25, 2015, 12:06:26 PM
Do you use core SEF or third party SEF?
I have check adding anything to the link, this give no 404 statut but always 200 (eg. http://winestore.co.uk/wine/santaclauss).
but using http://winestore.co.uk/wine/santaclauss-ws give a 404 error.

On cheking the router, i perhaps found why:

   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] ;
}


Check this code:

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

if $catIds[$hash] is not found then current vm router use $virtuemart_category_id comming from menu !

try to add after (line 643) :
} elseif ($id = $helper->getCategoryId (end($segments) ,$helper->activeMenu->virtuemart_category_id )) {
this code
if ($id === $helper->activeMenu->virtuemart_category_id)  JError::raise(E_ERROR,'404','Not found');
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: PRO on July 25, 2015, 12:10:20 PM
take that menu link and put it in a hidden menu


THEN: redo the home menu link to the same frontpage


Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: sandstorm on July 25, 2015, 12:43:40 PM
@studio42, I will check the router code in a while and add that line you suggested to see what happens.

@PRO - I'm not your suggestion will change anything.
This problem is happening on all pages where there is a virtuemart menu link - Frontpage, category, even orders - http://winestore.co.uk/my-orders/list
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: Studio 42 on July 25, 2015, 12:46:03 PM
Hi pro,
I think is a bug in the router, when a child category is not found then no redirect is set. this mean you have never a 404 except when you use the product prefix, because in this case the view set a 404(because product id is set to empty by router).
On category view, this fallback to menu category id and in all case category 0 is valid in this view.
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: sandstorm on July 25, 2015, 23:41:06 PM
Thanks for your time in helping with this studio42 - really appreciated  ;)

I added the line of code you suggested into router.php in the site winestore.co.uk & it now read like this for me;

} elseif ($id = $helper->getCategoryId (end($segments) ,$helper->activeMenu->virtuemart_category_id )) {

if ($id === $helper->activeMenu->virtuemart_category_id)  JError::raise(E_ERROR,'404','Not found');


404 pages now show for all parent level menu virtuemart links, but where I have 2nd or 3rd level links. The original problem of 404's redirecting to the same page happens.

So  http://winestore.co.uk/wine-santaclauss now produces a 404 page

But  http://winestore.co.uk/wine/santaclauss still just refreshes the page
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: Studio 42 on July 27, 2015, 12:37:00 PM
HI,
Remove the 1st change i posted and apply the change line 833 :
after :
if (!$catIds[$hash] = $db->loadResult()) {
add :
JError::raise(E_ERROR,'404','Not found');

Possible this do a problem in other case, please test, but by logic, this must only prevent missing category_id.
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: sandstorm on July 28, 2015, 21:01:11 PM
Thanks again Studio42  :D
I revert the change as advised and went with the new change.
So around line 833 for me now looks like this;
if (!$catIds[$hash] = $db->loadResult()) {
JError::raise(E_ERROR,'404','Not found');
$catIds[$hash] = $virtuemart_category_id;
}


This helps a bit further for lower level links, but it still doesn't solve the initial problem, which is when I have my main/default home menu link as VM Frontpage.
When I use VM frontpage as my main/default home page link, all incorrect URL's that should show my 404 page, just redirect to the home page.

This is also present when i put the site in offline mode, this is ignored and redirects to the home page.

In Vm Config I have disabled "VM handle 404 errors" as for me personally I do not want Virtuemart to handle my 404's.
I want to see 404's and fix them or redirect them when they show.

Currently testing VM3.0.10 on a copy site and the same problem occurs there too.

Any other ideas greatly appreciated.
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: Studio 42 on July 28, 2015, 21:13:27 PM
Perhaps you have set other redirections in your htaccess?
Wen i look in the firebug console on a 404 page :
http://winestore.co.uk/wine/store/ >error 303(see other = redirect)
http://winestore.co.uk/index.php > 200
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: sandstorm on July 28, 2015, 21:38:49 PM
.htaccess above the root only has;
AddHandler application/x-httpd-php56 .php .php5 .php4 .php3

& the .htaccess in root folder is the default htaccess.txt renamed to .htaccess

?? I'm lost now then ??
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: sandstorm on July 30, 2015, 23:26:38 PM
Quote from: Studio 42 on July 27, 2015, 12:37:00 PM
Remove the 1st change i posted and apply the change line 833 :
after :
if (!$catIds[$hash] = $db->loadResult()) {
add :
JError::raise(E_ERROR,'404','Not found');

Just a note that this change causes lots of other problems. Clicking onto any product redirects your to the catgeory or home page & you cant seem to view any products using this.
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: PRO on August 01, 2015, 15:11:35 PM
sandstorm,

are you trying to solve a problem that does not occur naturally?

How are you getting 404s?

Are you trying to get them? or are you getting them naturally?
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: sandstorm on August 01, 2015, 15:21:54 PM
I'm not sure if there is a router problem somewhere in my own site.
Had a chat with Max Milbers about is & another dev is taking a look this afternoon.

My problem is that when i set the home pagemenu link to "VM frontpage" and page that would normally have a 404, just redirect to the home page, even though I have VM 404 switched off?

I want to display 404's as we want to have these recorded in the redirect manager so we can deal with them or fix them - This is a new virtuemart store, replacing an old site.

I'll post back here if/when we solve this issue
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: Studio 42 on August 01, 2015, 21:01:52 PM
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
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: claesbas on November 24, 2016, 14:41:27 PM
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
Title: Re: Virtuemart Frontpage menu link, causes 404s to redirect to home page.
Post by: sandstorm on November 24, 2016, 14:48:27 PM
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