From bb43a12fba59efe11eb6417a7f028f5d17df16db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chans=C3=A9aume?= Date: Tue, 6 May 2014 09:23:38 +0200 Subject: [PATCH 1/2] Some tweaks added. We can now override module assets by redefining them in the template. if they are not in the template, it takes them from the module. if an asset does not exist, exception is catched and it no longer breaks the response. --- .../Smarty/Assets/SmartyAssetsManager.php | 57 ++++++++++++++----- 1 file changed, 43 insertions(+), 14 deletions(-) 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; } From dad74ba29023731c061fedcdef3343315b7d2ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Chans=C3=A9aume?= Date: Tue, 6 May 2014 09:32:59 +0200 Subject: [PATCH 2/2] added missing dependency --- local/modules/Front/Controller/OrderController.php | 1 + 1 file changed, 1 insertion(+) 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;