Joomla 3.9.0 System Redirect stoped working with Hikashop

  • Posts: 228
  • Thank you received: 21
  • Hikashop Business Hikashop Essential
5 years 4 months ago #300475

-- HikaShop version -- : 4.0.0
-- Joomla version -- : 3.9.0
-- PHP version -- : 5.6.38
-- Browser(s) name and version -- : any

For years across multiple sites we've used the Joomla Redirect plugin when products have been renamed (new alias or canonical URL) or moved to an new category.

We have plenty of history with this working just fine but have noticed just recently with Joomla 3.9.0 that all our old directs related to HikaShop URLs and any new ones we try to create not working.

It just takes them to the same old, defunct URL and displays a no product found results or worse in some cases, no message at all.

I've tested this with both 4.0 and older version including back to HikaShop 3.4.0 (patched) across different sites.
It is as if the redirect entries don't exists.

Other Joomla article and non-hikashop redirects work just fine still within the Joomla Redirect plugin, just not HikaShop.

I can force it with .htaccess redirects, but that is cumbersome to maintain and manage.

Has something changed with the Joomla Redirect plugin that we need to adjust for in HikaShop with Joomla 3.9.0?

Last edit: 5 years 4 months ago by jazzmang.

Please Log in or Create an account to join the conversation.

  • Posts: 4486
  • Thank you received: 609
  • MODERATOR
5 years 4 months ago #300500

Hello,

From our side everything is still working, so in order to better get the root issue, we will need to process ourselves some tests, in this idea can you provide :

- An url link with the issue
- A step by step process to reproduce your issue

Awaiting news from you.
Regards

Last edit: 5 years 4 months ago by Philip.

Please Log in or Create an account to join the conversation.

  • Posts: 228
  • Thank you received: 21
  • Hikashop Business Hikashop Essential
5 years 4 months ago #300523

Correct URL:
www.classicbilliards.net/antique-parts-a...readed-receiver.html

Old URL which has a Joomla Redirect set to point to the above new URL:
www.classicbilliards.net/antique-parts-a...m-threaded-stud.html

All that changed in the URL was stud to receiver, everything else remained the same on the product.

Pretty simple & straight forward setup. See attached screen shot of the entry in Joomla's Redirect component administrator area.

As you can see by the dates, this particularly entry (and there are dozens of others like it) exited for several months and was working.

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 81361
  • Thank you received: 13035
  • MODERATOR
5 years 4 months ago #300564

Hi,

I checked how the redirect plugin works and as far as I can see, it catches 404 errors so that it can redirect to the new URL.
And it has been like that for a while if not always.

Now, at the beginning of the "product/show.php" file of HikaShop you have this code:

if(empty($this->element)) {
	if($this->config->get('404_when_product_not_found',1)){
		header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found", true, 404);
		$app = JFactory::getApplication();
		$app->enqueueMessage(JText::_('PRODUCT_NOT_FOUND'), 'error');
		echo '</div>';
		return;
	}
	$app->enqueueMessage(JText::_('PRODUCT_NOT_FOUND'));
	hikashop_setPageTitle(JText::_('PRODUCT_NOT_FOUND'));
	echo '</div>';
	return;
}

So what this code does is that when it can't load the product for the product page (because the alias changed, like in your example), it will send a 404 error and display the "product not found" error.
I see that this is still the case on your link:
monosnap.com/file/wX8lN8lUW9iBius1l41hAK3HA8r7qT
However, with HikaShop 4, we've changed that code.
Before that code was:
if(empty($this->element)) {
	if($this->config->get('404_when_product_not_found',1)){
		//header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
		JError::raiseError(404, JText::_('PRODUCT_NOT_FOUND'));
		echo '</div>';
		return;
	}
	$app->enqueueMessage(JText::_('PRODUCT_NOT_FOUND'));
	hikashop_setPageTitle(JText::_('PRODUCT_NOT_FOUND'));
	echo '</div>';
	return;
}
As you can see, it was using JError::raiseError while now we directly use the header() function of PHP.
We did that change because with Joomla 4, we can't use JError::raiseError anymore as this has been completely removed.
I think that's why the redirect doesn't work anymore.
So try to change the code:
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found", true, 404);
		$app = JFactory::getApplication();
		$app->enqueueMessage(JText::_('PRODUCT_NOT_FOUND'), 'error');
to:
throw new Exception(JText::_('PRODUCT_NOT_FOUND'), 404);
That should make it work like it did before.
Let us know how it goes so that we can include the patch for the next version of HikaShop.

Please Log in or Create an account to join the conversation.

  • Posts: 228
  • Thank you received: 21
  • Hikashop Business Hikashop Essential
5 years 3 months ago #301018

Almost there.

I made the change and the URL does redirect correctly but still displays the error message:

Product not found or no longer available

See attached screen shot.

People are still going to think the product no longer exists in most cases.

If you refresh, the error goes away but ideally you don't want that message on redirect.

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 81361
  • Thank you received: 13035
  • MODERATOR
5 years 3 months ago #301022

Hi,

Are you sure that you did the change as I proposed ?
From what you're describing, it looks like you only changed the line

header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found", true, 404);
and kept the code
$app = JFactory::getApplication();
		$app->enqueueMessage(JText::_('PRODUCT_NOT_FOUND'), 'error');
instead of replacing all three lines by the new
throw new Exception(JText::_('PRODUCT_NOT_FOUND'), 404);

Please Log in or Create an account to join the conversation.

  • Posts: 228
  • Thank you received: 21
  • Hikashop Business Hikashop Essential
5 years 3 months ago #301068

I screwed up my commenting out of those other 2 lines.

Fixed and seems to be working as intended on this site now.

The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

Time to create page: 0.070 seconds
Powered by Kunena Forum