Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion classes/prettyblocks/core/PrettyBlocksField.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,13 @@ private function formatFieldSelect()
*/
private function formatFieldMultiselectForFront()
{
return $this->formatFieldMultiselect();
if (is_array($this->value)) {
return $this->value;
}
// if value doesn't exists in DB and new value is not set return default value
if ($this->force_default_value && isset($this->field['default'])) {
return $this->field['default'];
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions controllers/front/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ private function isAjax()
*/
public function displayAjaxinsertBlock()
{
$this->module->clearCache('*');
$code = pSQL(Tools::getValue('code'));
$zone_name = pSQL(Tools::getValue('zone_name'));
$id_lang = (int) Tools::getValue('ctx_id_lang');
Expand Down Expand Up @@ -150,6 +151,7 @@ public function displayAjaxremoveSubState()
// remove element
public function displayAjaxremoveState()
{
$this->module->clearCache('*');
$id_prettyblocks = (int) Tools::getValue('id_prettyblocks');
$block = new PrettyBlocksModel($id_prettyblocks);
if ($block->delete()) {
Expand Down Expand Up @@ -283,6 +285,7 @@ public function displayAjaxGetStates()

public function displayAjaxupdateBlockConfig()
{
$this->module->clearCache('*');
$id_block = (int) Tools::getValue('id_prettyblocks');
$id_lang = (int) Tools::getValue('ctx_id_lang');
$id_shop = (int) Tools::getValue('ctx_id_shop');
Expand Down
62 changes: 50 additions & 12 deletions prettyblocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ class PrettyBlocks extends Module implements WidgetInterface
'actionDispatcher',
'actionFrontControllerSetVariables',
'ActionRegisterThemeSettings',
'actionProductUpdate',
'actionProductDelete',
];

public function __construct()
{
$this->name = 'prettyblocks';
$this->tab = 'administration';
$this->version = '2.2.1';
$this->version = '2.3.0';
$this->author = 'PrestaSafe';
$this->need_instance = 1;
$this->js_path = $this->_path . 'views/js/';
Expand Down Expand Up @@ -201,6 +203,7 @@ public function getWidgetVariables($hookName = null, array $configuration = [])
public function renderWidget($hookName = null, array $configuration = [])
{
$vars = $this->getWidgetVariables($hookName, $configuration);

$this->smarty->assign($vars);
if (isset($configuration['zone_name'])) {
return $this->renderZone(['zone_name' => pSQL($configuration['zone_name'])]);
Expand Down Expand Up @@ -235,8 +238,8 @@ public function registerBlockToZone($zone_name, $block_code)
public function hookActionDispatcher()
{
/* @deprecated {magic_zone} is deprecated since v1.1.0. Use {prettyblocks_zone} instead. */
$this->context->smarty->registerPlugin('function', 'magic_zone', [PrettyBlocks::class, 'renderZone']);
$this->context->smarty->registerPlugin('function', 'prettyblocks_zone', [PrettyBlocks::class, 'renderZone']);
$this->context->smarty->registerPlugin('function', 'magic_zone', [PrettyBlocks::class, 'renderZoneStatic']);
$this->context->smarty->registerPlugin('function', 'prettyblocks_zone', [PrettyBlocks::class, 'renderZoneStatic']);
$this->context->smarty->registerPlugin('function', 'prettyblocks_title', [PrettyBlocks::class, 'renderTitle']);
}

Expand All @@ -260,27 +263,48 @@ public static function renderTitle($params)
return $title->setValueFromBlock(true)->setValue($value)->render();
}

public static function renderZone($params)
public function renderZone($params)
{
$zone_name = $params['zone_name'];

if (empty($zone_name)) {
return false;
}

$templateFile = 'module:prettyblocks/views/templates/front/zone.tpl';
$context = Context::getContext();
$id_lang = $context->language->id;
$id_shop = $context->shop->id;
$blocks = PrettyBlocksModel::getInstanceByZone($zone_name, 'front', $id_lang, $id_shop);
if (!$this->isCached($templateFile, $this->getCacheId($zone_name))) {
$id_lang = $context->language->id;
$id_shop = $context->shop->id;
$blocks = PrettyBlocksModel::getInstanceByZone($zone_name, 'front', $id_lang, $id_shop);

$context->smarty->assign([
'zone_name' => $zone_name,
'blocks' => $blocks,
]);
}

$context->smarty->assign([
'zone_name' => $zone_name,
'blocks' => $blocks,
]);
return $this->fetch($templateFile, $this->getCacheId($zone_name));
// return $context->smarty->fetch($templateFile, $this->getCacheId($zone_name));
}

return $context->smarty->fetch('module:prettyblocks/views/templates/front/zone.tpl');
public function renderZoneStatic($params)
{
$module = \Module::getInstanceByName('prettyblocks');

return $module->renderZone($params);
}

protected function getCacheId($name = null)
{
$cacheId = 'prettyblocks|' . parent::getCacheId($name);
/* if (!empty($this->context->customer->id)) {
$cacheId .= '|' . $this->context->customer->id;
} */

return $cacheId;
}

/**
* Hook for adding theme settings
* quick fix for adding tinyMCE api key.
Expand All @@ -297,4 +321,18 @@ public function hookActionRegisterThemeSettings()
],
];
}

public function hookActionProductUpdate($params)
{
$this->clearCache('*');
}

public function hookActionProductDelete($params)
{
$this->clearCache('*');
}

public function clearCache($var) {
$this->_clearCache($var);
}
}
37 changes: 37 additions & 0 deletions upgrade/upgrade-2.3.0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright (c) Since 2020 PrestaSafe and contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to contact@prestasafe.com so we can send you a copy immediately.
*
* @author PrestaSafe <contact@prestasafe.com>
* @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
*/
if (!defined('_PS_VERSION_')) {
exit;
}

/**
* @param prettyblocks $module
*
* @return bool|string
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
function upgrade_module_2_3_0($module)
{
$module->registerHook('actionProductUpdate');
$module->registerHook('actionProductDelete');
return true;
}