diff --git a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php index 33f6a5b3d..5974ef3db 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php +++ b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php @@ -12,6 +12,7 @@ namespace Thelia\Core\Template\Smarty\Assets; +use Thelia\Log\Tlog; use Thelia\Tools\URL; use Thelia\Core\Template\Assets\AssetManagerInterface; @@ -108,6 +109,27 @@ class SmartyAssetsManager $templateDirectories = $smartyParser->getTemplateDirectories($templateDefinition->getType()); + // if it's not a custom template and looking for a different origin (e.g. module) + // we first check if the asset is present in the default "source" (template) + // if not we take the default asset from the assetOrigin (module) + if (! $webAssetTemplate && $assetOrigin !== "0") { + if (isset($templateDirectories[$templateDefinition->getName()]["0"])) { + if (file_exists($templateDirectories[$templateDefinition->getName()]["0"] . DS . $file)) { + // the file exists, we take the default origin + $assetOrigin = "0"; + } + } + } + + if (! isset($templateDirectories[$templateDefinition->getName()][$assetOrigin])) { + // we try with the default origin + if (! $webAssetTemplate && $assetOrigin !== "0") { + $assetOrigin = "0"; + } else { + throw new \Exception("Failed to get real path of '/".dirname($file)."'"); + } + } + if (! isset($templateDirectories[$templateDefinition->getName()][$assetOrigin])) { throw new \Exception("Failed to get real path of '/".dirname($file)."'"); } @@ -119,17 +141,21 @@ class SmartyAssetsManager $file = str_replace('/', DS, $file); } - $url = $this->assetsManager->processAsset( - $assetSource . DS . $file, - $assetSource . DS . self::$assetsDirectory, - $this->web_root . $this->path_relative_to_web_root, - $templateDefinition->getPath(), - $assetOrigin, - URL::getInstance()->absoluteUrl($this->path_relative_to_web_root, null, URL::PATH_TO_FILE /* path only */), - $assetType, - $filters, - $debug - ); + $url = ""; + // test if file exists before running the process + if (file_exists($assetSource . DS . $file)) { + $url = $this->assetsManager->processAsset( + $assetSource . DS . $file, + $assetSource . DS . self::$assetsDirectory, + $this->web_root . $this->path_relative_to_web_root, + $templateDefinition->getPath(), + $assetOrigin, + URL::getInstance()->absoluteUrl($this->path_relative_to_web_root, null, URL::PATH_TO_FILE /* path only */), + $assetType, + $filters, + $debug + ); + } return $url; } @@ -138,10 +164,13 @@ class SmartyAssetsManager { // Opening tag (first call only) if ($repeat) { - $url = $this->computeAssetUrl($assetType, $params, $template); - + $url = ""; + try { + $url = $this->computeAssetUrl($assetType, $params, $template); + } catch (\Exception $ex) { + Tlog::getInstance()->addWarning("Failed to get real path of " . $params['file']); + } $template->assign('asset_url', $url); - } elseif (isset($content)) { return $content; } diff --git a/local/modules/Front/Controller/OrderController.php b/local/modules/Front/Controller/OrderController.php index 5067af316..2c6f3072e 100644 --- a/local/modules/Front/Controller/OrderController.php +++ b/local/modules/Front/Controller/OrderController.php @@ -22,6 +22,7 @@ /*************************************************************************************/ namespace Front\Controller; +use Front\Front; use Propel\Runtime\Exception\PropelException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Thelia\Cart\CartTrait;