Files
drmaterac.pl/modules/phstickers/phstickers.php
2025-01-06 20:47:25 +01:00

793 lines
40 KiB
PHP

<?php
/**
* NOTICE OF LICENSE
*
* This file is licenced under the Software License Agreement.
* With the purchase or the installation of the software in your application
* you accept the licence agreement.
*
* You must not modify, adapt or create derivative works of this source code
*
* @author PrestaHelp.com
* @copyright 2020 PrestaHelp
* @license LICENSE.txt
*/
if (!defined('_PS_VERSION_')) {
exit;
}
require_once __DIR__.'/classes/AuthDSPhStickers.php';
require_once __DIR__.'/classes/Sticker.php';
require_once __DIR__.'/classes/StickerUpdate.php';
class phstickers extends Module
{
public function __construct()
{
$this->name = 'phstickers';
$this->tab = 'other';
$this->version = '1.0.8';
$this->author = 'PrestaHelp';
$this->need_instance = 1;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Stikers - naklejki na produkcie');
$this->description = $this->l('Możesz dodać naklejki do produktu');
$this->confirmUninstall = $this->l('Odinstalowanie modułu nie powoduje utraty żadnych danych.');
}
public function install()
{
if (!$this->setInst()) {
return false;
}
$this->setConfig();
$this->installSql();
if (!parent::install() ||
!$this->setNewHook() ||
!$this->registerHook('displayHeader') ||
!$this->registerHook('displayAdminProductsExtra') ||
!$this->registerHook('actionProductUpdate') ||
!$this->registerHook('displayProductStickers') ||
!$this->registerHook('displayProductListStickers')
) {
return false;
} else {
return true;
}
}
public function uninstall()
{
$this->uninstallSql();
if (!parent::uninstall()) {
return false;
}
return true;
}
private function setInst() {
$shop = new Shop($this->context->shop->id);
$auth = new AuthDSPhStickers();
if ($auth->makeTools($this->displayName, $this->version, $shop->getBaseURL())){
return true;
}
return false;
}
private function isActiveModule()
{
$shop = new Shop((int)$this->context->shop->id);
$auth = new AuthDSPhStickers($this->name);
$licence = $auth->isActive($shop->getBaseURL());
if (empty($licence)) {
$domain = AuthDSPhStickers::clearDomain($shop->getBaseURL());
$licence = $auth->getStaticLicence($domain, 'Stikers - naklejki na produkcie', Configuration::get('PHSTICKERS_LICENCE'));
}
return array(
'active' => $licence,
'actived' => $licence['licence']->licence
);
}
private function setConfig()
{
Configuration::updateValue('PHSTICKERS_PRODUCT_MAX', 4);
Configuration::updateValue('PHSTICKERS_PRODUCT_STICKER_WIDTH', 100);
Configuration::updateValue('PHSTICKERS_PRODUCT_STICKER_HEIGHT', 100);
Configuration::updateValue('PHSTICKERS_PRODUCTLIST_STICKER_WIDTH', 60);
Configuration::updateValue('PHSTICKERS_PRODUCTLIST_STICKER_HEIGHT', 60);
Configuration::updateValue('PHSTICKERS_HIDE_MOBILE', 0);
Configuration::updateValue('PHSTICKERS_PROMOTION_SHOW', 1);
Configuration::updateValue('PHSTICKERS_NEWPRODUCT_SHOW', 1);
Configuration::updateValue('PHSTICKERS_BESTSELLER_SHOW', 1);
}
private function installSql()
{
include_once __DIR__.'/sql/install.php';
}
private function uninstallSql()
{
include_once __DIR__.'/sql/uninstall.php';
}
private function setNewHook()
{
$issetHook = Hook::getIdByName('displayProductStickers');
$res = true;
if (empty($issetHook)) {
$hook = new Hook();
$hook->name = 'displayProductStickers';
$hook->title = 'displayProductStickers';
$hook->description = 'display Stickers in product';
$res &= $hook->add();
}
$issetHook2 = Hook::getIdByName('displayProductListStickers');
if (empty($issetHook2)) {
$hook2 = new Hook();
$hook2->name = 'displayProductListStickers';
$hook2->title = 'displayProductListStickers';
$hook2->description = 'display Stickers in product list';
$res &= $hook2->add();
}
return $res;
}
public function hookDisplayHeader()
{
$activeted = $this->isActiveModule();
if ($activeted['actived'] == 1) {
if (self::ps16()) {
$this->context->controller->addCSS(($this->_path) . 'views/css/phstickers.css', 'all');
$this->context->controller->addJS(($this->_path) . 'views/js/phstickers.js');
} else {
$this->context->controller->addCSS(($this->_path) . 'views/css/phstickers17.css', 'all');
$this->context->controller->addJS(_PS_ROOT_DIR_ . '/js/jquery/jquery-1.11.0.min.js');
$this->context->controller->addJS(($this->_path) . 'views/js/phstickers17.js');
}
}
}
public function getContent()
{
$activeted = $this->isActiveModule();
if ($activeted['actived'] == 1) {
$output = '';
$ssl = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
$stickerUpdate = new StickerUpdate();
$this->process($stickerUpdate);
if (Tools::getIsset('addSticker')) {
$languages = Language::getLanguages(true);
$this->context->smarty->assign(array(
'languages' => $languages,
'manufacturer' => Manufacturer::getManufacturers(false, (int)$this->context->cookie->id_lang),
'positions' => Sticker::$positions
));
$output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/add.tpl');
} else if (Tools::getIsset('editSticker')) {
$id_sticker = (int)Tools::getValue('editSticker');
$sticker = Sticker::getSticker((int)$id_sticker);
if (!empty($sticker)) {
$lng = array();
if (!empty($sticker['langs'])) {
foreach ($sticker['langs'] as $lang) {
$lng[$lang['id_lang']] = $lang;
}
}
$sticker['lng'] = $lng;
$sticker['stickerDir'] = $ssl . $this->context->shop->domain . $this->context->shop->physical_uri . '/modules/' . $this->name . '/stickers/';
}
$adminListDir = $this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=other&module_name=' . $this->name;
$languages = Language::getLanguages(true);
$this->context->smarty->assign(array(
'languages' => $languages,
'sticker' => $sticker,
'adminListDir' => $adminListDir,
'manufacturer' => Manufacturer::getManufacturers(false, (int)$this->context->cookie->id_lang),
'positions' => Sticker::$positions
));
$output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/edit.tpl');
} else if (Tools::getIsset('addCategorySticker')) {
$imageStickerDir = $ssl . $this->context->shop->domain . $this->context->shop->physical_uri . '/modules/' . $this->name . '/stickers/' . (int)$this->context->cookie->id_lang . '/';
$list = Sticker::getAllStickers((int)$this->context->cookie->id_lang);
$categories = new HelperTreeCategories('associated-categories-tree');
$categories->setUseCheckBox(1)->setUseSearch(1)->setSelectedCategories(array());
$helper_category_ceneo = $categories->render();
$this->context->smarty->assign(array(
'list' => $list,
'imageStickerDir' => $imageStickerDir,
'helper_category_ceneo' => $helper_category_ceneo,
'PHSTICKERS_PRODUCT_MAX' => Configuration::get('PHSTICKERS_PRODUCT_MAX'),
'positions' => Sticker::$positions
));
$output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/addCategory.tpl');
} else if (Tools::getIsset('editCategorySticker')) {
$id_sticker_category = (int)Tools::getValue('editCategorySticker');
$categorySticker = Sticker::getCategorySticker((int)$id_sticker_category);
$category_name = '';
if (!empty($categorySticker)) {
$category = new Category((int)$categorySticker['id_category'], (int)$this->context->cookie->id_lang);
$category_name = $category->name;
}
$list = Sticker::getAllStickers((int)$this->context->cookie->id_lang);
$imageStickerDir = $ssl . $this->context->shop->domain . $this->context->shop->physical_uri . '/modules/' . $this->name . '/stickers/' . (int)$this->context->cookie->id_lang . '/';
$stickers = array();
$positions = array();
$categoryStickers = Sticker::getCategoryStickers((int)$categorySticker['id_category']);
if (!empty($categoryStickers)) {
foreach ($categoryStickers as $c) {
$stickers[] = (int)$c['id_sticker'];
$positions[$c['id_sticker']] = $c['position'];
}
}
$this->context->smarty->assign(array(
'list' => $list,
'category_name' => $category_name,
'imageStickerDir' => $imageStickerDir,
'stickers' => $stickers,
'id_category' => (int)$categorySticker['id_category'],
'PHSTICKERS_PRODUCT_MAX' => Configuration::get('PHSTICKERS_PRODUCT_MAX'),
'positions' => Sticker::$positions,
'stickerPosition' => $positions
));
$output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/editCategory.tpl');
} else {
$this->context->controller->addCSS(__DIR__ . '/assets/css/phelp.css');
$updateModule = false;
$module = Module::getInstanceByName($this->name);
$mversion = $module->version;
/* prestahelp API - do not remove! */
$auth = new AuthDSPhStickers($this->name);
$productsShow = $auth->getBaners();
$authorInfo = $auth->getAuthor();
$chlogInfo = $auth->getChangelog();
$chlogInfoOther = $auth->getChangelogOther();
$currentVersion = $auth->getCurrentModuleVersion();
/* prestahelp API - do not remove! */
$phelpBtm = __DIR__ . '/views/templates/admin/phelp-bottom.tpl';
$phelpTop = __DIR__ . '/views/templates/admin/phelp-top.tpl';
$moduleAssets = $ssl . $this->context->shop->domain . $this->context->shop->physical_uri . 'modules/' . $this->name . '/assets/';
$lastestVersion = $currentVersion['version'] == $mversion ? true : false;
$updateLink = 'https://modules.prestahelp.com/moduly/' . $this->name . '/' . $this->name . $currentVersion['version'] . '.zip';
$indexLink = 'https://modules.prestahelp.com/moduly/' . $this->name . '/';
$banersHtml = AuthDSPhStickers::getBanersHtml();
$adminAddLink = $this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=other&module_name=' . $this->name . '&addSticker=1';
$adminAddCategoryLink = $this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=other&module_name=' . $this->name . '&addCategorySticker=1';
$adminEditLink = $this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=other&module_name=' . $this->name . '&editSticker=';
$adminDeleteLink = $this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=other&module_name=' . $this->name . '&deleteSticker=';
$adminEditCategoryLink = $this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=other&module_name=' . $this->name . '&editCategorySticker=';
$adminDeleteCategoryLink = $this->context->link->getAdminLink('AdminModules', true) . '&configure=' . $this->name . '&tab_module=other&module_name=' . $this->name . '&deleteCategorySticker=';
$stickerDir = $ssl . $this->context->shop->domain . $this->context->shop->physical_uri . 'modules/' . $this->name . '/stickers/' . (int)$this->context->cookie->id_lang . '/';
$stickerList = Sticker::getAllStickers((int)$this->context->cookie->id_lang);
$stickerCategoryList = Sticker::getAllCategorySticker();
if (!empty($stickerCategoryList)) {
foreach ($stickerCategoryList as &$s) {
$category = new Category((int)$s['id_category'], (int)$this->context->cookie->id_lang);
$s['category_name'] = $category->name;
$stickerCat = Sticker::getSticker((int)$s['id_sticker'], (int)$this->context->cookie->id_lang);
$s['file_name'] = $stickerCat['langs']['file_name'];
$pos = ' -- ';
if ($s['position'] > 0) {
$pos = Sticker::$positions[$s['position']];
}
$s['pos'] = $pos;
}
}
$ready1 = false;
$ready2 = false;
if (self::ps17()) {
$proTpl = file_get_contents(_PS_ALL_THEMES_DIR_ . $this->context->shop->theme_name . '/templates/catalog/_partials/product-cover-thumbnails.tpl');
$isset1 = mb_strpos($proTpl, "{hook h='displayProductStickers'}");
if ($isset1 > 0) {
$ready1 = true;
}
$proTpl2 = file_get_contents(_PS_ALL_THEMES_DIR_ . $this->context->shop->theme_name . '/templates/catalog/_partials/miniatures/product.tpl');
$isset2 = mb_strpos($proTpl2, "{hook h='displayProductListStickers'");
if ($isset2 > 0) {
$ready2 = true;
}
} else {
$proTpl = file_get_contents(_PS_ALL_THEMES_DIR_ . $this->context->shop->theme_name . '/product.tpl');
$isset1 = mb_strpos($proTpl, "{hook h='displayProductStickers'}");
if ($isset1 > 0) {
$ready1 = true;
}
$proTpl2 = file_get_contents(_PS_ALL_THEMES_DIR_ . $this->context->shop->theme_name . '/product-list.tpl');
$isset2 = mb_strpos($proTpl2, "{hook h='displayProductListStickers'");
if ($isset2 > 0) {
$ready2 = true;
}
}
$stickerUpdate->checkUpdate();
$this->context->smarty->assign(array(
'stickerList' => $stickerList,
'adminAddLink' => $adminAddLink,
'adminAddCategoryLink' => $adminAddCategoryLink,
'adminEditLink' => $adminEditLink,
'adminDeleteLink' => $adminDeleteLink,
'stickerDir' => $stickerDir,
'stickerCategoryList' => $stickerCategoryList,
'adminEditCategoryLink' => $adminEditCategoryLink,
'adminDeleteCategoryLink' => $adminDeleteCategoryLink,
'PHSTICKERS_PRODUCT_MAX' => Configuration::get('PHSTICKERS_PRODUCT_MAX'),
'PHSTICKERS_PRODUCT_STICKER_WIDTH' => Configuration::get('PHSTICKERS_PRODUCT_STICKER_WIDTH'),
'PHSTICKERS_PRODUCT_STICKER_HEIGHT' => Configuration::get('PHSTICKERS_PRODUCT_STICKER_HEIGHT'),
'PHSTICKERS_PRODUCTLIST_STICKER_WIDTH' => Configuration::get('PHSTICKERS_PRODUCTLIST_STICKER_WIDTH'),
'PHSTICKERS_PRODUCTLIST_STICKER_HEIGHT' => Configuration::get('PHSTICKERS_PRODUCTLIST_STICKER_HEIGHT'),
'PHSTICKERS_HIDE_MOBILE' => Configuration::get('PHSTICKERS_HIDE_MOBILE'),
'PHSTICKERS_PROMOTION_SHOW' => Configuration::get('PHSTICKERS_PROMOTION_SHOW'),
'PHSTICKERS_NEWPRODUCT_SHOW' => Configuration::get('PHSTICKERS_NEWPRODUCT_SHOW'),
'PHSTICKERS_BESTSELLER_SHOW' => Configuration::get('PHSTICKERS_BESTSELLER_SHOW'),
'moduleVersion' => $mversion,
'updateModule' => $updateModule,
'moduleAssets' => $moduleAssets,
'phelpBtm' => $phelpBtm,
'phelpTop' => $phelpTop,
'productsShow' => (array)$productsShow,
'authorInfo' => $authorInfo,
'chlogInfo' => $chlogInfo,
'moduleName' => $module->displayName,
'moduleNameInfo' => $module->name,
'currentModuleVersion' => $currentVersion['version'],
'lastestVersion' => $lastestVersion,
'updateLink' => $updateLink,
'chlogInfoOther' => $chlogInfoOther,
'indexLink' => $indexLink,
'banersHtml' => $banersHtml,
'psVersion' => _PS_VERSION_,
'themeName' => $this->context->shop->theme_name,
'ready1' => $ready1,
'ready2' => $ready2,
'update' => $stickerUpdate->update,
'updateList' => $stickerUpdate->updateList,
'updated_date' => date('d-m-Y', strtotime($activeted['active']['licence']->date_expire_update)),
'licence_update' => $activeted['active']['licence']->licence_update,
'support_date' =>date('d-m-Y', strtotime($activeted['active']['licence']->date_expire_support)),
'licence_date' => date('d-m-Y', strtotime($activeted['active']['licence']->date_expire)),
'activeted' => $activeted,
'licence' => $activeted['active']['licence'],
));
$output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/list.tpl');
}
} else {
$output = '';
$showLicence = 0;
// $this->postProcess();
$shop = new Shop((int)$this->context->shop->id);
$this->context->smarty->assign(array(
'moduleDomain' => $shop->getBaseURL(),
'modConf' => 0,
'licenceCode' => Configuration::get('PHSTICKERS_LICENCE'),
'licenceCodeGen' => Configuration::get('PHSTICKERS_LICENCE_GEN'),
'licGenData' => Configuration::get('PHSTICKERS_LICENCE_GEN_DATA'),
'showLicence' => $showLicence,
));
$output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/nolic.tpl');
}
return $output;
}
private function process($stickerUpdate)
{
$ssl = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
$psAdminDir = explode('/', _PS_ADMIN_DIR_);
$adminDir = end($psAdminDir);
if (self::ps16()) {
$adminLink = $ssl.$this->context->shop->domain.$this->context->shop->physical_uri.$adminDir.'/'.$this->context->link->getAdminLink('AdminModules', true).'&configure='.$this->name.'&tab_module=other&module_name='.$this->name;
} else {
$adminLink = $this->context->link->getAdminLink('AdminModules', true, array(), array('configure' => $this->name, 'tab_module' => 'other', 'module_name' => $this->name));
}
if (Tools::getIsset('submitAddProcess')) {
$files = Sticker::orderFiles($_FILES);
$priceOn = (int)Tools::getValue('price_on');
$priceMin = Tools::getValue('price_min');
$priceMax = Tools::getValue('price_max');
$qtyOn = (int)Tools::getValue('qty_on');
$qtyMin = (int)Tools::getValue('qty_min');
$qtyMax = (int)Tools::getValue('qty_max');
$manuOn = (int)Tools::getValue('manu_on');
$idManu = (int)Tools::getValue('id_manufacturer');
$posPrice = (int)Tools::getValue('position_price');
$posQty = (int)Tools::getValue('position_qty');
$posManu = (int)Tools::getValue('position_manu');
$posNew = (int)Tools::getValue('position_new');
$showNew = (int)Tools::getValue('show_new');
Sticker::addSticker($files, (int)$priceOn, $priceMin, $priceMax, (int)$posPrice, (int)$qtyOn, (int)$qtyMin, (int)$qtyMax, (int)$posQty, (int)$manuOn, (int)$idManu, (int)$posManu, (int)$showNew, (int)$posNew);
Tools::redirect($adminLink.'&conf=3');
}
if (Tools::getIsset('deleteSticker')) {
$id_sticker = (int)Tools::getValue('deleteSticker');
$delete = Sticker::deleteSticker((int)$id_sticker);
Tools::redirect($adminLink.($delete ? '&conf=1' : ''));
}
if (Tools::getIsset('submitEditProcess')) {
$id_sticker = (int)Tools::getValue('id_sticker');
$files = Sticker::orderFiles($_FILES);
$priceOn = (int)Tools::getValue('price_on');
$priceMin = Tools::getValue('price_min');
$priceMax = Tools::getValue('price_max');
$qtyOn = (int)Tools::getValue('qty_on');
$qtyMin = (int)Tools::getValue('qty_min');
$qtyMax = (int)Tools::getValue('qty_max');
$manuOn = (int)Tools::getValue('manu_on');
$idManu = (int)Tools::getValue('id_manufacturer');
$posPrice = (int)Tools::getValue('position_price');
$posQty = (int)Tools::getValue('position_qty');
$posManu = (int)Tools::getValue('position_manu');
$posNew = (int)Tools::getValue('position_new');
$showNew = (int)Tools::getValue('show_new');
Sticker::editSticker((int)$id_sticker, $files, (int)$priceOn, $priceMin, $priceMax, (int)$posPrice, (int)$qtyOn, (int)$qtyMin, (int)$qtyMax, (int)$posQty, (int)$manuOn, (int)$idManu, (int)$posManu, (int)$showNew, (int)$posNew);
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('submitAddCategoryProcess')) {
$stickers = Tools::getValue('stickers');
$categorys = Tools::getValue('categoryBox');
$positions = Tools::getValue('position');
Sticker::addCategorySticker($categorys, $stickers, $positions);
Tools::redirect($adminLink.'&conf=3');
}
if (Tools::getIsset('submitEditCategoryProcess')) {
$id_category = (int)Tools::getValue('id_category');
$stickers = Tools::getValue('stickers');
$positions = Tools::getValue('position');
Sticker::deleteCategoryStickers((int)$id_category);
Sticker::editStickersCategory((int)$id_category, $stickers, $positions);
Tools::redirect($adminLink.'&conf=4');
}
if (Tools::getIsset('deleteCategorySticker')) {
$id_sticker_category = (int)Tools::getValue('deleteCategorySticker');
$delete = Sticker::deleteCategorySticker((int)$id_sticker_category);
Tools::redirect($adminLink.($delete ? '&conf=1' : ''));
}
if (Tools::getIsset('deleteCategoryMass')) {
$items = Tools::getValue('deletItem');
if (!empty($items)) {
foreach ($items as $item) {
Sticker::deleteCategorySticker((int)$item);
}
}
Tools::redirect($adminLink.'&conf=1');
}
if (Tools::getIsset('submitSettingsProcess')) {
Configuration::updateValue('PHSTICKERS_PRODUCT_MAX', (int)Tools::getValue('PHSTICKERS_PRODUCT_MAX'));
Configuration::updateValue('PHSTICKERS_PRODUCT_STICKER_WIDTH', (int)Tools::getValue('PHSTICKERS_PRODUCT_STICKER_WIDTH'));
Configuration::updateValue('PHSTICKERS_PRODUCT_STICKER_HEIGHT', (int)Tools::getValue('PHSTICKERS_PRODUCT_STICKER_HEIGHT'));
Configuration::updateValue('PHSTICKERS_PRODUCTLIST_STICKER_WIDTH', (int)Tools::getValue('PHSTICKERS_PRODUCTLIST_STICKER_WIDTH'));
Configuration::updateValue('PHSTICKERS_PRODUCTLIST_STICKER_HEIGHT', (int)Tools::getValue('PHSTICKERS_PRODUCTLIST_STICKER_HEIGHT'));
Configuration::updateValue('PHSTICKERS_HIDE_MOBILE', (int)Tools::getValue('PHSTICKERS_HIDE_MOBILE'));
Configuration::updateValue('PHSTICKERS_PROMOTION_SHOW', (int)Tools::getValue('PHSTICKERS_PROMOTION_SHOW'));
Configuration::updateValue('PHSTICKERS_NEWPRODUCT_SHOW', (int)Tools::getValue('PHSTICKERS_NEWPRODUCT_SHOW'));
Configuration::updateValue('PHSTICKERS_BESTSELLER_SHOW', (int)Tools::getValue('PHSTICKERS_BESTSELLER_SHOW'));
Tools::redirect($adminLink.'&conf=4');
}
$stickerUpdate->processUpdate($adminLink);
}
private static function ps17()
{
return Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=');
}
private static function ps16()
{
return Tools::version_compare(_PS_VERSION_, '1.7.0.0', '<=');
}
public function hookDisplayAdminProductsExtra($params)
{
$activeted = $this->isActiveModule();
if ($activeted['actived'] == 1) {
$output = '';
$id_product = (int)Tools::getValue('id_product');
if ($id_product == 0) {
$id_product = (int)$params['id_product'];
}
$ssl = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
$imageStickerDir = $ssl . $this->context->shop->domain . $this->context->shop->physical_uri . 'modules/' . $this->name . '/stickers/' . (int)$this->context->cookie->id_lang . '/';
$list = Sticker::getAllStickers((int)$this->context->cookie->id_lang);
$productStickers = Sticker::getProductSticker((int)$id_product);
$stickers = array();
$positions = array();
$inherit = 0;
if (!empty($productStickers)) {
foreach ($productStickers as $item) {
$stickers[] = (int)$item['id_sticker'];
$positions[$item['id_sticker']] = (int)$item['position'];
$inherit = (int)$item['inherit'];
}
}
$this->context->smarty->assign(array(
'list' => $list,
'imageStickerDir' => $imageStickerDir,
'stickers' => $stickers,
'PHSTICKERS_PRODUCT_MAX' => Configuration::get('PHSTICKERS_PRODUCT_MAX'),
'stickerPosition' => $positions,
'positions' => Sticker::$positions,
'ps16' => self::ps16(),
'si' => (int)$inherit
));
$output .= $this->context->smarty->fetch($this->local_path . 'views/templates/admin/product.tpl');
return $output;
}
}
public function hookActionProductUpdate()
{
$activeted = $this->isActiveModule();
if ($activeted['actived'] == 1) {
if (Tools::getIsset('stickers')) {
$id_product = (int)Tools::getValue('id_product');
$stickers = Tools::getValue('stickers');
$positions = Tools::getValue('position');
$inherit = (int)Tools::getVAlue('stickerInherit');
Sticker::deleteProductSticker((int)$id_product);
if (!empty($stickers)) {
Sticker::addStickerProduct((int)$id_product, $stickers, $positions, $inherit);
}
}
}
}
/**
* hook in product
* @param $params
* @return string
*/
public function hookDisplayProductStickers($params)
{
$activeted = $this->isActiveModule();
if ($activeted['actived'] == 1) {
$id_product = (int)Tools::getValue('id_product');
$output = '';
$ssl = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
$list = Sticker::getAllStickers((int)$this->context->cookie->id_lang);
$productStickers = Sticker::getProductSticker((int)$id_product);
$stickers = array();
$positions = array();
if (!empty($productStickers)) {
$inherit = 0;
foreach ($productStickers as $item) {
$stickers[] = $item['id_sticker'];
$positions[$item['id_sticker']] = $item['position'];
$inherit = (int)$item['inherit'];
}
if ($inherit == 1) {
$product = new Product((int)$id_product, false, (int)$this->context->cookie->id_lang);
$id_category = (int)$product->id_category_default;
$categoryStickers = Sticker::getCategoryStickers((int)$id_category);
if (!empty($categoryStickers)) {
foreach ($categoryStickers as $item) {
$stickers[] = $item['id_sticker'];
$positions[$item['id_sticker']] = $item['position'];
}
}
}
$stickers = array_unique($stickers);
} else {
$product = new Product((int)$id_product, false, (int)$this->context->cookie->id_lang);
$id_category = (int)$product->id_category_default;
$categoryStickers = Sticker::getCategoryStickers((int)$id_category);
if (!empty($categoryStickers)) {
foreach ($categoryStickers as $item) {
$stickers[] = $item['id_sticker'];
$positions[$item['id_sticker']] = $item['position'];
}
}
}
if (!empty($list)) {
$pos = 1;
$product = new Product((int)$id_product, true, (int)$this->context->cookie->id_lang);
foreach ($list as $l) {
if ($l['price_on'] == 1) {
if ($l['price_min'] >= '0.000000' && $l['price_max'] > '0.000000') {
if ($product->price >= $l['price_min'] && $product->price <= $l['price_max']) {
$stickers[] = $l['id_sticker'];
$positions[$l['id_sticker']] = $pos;
$pos++;
}
}
}
if ($l['qty_on'] == 1) {
if ($l['qty_min'] >= 0 && $l['qty_max'] > 0) {
$qty = Product::getQuantity((int)$id_product);
if ($qty >= $l['qty_min'] && $qty <= $l['qty_max']) {
$stickers[] = $l['id_sticker'];
$positions[$l['id_sticker']] = $pos;
$pos++;
}
}
}
if ($l['manu_on'] == 1 && $l['id_manufacturer'] > 0) {
if ($l['id_manufacturer'] == $product->id_manufacturer) {
$stickers[] = $l['id_sticker'];
$positions[$l['id_sticker']] = $pos;
$pos++;
}
}
if ($l['show_new'] == 1) {
if ($product->isNew() == 1) {
$stickers[] = $l['id_sticker'];
$positions[$l['id_sticker']] = $l['position_new'];
}
}
}
}
$stickersImage = array();
if (!empty($list) && !empty($stickers)) {
$i = 0;
foreach ($list as $l) {
if (in_array($l['id_sticker'], $stickers)) {
$stickersImage[$i]['image'] = $ssl . $this->context->shop->domain . $this->context->shop->physical_uri . 'modules/' . $this->name . '/stickers/' . (int)$this->context->cookie->id_lang . '/' . $l['file_name'];
$pos = 0;
if (isset($positions[$l['id_sticker']])) {
$pos = $positions[$l['id_sticker']];
}
$stickersImage[$i]['position'] = $pos;
$i++;
}
}
}
if (!empty($stickersImage)) {
$this->context->smarty->assign(array(
'stickers' => $stickersImage,
'stickerWidth' => Configuration::get('PHSTICKERS_PRODUCT_STICKER_WIDTH'),
'stickerHeight' => Configuration::get('PHSTICKERS_PRODUCT_STICKER_HEIGHT'),
));
$output .= $this->context->smarty->fetch($this->local_path . 'views/templates/hook/product.tpl');
return $output;
}
}
}
/**
* hook listy produktowej
* @param $params
* @return string|void
*/
public function hookDisplayProductListStickers($params)
{
$activeted = $this->isActiveModule();
if ($activeted['actived'] == 1) {
$bestSaleShow = Configuration::get('PHSTICKERS_BESTSELLER_SHOW');
$newProductShow = Configuration::get('PHSTICKERS_NEWPRODUCT_SHOW');
$promotionShow = Configuration::get('PHSTICKERS_PROMOTION_SHOW');
$hideMobile = Configuration::get('PHSTICKERS_HIDE_MOBILE');
if ($hideMobile == 1) {
require_once _PS_TOOL_DIR_ . 'mobile_Detect/Mobile_Detect.php';
$md = new Mobile_Detect();
if ($md->isMobile()) {
return;
}
}
if ($this->context->controller->php_self == 'best-sales' && $bestSaleShow == 0) {
return;
}
if ($this->context->controller->php_self == 'new-products' && $newProductShow == 0) {
return;
}
if ($this->context->controller->php_self == 'prices-drop' && $promotionShow == 0) {
return;
}
$id_product = $params['pro']['id_product'];
$output = '';
$ssl = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
$list = Sticker::getAllStickers((int)$this->context->cookie->id_lang);
$productStickers = Sticker::getProductSticker((int)$id_product);
$stickers = array();
$positions = array();
if (!empty($productStickers)) {
$inherit = 0;
foreach ($productStickers as $item) {
$stickers[] = $item['id_sticker'];
$positions[$item['id_sticker']] = $item['position'];
$inherit = (int)$item['inherit'];
}
if ($inherit == 1) {
$id_category = (int)Tools::getValue('id_category');
$categoryStickers = Sticker::getCategoryStickers((int)$id_category);
if (!empty($categoryStickers)) {
foreach ($categoryStickers as $item) {
$stickers[] = $item['id_sticker'];
$positions[$item['id_sticker']] = $item['position'];
}
}
}
$stickers = array_unique($stickers);
} else {
$id_category = (int)Tools::getValue('id_category');
$categoryStickers = Sticker::getCategoryStickers((int)$id_category);
if (!empty($categoryStickers)) {
foreach ($categoryStickers as $item) {
$stickers[] = $item['id_sticker'];
$positions[$item['id_sticker']] = $item['position'];
}
}
}
if (!empty($list)) {
$product = new Product((int)$id_product, true, (int)$this->context->cookie->id_lang);
foreach ($list as $l) {
if ($l['price_on'] == 1) {
if ($l['price_min'] >= '0.000000' && $l['price_max'] > '0.000000') {
$price = $product->price;
if (Product::isDiscounted($product->id)) {
$sp = SpecificPrice::getSpecificPrice((int)$product->id, $this->context->shop->id, $this->context->currency->id, $this->context->country->id, $this->context->customer->id_default_group, 1, null, 0, 0, 1);
if (!empty($sp)) {
$price = $product->getPrice(false);
}
}
if ($price >= $l['price_min'] && $price <= $l['price_max']) {
$stickers[] = $l['id_sticker'];
$positions[$l['id_sticker']] = $l['position_price'];
}
}
}
if ($l['qty_on'] == 1) {
if ($l['qty_min'] >= 0 && $l['qty_max'] > 0) {
$qty = Product::getQuantity((int)$id_product);
if ($qty >= $l['qty_min'] && $qty <= $l['qty_max']) {
$stickers[] = $l['id_sticker'];
$positions[$l['id_sticker']] = $l['position_qty'];
}
}
}
if ($l['manu_on'] == 1 && $l['id_manufacturer'] > 0) {
if ($l['id_manufacturer'] == $product->id_manufacturer) {
$stickers[] = $l['id_sticker'];
$positions[$l['id_sticker']] = $l['position_manu'];
}
}
if ($l['show_new'] == 1) {
if ($product->isNew() == 1) {
$stickers[] = $l['id_sticker'];
$positions[$l['id_sticker']] = $l['position_new'];
}
}
}
}
$stickersImage = array();
if (!empty($list) && !empty($stickers)) {
$i = 0;
foreach ($list as $l) {
if (in_array($l['id_sticker'], $stickers)) {
$stickersImage[$i]['image'] = $ssl . $this->context->shop->domain . $this->context->shop->physical_uri . 'modules/' . $this->name . '/stickers/' . (int)$this->context->cookie->id_lang . '/' . $l['file_name'];
$pos = 0;
if (isset($positions[$l['id_sticker']])) {
$pos = $positions[$l['id_sticker']];
}
$stickersImage[$i]['position'] = $pos;
$i++;
}
}
}
if (!empty($stickersImage)) {
$this->context->smarty->assign(array(
'stickers' => $stickersImage,
'stickerWidth' => Configuration::get('PHSTICKERS_PRODUCTLIST_STICKER_WIDTH'),
'stickerHeight' => Configuration::get('PHSTICKERS_PRODUCTLIST_STICKER_HEIGHT'),
));
$output .= $this->context->smarty->fetch($this->local_path . 'views/templates/hook/productList.tpl');
return $output;
}
}
}
}