Skip to content

Instantly share code, notes, and snippets.

@torunar
Created June 4, 2020 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torunar/a5c1c8ede255955cc4fb3094c9cf442e to your computer and use it in GitHub Desktop.
Save torunar/a5c1c8ede255955cc4fb3094c9cf442e to your computer and use it in GitHub Desktop.
diff --git a/app/functions/smarty_plugins/block.hook.php b/app/functions/smarty_plugins/block.hook.php
index 2f0aaf9529..65004929dd 100644
--- a/app/functions/smarty_plugins/block.hook.php
+++ b/app/functions/smarty_plugins/block.hook.php
@@ -21,7 +21,7 @@ function smarty_block_hook($params, $content, &$smarty)
$hook_content = '';
$hook_name = 'thooks_' . $smarty->template_area;
- Registry::registerCache($hook_name, array('addons'), Registry::cacheLevel('static'));
+ Registry::registerCache($hook_name, ['addons'], Registry::cacheLevel(['static', 'storefront']));
$hooks = Registry::ifGet($hook_name, array());
if (!isset($hooks[$params['name']])) {
diff --git a/app/Tygh/Providers/StorefrontProvider.php b/app/Tygh/Providers/StorefrontProvider.php
index 29a9a5cb79..5b8d935ffb 100644
--- a/app/Tygh/Providers/StorefrontProvider.php
+++ b/app/Tygh/Providers/StorefrontProvider.php
@@ -24,6 +24,7 @@ use Tygh\Storefront\RelationsManager;
use Tygh\Storefront\Factory;
use Tygh\Storefront\Normalizer;
use Tygh\Storefront\Repository;
+use Tygh\Tygh;
class StorefrontProvider implements ServiceProviderInterface
{
@@ -49,6 +50,16 @@ class StorefrontProvider implements ServiceProviderInterface
$this->params = $request;
}
+ /**
+ * Gets current storefront.
+ *
+ * @return \Tygh\Storefront\Storefront
+ */
+ public static function getStorefront()
+ {
+ return Tygh::$app['storefront'];
+ }
+
/**
* @inheritdoc
*/
diff --git a/app/Tygh/Registry.php b/app/Tygh/Registry.php
index 508878db7f..f538076053 100644
--- a/app/Tygh/Registry.php
+++ b/app/Tygh/Registry.php
@@ -15,6 +15,7 @@
namespace Tygh;
use Tygh\Exceptions\DeveloperException;
+use Tygh\Providers\StorefrontProvider;
class Registry
{
@@ -545,6 +546,9 @@ class Registry
$key = date('z', TIME);
} elseif ($id == 'company') {
$key = fn_get_runtime_company_id();
+ } elseif ($id === 'storefront') {
+ $storefront = StorefrontProvider::getStorefront();
+ $key = $storefront->storefront_id;
} elseif ($id == 'locale') {
$key = (defined('CART_LOCALIZATION') ? (CART_LOCALIZATION . '_') : '')
. CART_LANGUAGE . '_' . CART_SECONDARY_CURRENCY;
diff --git a/app/Tygh/SmartyEngine/Core.php b/app/Tygh/SmartyEngine/Core.php
index 29f7fd24a2..fa3ab63b6b 100644
--- a/app/Tygh/SmartyEngine/Core.php
+++ b/app/Tygh/SmartyEngine/Core.php
@@ -145,17 +145,16 @@ class Core extends \Smarty
$this->theme = Themes::areaFactory($area, $company_id, $storefront_id);
if ($area == 'C') {
- Registry::registerCache('theme_dirs', array(), Registry::cacheLevel('static'));
+ Registry::registerCache('theme_dirs', [], Registry::cacheLevel(['static', 'storefront']));
$this->theme_dirs = Registry::ifGet('theme_dirs', array());
- $id = (int) $storefront_id;
- if (!isset($this->theme_dirs[$id])) {
+ if (!$this->theme_dirs) {
// all theme directories have to be fetched to use add-on templates from base theme
- $this->theme_dirs[$id] = $this->theme->getThemeDirs(Themes::USE_BASE);
+ $this->theme_dirs = $this->theme->getThemeDirs(Themes::USE_BASE);
Registry::set('theme_dirs', $this->theme_dirs);
}
// add template directories of the theme and the parent theme
- foreach ($this->theme_dirs[$id] as $theme_name => $path_info) {
+ foreach ($this->theme_dirs as $theme_name => $path_info) {
if ($theme_name != $this->theme->getThemeName()) {
$this->addTemplateDir($path_info[Themes::PATH_ABSOLUTE] . ltrim($area_type_suffix, "/") . $suffix);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment