diff --git a/classes/prettyblocks/blocks/CategoryDescriptionBlock.php b/classes/prettyblocks/blocks/CategoryDescriptionBlock.php new file mode 100644 index 00000000..1a8e3260 --- /dev/null +++ b/classes/prettyblocks/blocks/CategoryDescriptionBlock.php @@ -0,0 +1,48 @@ + + * @copyright Since 2020 PrestaSafe and contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + * International Registered Trademark & Property of PrestaSafe + */ + +use PrestaSafe\PrettyBlocks\Interfaces\BlockInterface; + +class CategoryDescriptionBlock implements BlockInterface +{ + private $module; + + public function __construct($module) + { + $this->module = $module; + } + + public function registerBlocks(): array + { + return [ + 'name' => $this->module->l('Category description block'), + 'description' => $this->module->l('Render category description in a block'), + 'code' => 'prettyblocks_category_description', + 'tab' => 'product', + 'icon' => 'DocumentTextIcon', + 'need_reload' => false, + 'insert_default_values' => true, + 'templates' => [ + 'default' => 'module:' . $this->module->name . '/views/templates/blocks/category/category_description_block.tpl', + ], + ]; + } +} diff --git a/classes/prettyblocks/blocks/CmsContentBlock.php b/classes/prettyblocks/blocks/CmsContentBlock.php new file mode 100644 index 00000000..31924626 --- /dev/null +++ b/classes/prettyblocks/blocks/CmsContentBlock.php @@ -0,0 +1,48 @@ + + * @copyright Since 2020 PrestaSafe and contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + * International Registered Trademark & Property of PrestaSafe + */ + +use PrestaSafe\PrettyBlocks\Interfaces\BlockInterface; + +class CmsContentBlock implements BlockInterface +{ + private $module; + + public function __construct($module) + { + $this->module = $module; + } + + public function registerBlocks(): array + { + return [ + 'name' => $this->module->l('Cms content block'), + 'description' => $this->module->l('Render CMS description in a block'), + 'code' => 'prettyblocks_cms_content', + 'tab' => 'product', + 'icon' => 'DocumentTextIcon', + 'need_reload' => false, + 'insert_default_values' => true, + 'templates' => [ + 'default' => 'module:' . $this->module->name . '/views/templates/blocks/cms/cms_content_block.tpl', + ], + ]; + } +} diff --git a/classes/prettyblocks/blocks/ProductDescriptionBlock.php b/classes/prettyblocks/blocks/ProductDescriptionBlock.php index 65efd670..ff2a67cf 100644 --- a/classes/prettyblocks/blocks/ProductDescriptionBlock.php +++ b/classes/prettyblocks/blocks/ProductDescriptionBlock.php @@ -37,21 +37,12 @@ public function registerBlocks(): array 'description' => $this->module->l('Render product description in a block'), 'code' => 'prettyblocks_product_description', 'tab' => 'product', - 'icon' => 'CommandLineIcon', + 'icon' => 'DocumentTextIcon', 'need_reload' => false, 'insert_default_values' => true, 'templates' => [ 'default' => 'module:' . $this->module->name . '/views/templates/blocks/products/product_description_block.tpl', - ], - 'config' => [ - 'fields' => [ - 'code' => [ - 'type' => 'textarea', - 'label' => $this->module->l('Smarty code'), - 'default' => '', - ], - ], - ], + ] ]; } } diff --git a/classes/prettyblocks/blocks/ProductDescriptionShortBlock.php b/classes/prettyblocks/blocks/ProductDescriptionShortBlock.php index 67d01d10..a1815c8e 100644 --- a/classes/prettyblocks/blocks/ProductDescriptionShortBlock.php +++ b/classes/prettyblocks/blocks/ProductDescriptionShortBlock.php @@ -37,21 +37,12 @@ public function registerBlocks(): array 'description' => $this->module->l('Render product description short in a block'), 'code' => 'prettyblocks_product_description_short', 'tab' => 'product', - 'icon' => 'CommandLineIcon', + 'icon' => 'DocumentTextIcon', 'need_reload' => false, 'insert_default_values' => true, 'templates' => [ 'default' => 'module:' . $this->module->name . '/views/templates/blocks/products/product_description_short_block.tpl', - ], - 'config' => [ - 'fields' => [ - 'code' => [ - 'type' => 'textarea', - 'label' => $this->module->l('Smarty code'), - 'default' => '', - ], - ], - ], + ] ]; } } diff --git a/classes/prettyblocks/blocks/TinySlider.php b/classes/prettyblocks/blocks/TinySlider.php new file mode 100644 index 00000000..1f617507 --- /dev/null +++ b/classes/prettyblocks/blocks/TinySlider.php @@ -0,0 +1,48 @@ + + * @copyright Since 2020 PrestaSafe and contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + * International Registered Trademark & Property of PrestaSafe + */ + +use PrestaSafe\PrettyBlocks\Interfaces\BlockInterface; + +class TinySlider implements BlockInterface +{ + private $module; + + public function __construct($module) + { + $this->module = $module; + } + + public function registerBlocks(): array + { + return [ + 'name' => $this->module->l('Tiny Slider'), + 'description' => $this->module->l('Render a simple and nice slider'), + 'code' => 'prettyblocks_tiny_slider', + 'tab' => 'sliders', + 'icon' => 'RectangleStackIcon', + 'need_reload' => false, + 'insert_default_values' => true, + 'templates' => [ + 'default' => 'module:' . $this->module->name . '/views/templates/blocks/tinyslider/default.tpl', + ], + ]; + } +} diff --git a/prettyblocks.php b/prettyblocks.php index e170b522..3f7e7a70 100755 --- a/prettyblocks.php +++ b/prettyblocks.php @@ -270,6 +270,47 @@ private function _addDynamicZones() $this->context->smarty->assign('product', $product); } } + + if ($this->context->controller->php_self == 'category') { + // categories + if (isset($smartyVars['category'])) { + $category = $smartyVars['category']; + $zone_name = 'category_description_' . $smartyVars['category']['id']; + // si no blocks on this zone, feed product description + if (!HelperBuilder::zoneHasBlock($zone_name)) { + $this->registerBlockToZone($zone_name, 'prettyblocks_category_description'); + } + $description = $this->renderZone( + [ + 'zone_name' => $zone_name, + 'priority' => true, + 'alias' => 'Description catégorie', + ] + ); + $category['description'] = $description; + $this->context->smarty->assign('category', $category); + } + } + // cms + if ($this->context->controller->php_self == 'cms') { + if (isset($smartyVars['cms'])) { + $cms = $smartyVars['cms']; + $zone_name = 'cms_description_' . $smartyVars['cms']['id']; + // si no blocks on this zone, feed product description + if (!HelperBuilder::zoneHasBlock($zone_name)) { + $this->registerBlockToZone($zone_name, 'prettyblocks_cms_content'); + } + $description = $this->renderZone( + [ + 'zone_name' => $zone_name, + 'priority' => true, + 'alias' => 'Description CMS', + ] + ); + $cms['content'] = $description; + $this->context->smarty->assign('cms', $cms); + } + } } public function hookdisplayHeader($params) @@ -416,10 +457,14 @@ public function hookActionRegisterThemeSettings() */ public function hookActionRegisterBlock($params) { - return HelperBuilder::renderBlocks([ - // new SmartyRender($this), + $defaultsBlocks = [ new ProductDescriptionBlock($this), new ProductDescriptionShortBlock($this), - ]); + new CmsContentBlock($this), + new CategoryDescriptionBlock($this), + ]; + // https://preview.keenthemes.com/html/keen/docs/general/tiny-slider/overview + $defaultsBlocks[] = new TinySlider($this); + return HelperBuilder::renderBlocks($defaultsBlocks); } } diff --git a/views/templates/blocks/category/category_description_block.tpl b/views/templates/blocks/category/category_description_block.tpl new file mode 100644 index 00000000..e1c78f67 --- /dev/null +++ b/views/templates/blocks/category/category_description_block.tpl @@ -0,0 +1,3 @@ +{if isset($category) && isset($category.description)} + {$category.description nofilter} +{/if} diff --git a/views/templates/blocks/cms/cms_content_block.tpl b/views/templates/blocks/cms/cms_content_block.tpl new file mode 100644 index 00000000..b13945ec --- /dev/null +++ b/views/templates/blocks/cms/cms_content_block.tpl @@ -0,0 +1,3 @@ +{if isset($cms) && isset($cms.content)} + {$cms.content nofilter} +{/if} diff --git a/views/templates/blocks/tinyslider/default.tpl b/views/templates/blocks/tinyslider/default.tpl new file mode 100644 index 00000000..8e95b643 --- /dev/null +++ b/views/templates/blocks/tinyslider/default.tpl @@ -0,0 +1 @@ +Helloo slider \ No newline at end of file