News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

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

sandstorm

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

J3.6.4 / PHP7.0.12
VM3.0.16

Studio 42

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.

sandstorm

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. ???
J3.6.4 / PHP7.0.12
VM3.0.16

Studio 42

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');

PRO

take that menu link and put it in a hidden menu


THEN: redo the home menu link to the same frontpage



sandstorm

@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
J3.6.4 / PHP7.0.12
VM3.0.16

Studio 42

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.

sandstorm

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
J3.6.4 / PHP7.0.12
VM3.0.16

Studio 42

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.

sandstorm

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.
J3.6.4 / PHP7.0.12
VM3.0.16

Studio 42

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

sandstorm

.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 ??
J3.6.4 / PHP7.0.12
VM3.0.16

sandstorm

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.
J3.6.4 / PHP7.0.12
VM3.0.16

PRO

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?

sandstorm

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
J3.6.4 / PHP7.0.12
VM3.0.16