MacOS 404 error when Ajax fastcart fails to handle redirect correctly.

Behaviour:
Some browsers (most notably on MacOS) seem to drop Ajax calls that should be appearing in the fastcart pop-over and pass them to a new tab or the parent window resulting in the end-user getting a 404.

This seems to happen when the cart has returned an error such as “insufficient stock for that product” or similar.

Other OS’s and browsers seem to work fine but MacOS doesn’t for some reason.

Fix:

Open: lib/class.redirects.php

Find:

public static function checkRedirect($urlPath)
{
	// @codeCoverageIgnoreStart
	$newUrl = self::generateRedirectUrl($urlPath);

	if (!$newUrl) {

After, Insert:

	//MOD: Catch fastcart 404 and redirect
	/*
	* The calls are supposed to be Ajax but sometimes are treated as non-ajax calls so this
	* catches and redirects them as non-fastcart calls in the same way as they are handled
	* in common.js
	*/
	$fastCartLessUrl = preg_replace('/&fastcart=1/','',$urlPath);
	if($fastCartLessUrl != $urlPath) {
		self::redirect($fastCartLessUrl);
	}
	//MOD END

Save and upload.

The function becomes:

public static function checkRedirect($urlPath)
{
	// @codeCoverageIgnoreStart
	$newUrl = self::generateRedirectUrl($urlPath);

	if (!$newUrl) {
		$fastCartLessUrl = preg_replace('/&fastcart=1/','',$urlPath);
		if($fastCartLessUrl != $urlPath) {
			self::redirect($fastCartLessUrl);
		}
		return false;
	}

	self::redirect($newUrl);
	// @codeCoverageIgnoreEnd
}

It’s not particularly elegant but it deals with the 404 and recreates what Common.js normally does when the Ajax call returns an error.

Leave a Reply

Your email address will not be published. Required fields are marked *