Magento Fehler

When using the Magento extension "Improved Navigation" from Amasty, the following error can occur: If the filters are integrated on a CMS page (e.g. as an entry point on the homepage), selecting a filter leads to the subpage "/shopby" with the respective option as a URL parameter. However, the controller does not recognize any involvement of the Amasty extension there and attempts to display a CMS page. After some research, it turns out that Amasty unnecessarily changes the URL "/shopby" to "/s", which cannot then be mapped correctly—the result is the display of the 404 page.

 

 This is caused by changes to the URL in the class "Amasty_Shopby_Helper_Url" (defined in \app\code\local\Amasty\Shopby\Helper\Url.php). In the function "checkRemoveSuffix($url)", which is actually only supposed to remove a potentially existing suffix (e.g. ".html"), a validation function fails. The return value of the PHP function

substr_compare($url, $suffix, -$l),

which is compared with "0" here, is incorrect when the optional fourth parameter $length, which specifies the number of characters to compare, is missing. This value is also "0" when the strings being compared are not identical, causing the previously correct URL to be incorrectly modified because characters are removed based on the length of the suffix specified in the backend. Since ".html" had a length of 5 characters in our case, the last 5 characters of the URL were therefore removed, turning "/shopby" into "/s" by removing "hopby".

 

Our agency then asked ourselves the question: "Why?" After further research, we came across two PHP bug reports:

 

https://bugs.php.net/bug.php?id=67069&edit=1 and

https://bugs.php.net/bug.php?id=67043,

 

which reported irregularities in the substr_compare function in PHP version 5.5.11. And as luck would have it, our local server was running PHP 5.5.11. To rule out any other possible sources of the error, we changed the following line in the Magento extension (filename as mentioned above):

 

substr_compare($url, $suffix, -$l)

to

substr_compare($url, $suffix, -$l, $l)

 

This resolved the problem, and the Magento shop was once again able to display the correct page under "/shopby". Tested with Magento CE 1.9.