Skip to content

Commit

Permalink
Merge pull request #386 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Release 5.1.1
  • Loading branch information
Progi1984 authored Apr 8, 2022
2 parents c33ba8e + 363ed4d commit 7ec28ec
Show file tree
Hide file tree
Showing 25 changed files with 506 additions and 1,063 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ Connect with your visitors and reassure them about secure payment, free shipping
## Multistore compatibility

This module is compatible with the multistore :heavy_check_mark: <br/>
It can be configured differently from one store to another.<br/>
It can be configured quickly in the same way on all stores thanks to the all shops context or the group of shops.<br/>
It can be activated on one store and deactivated on another
The module can only specify if block reasassurance is displayed from one shop to another but the configuration is common to all shops.

## Reporting issues

Expand Down
4 changes: 2 additions & 2 deletions _dev/back/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $(window).ready(() => {
$('.listing-body').sortable({
update() {
const blocks = [];
$('.listing-general-rol').each(() => {
$('.listing-general-rol').each(function () {
blocks.push($(this).attr('data-block'));
});

Expand Down Expand Up @@ -170,7 +170,7 @@ $(window).ready(() => {

const landscape = $(`.panel-body-${id} .psr-picto`).attr('src');

if (typeof landscape === 'undefined') {
if (typeof landscape === 'undefined' || landscape === 'undefined') {
$('.psr-picto:visible').hide();
$('.svg_chosed_here:visible').hide();
$('.landscape').show();
Expand Down
46 changes: 30 additions & 16 deletions _dev/front/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,52 @@
import './front.scss';

$(window).ready(() => {
function styleSVG() {
const imgObject = $(this);
const imgID = imgObject.attr('id');
const imgClass = imgObject.attr('class');
const imgURL = imgObject.attr('src');
/**
* @param {String} imgSrc
*/
function styleSVG(imgSrc) {
const imgTarget = $(`.blockreassurance_product img.svg.invisible[src="${imgSrc}"], .blockreassurance img.svg.invisible[src="${imgSrc}"]`);

if (imgTarget.length === 0) {
return;
}

// Fetch the image
$.ajax({
url: imgURL,
url: imgSrc,
type: 'GET',
success(data) {
if ($.isXMLDoc(data)) {
// Get the SVG tag, ignore the rest
let $svg = $(data).find('svg');
// Add replaced image's ID to the new SVG
$svg = typeof imgID !== 'undefined' ? $svg.attr('id', imgID) : $svg;
// Add replaced image's classes to the new SVG
$svg = typeof imgClass !== 'undefined' ? $svg.attr('class', `${imgClass} replaced-svg`) : $svg.attr('class', ' replaced-svg');
$svg.removeClass('invisible');
// Add URL in data
$svg = $svg.attr('data-img-url', imgURL);
$svg = $svg.attr('data-img-url', imgSrc);
// Remove any invalid XML tags as per http://validator.w3.org
$svg = $svg.removeAttr('xmlns:a');
// Set color defined in backoffice
$svg.find('path[fill]').attr('fill', window.psr_icon_color);
$svg.find('path:not([fill])').css('fill', window.psr_icon_color);
// Replace image with new SVG
imgObject.replaceWith($svg);
// For each element, replace the svg with specific ID & CSS class
imgTarget.each(function () {
const imgID = $(this).attr('id');
const imgClass = $(this).attr('class');
let $imgSvg = $svg.clone();
// Add replaced image's ID to the new SVG
$imgSvg = typeof imgID !== 'undefined' ? $imgSvg.attr('id', imgID) : $imgSvg;
// Add replaced image's classes to the new SVG
$imgSvg = typeof imgClass !== 'undefined' ? $imgSvg.attr('class', `${imgClass} replaced-svg`) : $imgSvg.attr('class', ' replaced-svg');
$imgSvg.removeClass('invisible');
$(this).replaceWith($imgSvg);
});
}
imgObject.removeClass('invisible');
},
});
}

$('.blockreassurance_product img.svg, .blockreassurance img.svg').each(styleSVG);
const imgSrcSvg = $('.blockreassurance_product img.svg, .blockreassurance img.svg').map(function () {
return $(this).attr('src');
}).toArray();
imgSrcSvg
.filter((el, pos) => imgSrcSvg.indexOf(el) === pos)
.forEach(styleSVG);
});
32 changes: 14 additions & 18 deletions blockreassurance.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function __construct()
// Settings
$this->name = 'blockreassurance';
$this->tab = 'seo';
$this->version = '5.1.0';
$this->version = '5.1.1';
$this->author = 'PrestaShop';
$this->need_instance = false;

Expand Down Expand Up @@ -146,7 +146,6 @@ public function install()
`custom_icon` varchar(255) NULL,
`status` int(10) unsigned NOT NULL,
`position` int(10) unsigned NOT NULL,
`id_shop` int(10) unsigned NOT NULL,
`type_link` int(10) unsigned NULL,
`id_cms` int(10) unsigned NULL,
`date_add` datetime NOT NULL,
Expand All @@ -156,22 +155,21 @@ public function install()
$sqlQueries[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'psreassurance_lang` (
`id_psreassurance` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
`id_shop` int(10) unsigned NOT NULL,
`title` varchar(255) NOT NULL,
`description` varchar(255) NOT NULL,
`link` varchar(255) NOT NULL,
PRIMARY KEY (`id_psreassurance`,`id_shop`,`id_lang`)
PRIMARY KEY (`id_psreassurance`,`id_lang`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;';

$sqlQueries[] = 'INSERT INTO ' . _DB_PREFIX_ . 'psreassurance (icon, custom_icon, status, position, id_shop, type_link, id_cms, date_add) VALUES '
. "('" . $this->img_path . "reassurance/pack2/security.svg', null, 1, 1, 1, null, null, now()),"
. "('" . $this->img_path . "reassurance/pack2/carrier.svg', null, 1, 2, 1, null, null, now()),"
. "('" . $this->img_path . "reassurance/pack2/parcel.svg', null, 1, 3, 1, null, null, now())";
$sqlQueries[] = 'INSERT INTO ' . _DB_PREFIX_ . 'psreassurance (icon, custom_icon, status, position, type_link, id_cms, date_add) VALUES '
. "('" . $this->img_path . "reassurance/pack2/security.svg', null, 1, 1, null, null, now()),"
. "('" . $this->img_path . "reassurance/pack2/carrier.svg', null, 1, 2, null, null, now()),"
. "('" . $this->img_path . "reassurance/pack2/parcel.svg', null, 1, 3, null, null, now())";
foreach (Language::getLanguages(false) as $lang) {
$sqlQueries[] = 'INSERT INTO ' . _DB_PREFIX_ . 'psreassurance_lang (id_psreassurance, id_lang, id_shop, title, description, link) VALUES '
. '(1, ' . $lang['id_lang'] . ", 1, '" . $this->trans('Security policy', [], 'Modules.Blockreassurance.Shop', $lang['locale']) . "', '" . $this->trans('(edit with the Customer Reassurance module)', [], 'Modules.Blockreassurance.Shop', $lang['locale']) . "', ''),"
. '(2, ' . $lang['id_lang'] . ", 1, '" . $this->trans('Delivery policy', [], 'Modules.Blockreassurance.Shop', $lang['locale']) . "', '" . $this->trans('(edit with the Customer Reassurance module)', [], 'Modules.Blockreassurance.Shop', $lang['locale']) . "', ''),"
. '(3, ' . $lang['id_lang'] . ", 1, '" . $this->trans('Return policy', [], 'Modules.Blockreassurance.Shop', $lang['locale']) . "', '" . $this->trans('(edit with the Customer Reassurance module)', [], 'Modules.Blockreassurance.Shop', $lang['locale']) . "', '')";
$sqlQueries[] = 'INSERT INTO ' . _DB_PREFIX_ . 'psreassurance_lang (id_psreassurance, id_lang, title, description, link) VALUES '
. '(1, ' . $lang['id_lang'] . ", '" . $this->trans('Security policy', [], 'Modules.Blockreassurance.Shop', $lang['locale']) . "', '" . $this->trans('(edit with the Customer Reassurance module)', [], 'Modules.Blockreassurance.Shop', $lang['locale']) . "', ''),"
. '(2, ' . $lang['id_lang'] . ", '" . $this->trans('Delivery policy', [], 'Modules.Blockreassurance.Shop', $lang['locale']) . "', '" . $this->trans('(edit with the Customer Reassurance module)', [], 'Modules.Blockreassurance.Shop', $lang['locale']) . "', ''),"
. '(3, ' . $lang['id_lang'] . ", '" . $this->trans('Return policy', [], 'Modules.Blockreassurance.Shop', $lang['locale']) . "', '" . $this->trans('(edit with the Customer Reassurance module)', [], 'Modules.Blockreassurance.Shop', $lang['locale']) . "', '')";
}

foreach ($sqlQueries as $query) {
Expand Down Expand Up @@ -288,9 +286,8 @@ public function getContent()
'psr_text_color' => Configuration::get('PSR_TEXT_COLOR'),
'psr_icon_color' => Configuration::get('PSR_ICON_COLOR'),
'logo_path' => $this->logo_path,
'languages' => Language::getLanguages(),
'allblock' => ReassuranceActivity::getAllBlockByLang($id_lang, $this->context->shop->id),
'allblockByShop' => ReassuranceActivity::getAllBlockByShop(),
'languages' => Language::getLanguages(false),
'allblock' => ReassuranceActivity::getAllBlock(),
'currentPage' => $currentPage,
'moduleAdminLink' => $moduleAdminLink,
'img_path' => $this->img_path,
Expand Down Expand Up @@ -430,8 +427,7 @@ public function renderWidget($hookName = null, array $configuration = [])
public function getWidgetVariables($hookName = null, array $configuration = [])
{
$blocks = ReassuranceActivity::getAllBlockByStatus(
$this->context->language->id,
$this->context->shop->id
$this->context->language->id
);

$elements = [];
Expand Down Expand Up @@ -490,7 +486,7 @@ private function renderTemplateInHook($template)
$id_lang = $this->context->language->id;

$this->context->smarty->assign([
'blocks' => ReassuranceActivity::getAllBlockByStatus($id_lang, $this->context->shop->id),
'blocks' => ReassuranceActivity::getAllBlockByStatus($id_lang),
'iconColor' => Configuration::get('PSR_ICON_COLOR'),
'textColor' => Configuration::get('PSR_TEXT_COLOR'),
// constants
Expand Down
70 changes: 25 additions & 45 deletions classes/ReassuranceActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class ReassuranceActivity extends ObjectModel
public $description;
public $status;
public $position;
public $id_shop;
public $type_link;
public $link;
public $id_cms;
Expand All @@ -50,42 +49,22 @@ class ReassuranceActivity extends ObjectModel
'table' => 'psreassurance',
'primary' => 'id_psreassurance',
'multilang' => true,
'multilang_shop' => true,
'fields' => [
'icon' => ['type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isCleanHtml', 'size' => 255],
'custom_icon' => ['type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isCleanHtml', 'size' => 255],
'title' => ['type' => self::TYPE_STRING, 'shop' => true, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 255],
'description' => ['type' => self::TYPE_HTML, 'shop' => true, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 2000],
'status' => ['type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool', 'required' => true],
'position' => ['type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isunsignedInt', 'required' => false],
'type_link' => ['type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isunsignedInt', 'required' => false],
'id_cms' => ['type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isunsignedInt', 'required' => false],
'link' => ['type' => self::TYPE_STRING, 'shop' => true, 'lang' => true, 'validate' => 'isUrl', 'required' => false, 'size' => 255],
'date_add' => ['type' => self::TYPE_DATE, 'shop' => true, 'validate' => 'isDate'],
'date_upd' => ['type' => self::TYPE_DATE, 'shop' => true, 'validate' => 'isDate'],
'icon' => ['type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 255],
'custom_icon' => ['type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 255],
'status' => ['type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true],
'position' => ['type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => false],
'type_link' => ['type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => false],
'id_cms' => ['type' => self::TYPE_INT, 'validate' => 'isunsignedInt', 'required' => false],
'date_add' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
'date_upd' => ['type' => self::TYPE_DATE, 'validate' => 'isDate'],
// lang fields
'title' => ['type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 255],
'description' => ['type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml', 'size' => 2000],
'link' => ['type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isUrl', 'required' => false, 'size' => 255],
],
];

/**
* @param int $id_lang
* @param int $id_shop
*
* @return array
*
* @throws PrestaShopDatabaseException
*/
public static function getAllBlockByLang($id_lang = 1, $id_shop = 1)
{
$sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'psreassurance` pr
LEFT JOIN ' . _DB_PREFIX_ . 'psreassurance_lang prl ON (pr.id_psreassurance = prl.id_psreassurance)
WHERE prl.id_lang = "' . (int) $id_lang . '" AND prl.id_shop = "' . (int) $id_shop . '"
ORDER BY pr.position';

$result = Db::getInstance()->executeS($sql);

return $result;
}

/**
* @param array $psr_languages
* @param int $type_link
Expand Down Expand Up @@ -139,55 +118,56 @@ public function handleBlockValues($psr_languages, $type_link, $id_cms)
}

/**
* @param int $id_shop
*
* @return array
*
* @throws PrestaShopDatabaseException
*/
public static function getAllBlockByShop($id_shop = 1)
public static function getAllBlock()
{
$result = [];

$sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'psreassurance` pr
LEFT JOIN ' . _DB_PREFIX_ . 'psreassurance_lang prl ON (pr.id_psreassurance = prl.id_psreassurance)
WHERE prl.id_shop = "' . (int) $id_shop . '"
GROUP BY prl.id_lang, pr.id_psreassurance
ORDER BY pr.position';

$dbResult = Db::getInstance()->executeS($sql);

foreach ($dbResult as $key => $value) {
$result[$value['id_lang']][$value['id_psreassurance']]['title'] = $value['title'];
$result[$value['id_lang']][$value['id_psreassurance']]['description'] = $value['description'];
$result[$value['id_lang']][$value['id_psreassurance']]['url'] = $value['link'];
if (!isset($result[$value['id_psreassurance']])) {
$result[$value['id_psreassurance']] = $value;
$result[$value['id_psreassurance']]['title'] = [];
$result[$value['id_psreassurance']]['description'] = [];
$result[$value['id_psreassurance']]['url'] = [];
}
$result[$value['id_psreassurance']]['title'][$value['id_lang']] = $value['title'];
$result[$value['id_psreassurance']]['description'][$value['id_lang']] = $value['description'];
$result[$value['id_psreassurance']]['url'][$value['id_lang']] = $value['link'];
}

return $result;
}

/**
* @param int $id_lang
* @param int $id_shop
*
* @return array
*
* @throws PrestaShopDatabaseException
*/
public static function getAllBlockByStatus($id_lang = 1, $id_shop = 1)
public static function getAllBlockByStatus($id_lang = 1)
{
$sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'psreassurance` pr
LEFT JOIN ' . _DB_PREFIX_ . 'psreassurance_lang prl ON (pr.id_psreassurance = prl.id_psreassurance)
WHERE prl.id_lang = "' . (int) $id_lang . '"
AND prl.id_shop = "' . (int) $id_shop . '"
AND pr.status = 1
ORDER BY pr.position';

$result = Db::getInstance()->executeS($sql);

$xmlMimes = ['image/svg', 'image/svg+xml'];
foreach ($result as &$item) {
$item['is_svg'] = !empty($item['custom_icon'])
&& (self::getMimeType(str_replace(__PS_BASE_URI__, _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR, $item['custom_icon'])) == 'image/svg');
&& (in_array(self::getMimeType(_PS_ROOT_DIR_ . $item['custom_icon']), $xmlMimes));
}

return $result;
Expand Down
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
}
],
"require": {
"php": ">=5.6.0",
"doctrine/cache": "^1.6",
"symfony/css-selector": "^3.4 || ^4.4 || ^5.0",
"guzzlehttp/cache-subscriber": "^0.2.0"
"php": ">=5.6.0"
},
"require-dev": {
"prestashop/php-dev-tools": "^3.4"
Expand Down
Loading

0 comments on commit 7ec28ec

Please sign in to comment.