From 3073f9a43cf7ecdaacc7a94227aeccbe3a2fa06b Mon Sep 17 00:00:00 2001 From: Etienne Roudeix Date: Wed, 3 Jul 2013 16:07:18 +0200 Subject: [PATCH] fix thelia diese problems --- core/lib/Thelia/Config/Resources/config.xml | 4 ++ .../Core/Template/Element/LoopResultRow.php | 2 +- .../Template/Smarty/Plugins/TheliaSyntax.php | 54 +++++++++++++++++++ .../Core/Template/Smarty/SmartyParser.php | 11 ++-- templates/smarty-sample/category.html | 3 +- 5 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaSyntax.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index c8d0ef53f..b163f1983 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -67,6 +67,10 @@ + + + + diff --git a/core/lib/Thelia/Core/Template/Element/LoopResultRow.php b/core/lib/Thelia/Core/Template/Element/LoopResultRow.php index 73d2f937a..3ac05fe5c 100755 --- a/core/lib/Thelia/Core/Template/Element/LoopResultRow.php +++ b/core/lib/Thelia/Core/Template/Element/LoopResultRow.php @@ -29,7 +29,7 @@ class LoopResultRow public function set($key, $value) { - $this->substitution[$key] = $value; + $this->substitution[$key] = $value === null ? '' : $value; } public function get($key) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaSyntax.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaSyntax.php new file mode 100644 index 000000000..9b508cf3e --- /dev/null +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/TheliaSyntax.php @@ -0,0 +1,54 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Core\Template\Smarty\Plugins; + +use Thelia\Core\Template\Smarty\SmartyPluginDescriptor; +use Thelia\Core\Template\Smarty\SmartyPluginInterface; + +/** + * Class TheliaSyntax + * @package Thelia\Core\Template\Smarty\Plugins + * + * @author Etienne Roudeix + */ +class TheliaSyntax implements SmartyPluginInterface +{ + public function dieseCancel($value, $diese) + { + if($value === null) { + return $diese; + } + + return $value; + } + + /** + * @return SmartyPluginDescriptor[] + */ + public function getPluginDescriptors() + { + return array( + new SmartyPluginDescriptor("modifier", "dieseCanceller", $this, "dieseCancel") + ); + } +} diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php index ac83bf57e..8e34a89ed 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php @@ -29,10 +29,11 @@ class SmartyParser extends Smarty implements ParserInterface protected $status = 200; /** - * @param \Symfony\Component\HttpFoundation\Request $request - * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher - * @param bool $template - * @param string $env Environment define for the kernel application. Used for the cache directory + * @param Request $request + * @param EventDispatcherInterface $dispatcher + * @param bool $template + * @param string $env + * @param bool $debug */ public function __construct(Request $request, EventDispatcherInterface $dispatcher, $template = false, $env = "prod", $debug = false) { @@ -78,7 +79,7 @@ class SmartyParser extends Smarty implements ParserInterface public function preThelia($tpl_source, \Smarty_Internal_Template $template) { $new_source = preg_replace('`{#([a-zA-Z][a-zA-Z0-9\-_]*)(.*)}`', '{\$$1$2}', $tpl_source); - $new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9\-_]*)`', '{\$$1|default:\'#$1\'}', $new_source); + $new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9\-_]*)`', '{\$$1|dieseCanceller:\'#$1\'}', $new_source); return $new_source; } diff --git a/templates/smarty-sample/category.html b/templates/smarty-sample/category.html index 8a0dc2dba..b99390cb6 100755 --- a/templates/smarty-sample/category.html +++ b/templates/smarty-sample/category.html @@ -19,10 +19,11 @@
{/loop*}

PRODUCTS

-{loop name="product" type="product" min_weight="2.5" max_weight="10"} +{loop name="product" type="product"}

PRODUCT : #REF / #TITLE

price : #PRICE €
promo price : #PROMO_PRICE €
is promo : #PROMO
+ is new : #NEW
weight : #WEIGHT
{/loop}