Skip to content

Instantly share code, notes, and snippets.

@veganista
Created October 3, 2016 08:30
Show Gist options
  • Save veganista/770d5cdb2259daf13ddf78e101a06945 to your computer and use it in GitHub Desktop.
Save veganista/770d5cdb2259daf13ddf78e101a06945 to your computer and use it in GitHub Desktop.
Laravel Valet Driver - OpenCart 2.x
<?php
class OpenCartValetDriver extends ValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri)
{
if (file_exists($sitePath.'/system/engine/action.php')) {
return true;
}
return false;
}
/**
* Determine if the incoming request is for a static file.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string|false
*/
public function isStaticFile($sitePath, $siteName, $uri)
{
if (file_exists($staticFilePath = $sitePath.$uri)) {
return $staticFilePath;
}
return false;
}
/**
* Get the fully resolved path to the application's front controller.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
* @return string
*/
public function frontControllerPath($sitePath, $siteName, $uri)
{
if ($uri != '' && $uri != '/' && ! strstr($uri, '&') && ! strstr($uri, '?') && ! strstr($uri, '.php') && ! strstr($uri, 'admin')) {
$_GET['_route_'] = ltrim($uri, '/');
} elseif (strstr($uri, 'admin')) {
return $sitePath . '/admin/index.php';
} else {
$parameters[0] = $_SERVER['QUERY_STRING'];
if (strstr($parameters[0], '&')) {
$parameters = explode('&', $parameters[0]);
}
$parameters = array_filter($parameters);
foreach ($parameters as $parameter) {
if (strstr($parameter, '=')) {
$parameter = explode('=', $parameter);
} else {
$parameter[0] = $parameter;
$parameter[1] = '';
}
$_GET[$parameter[0]] = $parameter[1];
}
}
return $sitePath . '/index.php';
}
}
@shiroamada
Copy link

How to make those product SEO url to work. e.g I have opencart.dev/iphone-x, it keep showing the homepage. It didn't go to product page.

@Azam53
Copy link

Azam53 commented Jan 5, 2018

Hello veganista,
Can you please tell me how to use this module in laravel since I am interested in connecting laravel and opencart please help me just elaborate waiting for your reply.

@veganista
Copy link
Author

@shiroamada What version of OpenCart are you working with. This appears to work for me.

@Azam53 You wouldn't use this to connect Laravel with OpenCart, this is for serving OpenCart stores using Valet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment