* @copyright 2007-2017 ST-themes * @license Use, by you or one client for one Prestashop instance. */ if (!defined('_PS_VERSION_')) exit; use PrestaShop\PrestaShop\Core\Module\WidgetInterface; use PrestaShop\PrestaShop\Core\Product\ProductExtraContent; require_once _PS_MODULE_DIR_.'ststickers/classes/StStickersClass.php'; require_once _PS_MODULE_DIR_.'ststickers/classes/StStickersMapClass.php'; class StStickers extends Module implements WidgetInterface { private $templateFile; protected static $access_rights = 0775; public $fields_list; public $fields_value; public $fields_form; public $googleFonts; private $_html = ''; private static $type = array(); private static $location = array(); private static $position = array(); private $spacer_size = '5'; protected $templatePath; public function __construct() { $this->name = 'ststickers'; $this->tab = 'front_office_features'; $this->version = '1.1.1'; $this->author = 'SUNNYTOO.COM'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->getTranSlator()->trans('Stickers block', array(), 'Modules.Ststickers.Admin'); $this->description = $this->getTranSlator()->trans('Show sticker icon or label on product images.', array(), 'Modules.Ststickers.Admin'); $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); $this->templateFile = 'module:ststickers/views/templates/hook/ststickers.tpl'; self::$type = array( 0 => array( 'id' => 'type_0', 'value' => 0, 'label' => $this->getTranslator()->trans('Custom', array(), 'Modules.Ststickers.Admin'), 'class' => '', ), 1 => array( 'id' => 'type_1', 'value' => 1, 'label' => $this->getTranslator()->trans('New(Native)', array(), 'Modules.Ststickers.Admin'), 'class' => 'new', ), 2 => array( 'id' => 'type_2', 'value' => 2, 'label' => $this->getTranslator()->trans('On sale(Native)', array(), 'Modules.Ststickers.Admin'), 'class' => 'on-sale', ), 3 => array( 'id' => 'type_3', 'value' => 3, 'label' => $this->getTranslator()->trans('Reduced price(Native)', array(), 'Modules.Ststickers.Admin'), 'class' => 'discount', ), 4 => array( 'id' => 'type_4', 'value' => 4, 'label' => $this->getTranslator()->trans('Sold out(Native)', array(), 'Modules.Ststickers.Admin'), 'class' => 'sold-out', ), 7 => array( 'id' => 'type_7', 'value' => 7, 'label' => $this->getTranslator()->trans('In stock, Product available with different options and allowed backorders(Native)', array(), 'Modules.Ststickers.Admin'), 'class' => 'in-stock', ), 5 => array( 'id' => 'type_5', 'value' => 5, 'label' => $this->getTranslator()->trans('Online only(Native)', array(), 'Modules.Ststickers.Admin'), 'class' => 'online-only', ), 6 => array( 'id' => 'type_6', 'value' => 6, 'label' => $this->getTranslator()->trans('Pack(Native)', array(), 'Modules.Ststickers.Admin'), 'class' => 'pack', ), ); self::$location = array( 0 => array( 'id' => 'location_0', 'value' => 0, 'label' => $this->getTranslator()->trans('All products', array(), 'Modules.Ststickers.Admin') ), 1 => array( 'id' => 'location_1', 'value' => 1, 'label' => $this->getTranslator()->trans('Specify some products', array(), 'Modules.Ststickers.Admin') ), 2 => array( 'id' => 'location_2', 'value' => 2, 'label' => $this->getTranslator()->trans('By category', array(), 'Modules.Ststickers.Admin') ), 3 => array( 'id' => 'location_3', 'value' => 3, 'label' => $this->getTranslator()->trans('By manufacturer', array(), 'Modules.Ststickers.Admin') ), ); self::$position = array( 10 => array( 'id' => 10, 'name' => $this->getTranslator()->trans('Under product image', array(), 'Modules.Ststickers.Admin'), ), 11 => array( 'id' => 11, 'name' => $this->getTranslator()->trans('At the very bottom of product block', array(), 'Modules.Ststickers.Admin'), ), 13 => array( 'id' => 13, 'name' => $this->getTranslator()->trans('Along with price', array(), 'Modules.Ststickers.Admin'), ), 1 => array( 'id' => 1, 'name' => $this->getTranslator()->trans('Top left corner of product image', array(), 'Modules.Ststickers.Admin'), ), 2 => array( 'id' => 2, 'name' => $this->getTranslator()->trans('Top center of product image', array(), 'Modules.Ststickers.Admin'), ), 3 => array( 'id' => 3, 'name' => $this->getTranslator()->trans('Top right corner of product image', array(), 'Modules.Ststickers.Admin'), ), 4 => array( 'id' => 4, 'name' => $this->getTranslator()->trans('Center left of product image', array(), 'Modules.Ststickers.Admin'), ), 5 => array( 'id' => 5, 'name' => $this->getTranslator()->trans('Center center of product image', array(), 'Modules.Ststickers.Admin'), ), 12 => array( 'id' => 12, 'name' => $this->getTranslator()->trans('Center center of product image(100% width)', array(), 'Modules.Ststickers.Admin'), ), 6 => array( 'id' => 6, 'name' => $this->getTranslator()->trans('Center right of product image', array(), 'Modules.Ststickers.Admin'), ), 7 => array( 'id' => 7, 'name' => $this->getTranslator()->trans('Bottom left corner of product image', array(), 'Modules.Ststickers.Admin'), ), 8 => array( 'id' => 8, 'name' => $this->getTranslator()->trans('Bottom center of product image', array(), 'Modules.Ststickers.Admin') ), 9 => array( 'id' => 9, 'name' => $this->getTranslator()->trans('Bottom right corner of product image', array(), 'Modules.Ststickers.Admin') ), ); $this->templatePath = 'module:'.$this->name.'/views/templates/hook/'; } public function install() { $res = parent::install() && $this->installDb() && $this->registerHook('displayHeader') && $this->registerHook('actionStAssemble') && $this->registerHook('actionProductSearchAfter') && $this->registerHook('displayProductExtraContent') && $this->registerHook('displayAdminProductsExtra') && $this->registerHook('actionObjectCategoryDeleteAfter') && $this->registerHook('actionObjectManufacturerDeleteAfter') && $this->registerHook('actionShopDataDuplication'); if ($res) { // Truncate table before insert data. Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'st_sticker`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'st_sticker_lang`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'st_sticker_shop`'); Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.'st_sticker_map`'); foreach(Shop::getShops(false) as $shop) $res &= $this->sampleData($shop['id_shop']); } $this->clearStickersCache(); return (bool)$res; } /** * Creates tables */ public function installDb() { $return = (bool)Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'st_sticker` ( `id_st_sticker` int(10) unsigned NOT NULL AUTO_INCREMENT, `type` tinyint(1) unsigned NOT NULL DEFAULT 0, `text_color` varchar(7) DEFAULT NULL, `bg_color` varchar(7) DEFAULT NULL, `border_color` varchar(7) DEFAULT NULL, `border_width` smallint(6) unsigned DEFAULT 0, `border_radius` smallint(6) unsigned DEFAULT 0, `bg_opacity` float(4,2) NOT NULL DEFAULT 1, `text_width` smallint(6) unsigned DEFAULT 0, `text_height` smallint(6) unsigned DEFAULT 0, `sticker_position` tinyint(3) unsigned NOT NULL DEFAULT 3, `active` tinyint(1) unsigned NOT NULL DEFAULT 1, `hide_on_mobile` tinyint(1) unsigned NOT NULL DEFAULT 0, `offset_x` smallint(6) signed DEFAULT 0, `offset_y` smallint(6) signed DEFAULT 0, `font_size` smallint(6) unsigned DEFAULT NULL, `text_font` varchar(255) DEFAULT NULL, `text_font_weight` varchar(255) DEFAULT NULL, `position` int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (`id_st_sticker`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;'); $return &= (bool)Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'st_sticker_lang` ( `id_st_sticker` int(10) UNSIGNED NOT NULL, `id_lang` int(10) unsigned NOT NULL, `name` varchar(255) DEFAULT NULL, `text` varchar(255) DEFAULT NULL, `image_multi_lang` varchar(255) DEFAULT NULL, `image_lang_default` varchar(255) DEFAULT NULL, `width` int(10) unsigned NOT NULL DEFAULT 0, `height` int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (`id_st_sticker`, `id_lang`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;'); $return &= (bool)Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'st_sticker_shop` ( `id_st_sticker` int(10) UNSIGNED NOT NULL, `id_shop` int(11) NOT NULL, PRIMARY KEY (`id_st_sticker`,`id_shop`), KEY `id_shop` (`id_shop`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 ;'); $return &= (bool)Db::getInstance()->execute(' CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'st_sticker_map` ( `id_st_sticker_map` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_st_sticker` int(11) NOT NULL DEFAULT 0, `location` tinyint(1) unsigned NOT NULL DEFAULT 0, `id_category` int(10) unsigned NOT NULL DEFAULT 0, `id_manufacturer` int(10) unsigned NOT NULL DEFAULT 0, `id_products` text DEFAULT NULL, `active` tinyint(1) unsigned NOT NULL DEFAULT 1, PRIMARY KEY (`id_st_sticker_map`) ) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;'); return $return; } public function sampleData($id_shop) { $return = true; // Type: 1=New 2=Sale 3=Price drop 4=sold out $samples = array( array( 'name' => 'New sticker', 'text' => 'New', 'type' => 1, 'sticker_position' => 1, 'active' => 1, 'border_color' => '#999999', 'border_width' => 2, 'text_color' => '', 'bg_color' => '', ), array( 'name' => 'On sale sticker', 'text' => 'Sale', 'type' => 2, 'sticker_position' => 3, 'active' => 1, 'border_color' => '#999999', 'border_width' => 2, 'text_color' => '', 'bg_color' => '', ), array( 'name' => 'Reduced price sticker', 'text' => 'Reduced price', 'type' => 3, 'sticker_position' => 13, 'active' => 1, 'border_color' => '', 'border_width' => 0, 'text_color' => '#ffffff', 'bg_color' => '#E54D26', ), array( 'name' => 'Sold out sticker', 'text' => 'Sold out', 'type' => 4, 'sticker_position' => 10, 'active' => 1, 'border_color' => '#999999', 'border_width' => 2, 'text_color' => '', 'bg_color' => '', ), array( 'name' => 'Online only sticker', 'text' => 'Online only', 'type' => 5, 'sticker_position' => 11, 'active' => 0, 'border_color' => '#999999', 'border_width' => 2, 'text_color' => '', 'bg_color' => '', ), array( 'name' => 'Pack sticker', 'text' => 'Pack', 'type' => 6, 'sticker_position' => 5, 'active' => 0, 'border_color' => '#999999', 'border_width' => 2, 'text_color' => '', 'bg_color' => '', ), ); foreach($samples as $sample) { $module = new StStickersClass(); $module->type = $sample['type']; $module->sticker_position = $sample['sticker_position']; $module->active = $sample['active']; $module->border_color = $sample['border_color']; $module->border_width = $sample['border_width']; $module->bg_color = $sample['bg_color']; $module->text_color = $sample['text_color']; $module->id_shop_list = array($id_shop); foreach (Language::getLanguages(false) as $lang) { $module->name[$lang['id_lang']] = $sample['name']; $module->text[$lang['id_lang']] = $sample['text']; } $return &= $module->add(); } return $return; } public function uninstall() { $this->clearStickersCache(); // Delete configuration return $this->uninstallDb() && parent::uninstall(); } /** * deletes tables */ public function uninstallDb() { return Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'st_sticker`,`'._DB_PREFIX_.'st_sticker_lang`,`'._DB_PREFIX_.'st_sticker_shop`,`'._DB_PREFIX_.'st_sticker_map`'); } private function _checkImageDir() { $result = true; if (!file_exists(_PS_UPLOAD_DIR_.$this->name)) { $success = @mkdir(_PS_UPLOAD_DIR_.$this->name, self::$access_rights, true) || @chmod(_PS_UPLOAD_DIR_.$this->name, self::$access_rights); if(!$success) { $result = false; $this->_html .= $this->displayError('"'._PS_UPLOAD_DIR_.$this->name.'" '.$this->getTranslator()->trans('An error occurred during new folder creation', array(), 'Admin.Theme.Panda')); } } return $result; } public function getContent() { $this->context->controller->addJS(($this->_path).'views/js/admin.js'); $this->context->controller->addCss($this->_path.'views/css/admin.css'); $this->googleFonts = include(_PS_MODULE_DIR_.'stthemeeditor/googlefonts.php'); $this->_html .= ''; $check_result = $this->_checkImageDir(); $id_st_sticker = (int)Tools::getValue('id_st_sticker'); $id_st_sticker_map = (int)Tools::getValue('id_st_sticker_map'); if (Tools::getValue('ajax') && Tools::getValue('act') == 'changeProductSticker' ) { $result = array( 'r' => false, 'm' => '', 'd' => '' ); if ($id_product=Tools::getValue('id_product')) { $id_st_sticker_map = StStickersMapClass::changeProductSticker($id_st_sticker, $id_product, $id_st_sticker_map); if ((int)$id_st_sticker_map > 0) { $result = array( 'r' => true, 'm' => '', 'd' => (int)$id_st_sticker_map, ); } } die(json_encode($result)); } if(Tools::getValue('act')=='delete_image' && $id_st_sticker) { $result = array( 'r' => false, 'm' => '', 'd' => '' ); $id_lang = Tools::getValue('id_lang'); $sticker = new StStickersClass($id_st_sticker, $id_lang); $sticker->image_multi_lang = ''; $result['r'] = $sticker->save(); die(json_encode($result)); } if ((Tools::isSubmit('status'.$this->name))) { $sticker = new StStickersClass((int)$id_st_sticker); if($sticker->id && $sticker->toggleStatus()) { $this->clearStickersCache(); Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); } else $this->_html .= $this->displayError($this->getTranslator()->trans('an error occurred while updating the status.', array(), 'Admin.Theme.Panda')); } if ((Tools::isSubmit('statusmap'.$this->name))) { $map = new StStickersMapClass((int)$id_st_sticker_map); if($map->id && $map->toggleStatus()) { $this->clearStickersCache(); Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); } else $this->_html .= $this->displayError($this->getTranslator()->trans('an error occurred while updating the status.', array(), 'Admin.Theme.Panda')); } if (isset($_POST['save'.$this->name]) || isset($_POST['save'.$this->name.'AndStay'])) { if ($id_st_sticker) $sticker = new StStickersClass((int)$id_st_sticker); else $sticker = new StStickersClass(); $error = array(); $sticker->copyFromPost(); if ($text_font = Tools::getValue('text_font_select')) { $sticker->text_font = $text_font; } if (!$sticker->type) { $sticker->type = 0; } $languages = Language::getLanguages(false); $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $default_image = array(); foreach ($languages as $lang) { $res = $this->stUploadImage('image_multi_lang_'.$lang['id_lang']); if(count($res['error'])) $error = array_merge($error,$res['error']); elseif($res['image']) { $sticker->image_multi_lang[$lang['id_lang']] = $res['image']; $sticker->width[$lang['id_lang']] = $res['width']; $sticker->height[$lang['id_lang']] = $res['height']; $default_image || $default_image = $res; } } // Check uploded icon. if ($default_image) { foreach ($languages as $lang) { if (!$sticker->image_multi_lang[$lang['id_lang']]) { $sticker->image_lang_default[$lang['id_lang']] = $default_image['image']; $sticker->width[$lang['id_lang']] = $default_image['width']; $sticker->height[$lang['id_lang']] = $default_image['height']; } } } if (!count($error) && $sticker->validateFields(false) && $sticker->validateFieldsLang(false)) { $shop_ids = $sticker->getShopIds(); $sticker->clearShopIds(); $id_shop_list = array(); if($assos_shop = Tools::getValue('checkBoxShopAsso_st_sticker')) { foreach ($assos_shop as $id_shop => $row) { $id_shop_list[] = $id_shop; } } if (!$id_shop_list) { $id_shop_list = array(Context::getContext()->shop->id); } $sticker->id_shop_list = array_unique($id_shop_list); if($sticker->save()) { $sticker->cacheFonts(); $this->clearStickersCache(); if(isset($_POST['save'.$this->name.'AndStay'])) Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&id_st_sticker='.$sticker->id.'&conf='.($id_st_sticker?4:3).'&update'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); else Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&conf='.($id_st_sticker?4:3).'&token='.Tools::getAdminTokenLite('AdminModules')); } else { $sticker->restoreShopIds($shop_ids); $this->_html .= $this->displayError($this->getTranslator()->trans('An error occurred during sticker', array(), 'Modules.Ststickers.Admin').' '.($id_st_sticker ? $this->gettranslator()->trans('updating', array(), 'Admin.Theme.Panda') : $this->gettranslator()->trans('creation', array(), 'Admin.Theme.Panda'))); } } else $this->_html .= count($error) ? implode('',$error) : $this->displayError($this->getTranslator()->trans('invalid value for field(s).', array(), 'Admin.Theme.Panda')); } if (isset($_POST['savemap'.$this->name]) || isset($_POST['savemap'.$this->name.'AndStay'])) { if ($id_st_sticker_map) $sticker = new StStickersMapClass((int)$id_st_sticker_map); else $sticker = new StStickersMapClass(); $error = array(); $id_products = $sticker->id_products; $sticker->copyFromPost(); $sticker->id_category = 0; $sticker->id_manufacturer = 0; $sticker->id_products = ''; switch($sticker->location) { case 1: if ($id_product = Tools::getValue('id_product')) { $id_product_arr = array(); foreach($id_product AS $id) { /*if (!StStickersMapClass::getByProductId($id, $sticker->id_st_sticker)) { $id_product_arr[] = $id; }*/ $product = new Product((int)$id); if ($product->id) { $id_product_arr[] = (int)$id; } } /*if ($id_products && $id_st_sticker_map) { $id_product_arr = array_merge($id_product_arr, explode(',', trim($id_products, ','))); }*/ if ($id_product_arr = array_unique($id_product_arr)) { $sticker->id_products = ','.implode(',', $id_product_arr).','; } } break; case 2: $sticker->id_category = (int)Tools::getValue('id_category'); break; case 3: $sticker->id_manufacturer = (int)Tools::getValue('id_manufacturer'); break; } if (!$sticker->id_st_sticker) { $error[] = $this->displayError($this->getTranslator()->trans('"Sticker" is required.', array(), 'Modules.Ststickers.Admin')); } if (!count($error) && $sticker->validateFields(false) && $sticker->validateFieldsLang(false)) { if($sticker->save()) { $this->clearStickersCache(); if(isset($_POST['savemap'.$this->name.'AndStay'])) Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&id_st_sticker_map='.$sticker->id.'&conf='.($id_st_sticker_map?4:3).'&updatemap'.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); else Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&conf='.($id_st_sticker_map?4:3).'&token='.Tools::getAdminTokenLite('AdminModules')); } else $this->_html .= $this->displayError($this->getTranslator()->trans('An error occurred during sticker', array(), 'Modules.Ststickers.Admin').' '.($id_st_sticker ? $this->gettranslator()->trans('updating', array(), 'Admin.Theme.Panda') : $this->gettranslator()->trans('creation', array(), 'Admin.Theme.Panda'))); } else $this->_html .= count($error) ? implode('',$error) : $this->displayError($this->getTranslator()->trans('invalid value for field(s).', array(), 'Admin.Theme.Panda')); } if(Tools::isSubmit('add'.$this->name) || (Tools::isSubmit('update'.$this->name) && $id_st_sticker)) { $helper = $this->initForm(); return $this->_html.$helper->generateForm($this->fields_form); } elseif (Tools::isSubmit('delete'.$this->name) && $id_st_sticker) { $sticker = new StStickersClass($id_st_sticker); $sticker->delete(); $this->clearStickersCache(); Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); } if(Tools::isSubmit('addmap'.$this->name) || (Tools::isSubmit('updatemap'.$this->name) && $id_st_sticker_map)) { $helper = $this->initMapForm(); return $this->_html.$helper->generateForm($this->fields_form); } elseif (Tools::isSubmit('deletemap'.$this->name) && $id_st_sticker_map) { $sticker = new StStickersMapClass($id_st_sticker_map); $sticker->delete(); $this->clearStickersCache(); Tools::redirectAdmin(AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules')); } else { $stickers = StStickersClass::getAll(); $helper = $this->initList($stickers); $this->_html .= $helper->generateList($stickers, $this->fields_list); $helper = $this->initMapList(); return $this->_html.$helper->generateList(StStickersMapClass::getAll(), $this->fields_list); } } protected function stUploadImage($item) { $result = array( 'error' => array(), 'image' => '', 'thumb' => '', ); if (isset($_FILES[$item]) && isset($_FILES[$item]['tmp_name']) && !empty($_FILES[$item]['tmp_name'])) { $type = strtolower(substr(strrchr($_FILES[$item]['name'], '.'), 1)); $name = str_replace(strrchr($_FILES[$item]['name'], '.'), '', $_FILES[$item]['name']); $imagesize = array(); $imagesize = @getimagesize($_FILES[$item]['tmp_name']); if (!empty($imagesize) && in_array(strtolower(substr(strrchr($imagesize['mime'], '/'), 1)), array('jpg', 'gif', 'jpeg', 'png')) && in_array($type, array('jpg', 'gif', 'jpeg', 'png'))) { $temp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); $salt = $name ? Tools::str2url($name) : sha1(microtime()); $c_name = $salt; $c_name_thumb = $c_name.'-thumb'; if ($upload_error = ImageManager::validateUpload($_FILES[$item])) $result['error'][] = $upload_error; elseif (!$temp_name || !move_uploaded_file($_FILES[$item]['tmp_name'], $temp_name)) $result['error'][] = $this->displayError($this->getTranslator()->trans('An error occurred during the image upload.', array(), 'Admin.Theme.Panda')); else{ $infos = getimagesize($temp_name); $ratio_y = 72; $ratio_x = $infos[0] / ($infos[1] / $ratio_y); if(!ImageManager::resize($temp_name, _PS_UPLOAD_DIR_.$this->name.'/'.$c_name.'.'.$type, null, null, $type) || !ImageManager::resize($temp_name, _PS_UPLOAD_DIR_.$this->name.'/'.$c_name_thumb.'.'.$type, $ratio_x, $ratio_y, $type)) $result['error'][] = $this->displayError($this->getTranslator()->trans('an error occurred during the image upload.', array(), 'Admin.Theme.Panda')); } if (isset($temp_name)) @unlink($temp_name); if(!count($result['error'])) { $result['image'] = $this->name.'/'.$c_name.'.'.$type; $result['thumb'] = $this->name.'/'.$c_name_thumb.'.'.$type; $result['width'] = $imagesize[0]; $result['height'] = $imagesize[1]; } return $result; } } else return $result; } private function getCategoryOption(&$category_arr,$id_category = 1, $id_lang = false, $id_shop = false, $recursive = true) { $id_lang = $id_lang ? (int)$id_lang : (int)Context::getContext()->language->id; $category = new Category((int)$id_category, (int)$id_lang, (int)$id_shop); if (is_null($category->id)) return; if ($recursive) { $children = Category::getChildren((int)$id_category, (int)$id_lang, true, (int)$id_shop); $spacer = str_repeat(' ', $this->spacer_size * (int)$category->level_depth); } $shop = (object) Shop::getShop((int)$category->getShopID()); $category_arr[$category->id] = array( 'id' => $category->id, 'name' => (isset($spacer) ? $spacer : '').$category->name.' ('.$shop->name.')', ); if (isset($children) && count($children)) foreach ($children as $child) { $this->getCategoryOption($category_arr,(int)$child['id_category'], (int)$id_lang, (int)$child['id_shop'],$recursive); } } protected function initForm() { $id_st_sticker = (int)Tools::getValue('id_st_sticker'); $sticker = new StStickersClass($id_st_sticker); $variants = array(); $variants_default = ['400'=>'400', '700'=>'700', 'italic'=>'italic', '700italic'=>'700italic']; $google_font_link = ''; if($sticker->id && $sticker->text_font){ $temp = $this->googleFonts[str_replace(' ', '_', $sticker->text_font)]['variants']; foreach ($temp as $v) { $variants_default[$v] = $v; } //this can be improved by moving it to the head of BO $google_font_link .= ''; $sticker->text_font_select = $sticker->text_font; } foreach($variants_default AS $value) { $variants[] = array('id'=>$value,'name'=>$value); } array_unshift($variants, array('id'=>'','name'=>'--')); $this->fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->getTranslator()->trans('Settings for ', array(), 'Modules.Ststickers.Admin').self::$type[(int)$sticker->type]['label'], 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'text', 'label' => $this->getTranslator()->trans('Name(Reminder):', array(), 'Modules.Ststickers.Admin'), 'name' => 'name', 'size' => 64, 'lang' => true, 'desc' => $this->getTranslator()->trans('This is used as a reminder, it would not show on the front offce.', array(), 'Modules.Ststickers.Admin'), ), array( 'type' => 'radio', 'label' => $this->getTranslator()->trans('Sticker:', array(), 'Modules.Ststickers.Admin'), 'name' => 'type', 'default_value' => 0, 'values' => self::$type, 'desc' => $this->getTranslator()->trans('"In stock" and "Sold out" stickers would not show out on the product page, it would be reductant to show availability messages twice.', array(), 'Modules.Ststickers.Admin'), ), array( 'type' => 'text', 'label' => $this->getTranslator()->trans('Text:', array(), 'Admin.Theme.Panda'), 'name' => 'text', 'size' => 64, 'lang' => true, 'desc' => $this->getTranslator()->trans('"In stock" and "Sold out" stickers do not use this setting. They use texts defined on the product detail page or the product settings page.', array(), 'Modules.Ststickers.Admin'), ), array( 'type' => 'select', 'label' => $this->getTranslator()->trans('Position:', array(), 'Admin.Theme.Panda'), 'name' => 'sticker_position', 'default_value' => 3, 'options' => array( 'query' => self::$position, 'id' => 'id', 'name' => 'name', ), ), array( 'type' => 'text', 'label' => $this->getTranslator()->trans('Offset X:', array(), 'Admin.Theme.Panda'), 'name' => 'offset_x', 'prefix' => 'px', 'class' => 'fixed-width-lg', 'desc' => $this->getTranslator()->trans('Accept positive and negative numbers ', array(), 'Admin.Theme.Panda'), ), array( 'type' => 'text', 'label' => $this->getTranslator()->trans('Offset Y:', array(), 'Admin.Theme.Panda'), 'name' => 'offset_y', 'prefix' => 'px', 'class' => 'fixed-width-lg', 'desc' => $this->getTranslator()->trans('Accept positive and negative numbers ', array(), 'Admin.Theme.Panda'), ), array( 'type' => 'select', 'label' => $this->getTranslator()->trans('Google fonts:', array(), 'Admin.Theme.Panda'), 'name' => 'text_font_select', 'onchange' => 'handle_font_change(this);', 'options' => array( 'query' => $this->fontOptions(), 'id' => 'id', 'name' => 'name', 'default' => array( 'value' => 0, 'label' => $this->getTranslator()->trans('Use default', array(), 'Admin.Theme.Panda'), ), ), 'default_value' => '', 'validation' => 'isGenericName', ), array( 'type' => 'select', 'label' => $this->getTranslator()->trans('Font weight:', array(), 'Admin.Theme.Panda'), 'onchange' => 'handle_font_style(this);', 'name' => 'text_font_weight', 'options' => array( 'query' => $variants, 'id' => 'id', 'name' => 'name', ), 'default_value' => '', 'validation' => 'isAnything', 'desc' => '
Example Title
'.$google_font_link, ), array( 'type' => 'text', 'label' => $this->getTranslator()->trans('Font size:', array(), 'Admin.Theme.Panda'), 'name' => 'font_size', 'prefix' => 'px', 'class' => 'fixed-width-lg', ), array( 'type' => 'color', 'label' => $this->getTranslator()->trans('Text color:', array(), 'Admin.Theme.Panda'), 'name' => 'text_color', 'size' => 33, ), array( 'type' => 'color', 'label' => $this->getTranslator()->trans('Background color:', array(), 'Admin.Theme.Panda'), 'name' => 'bg_color', 'size' => 33, ), array( 'type' => 'text', 'label' => $this->getTranslator()->trans('Background opacity:', array(), 'Admin.Theme.Panda'), 'name' => 'bg_opacity', 'validation' => 'isFloat', 'default_value' => 1, 'class' => 'fixed-width-lg', 'desc' => $this->getTranslator()->trans('From 0.0 (fully transparent) to 1.0 (fully opaque).', array(), 'Admin.Theme.Panda'), ), array( 'type' => 'text', 'label' => $this->getTranslator()->trans('Border width:', array(), 'Admin.Theme.Panda'), 'name' => 'border_width', 'prefix' => 'px', 'class' => 'fixed-width-lg', ), array( 'type' => 'color', 'label' => $this->getTranslator()->trans('Border color:', array(), 'Admin.Theme.Panda'), 'name' => 'border_color', 'size' => 33, ), array( 'type' => 'text', 'label' => $this->getTranslator()->trans('Border radius:', array(), 'Admin.Theme.Panda'), 'name' => 'border_radius', 'prefix' => 'px', 'class' => 'fixed-width-lg', 'validation' => 'isNullOrUnsignedId', 'desc' => $this->getTranslator()->trans('Set a large value for this field to make it be round.', array(), 'Modules.Ststickers.Admin'), ), array( 'type' => 'text', 'label' => $this->getTranslator()->trans('Width:', array(), 'Admin.Theme.Panda'), 'name' => 'text_width', 'prefix' => 'px', 'class' => 'fixed-width-lg', 'desc' => $this->getTranslator()->trans('Setting a width to stickers can center them.', array(), 'Modules.Ststickers.Admin'), ), array( 'type' => 'text', 'label' => $this->getTranslator()->trans('Height:', array(), 'Admin.Theme.Panda'), 'name' => 'text_height', 'prefix' => 'px', 'class' => 'fixed-width-lg', ), array( 'type' => 'switch', 'label' => $this->getTranslator()->trans('Status:', array(), 'Admin.Theme.Panda'), 'name' => 'active', 'is_bool' => true, 'default_value' => 1, 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->getTranslator()->trans('Enabled', array(), 'Admin.Theme.Panda') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->getTranslator()->trans('Disabled', array(), 'Admin.Theme.Panda') ) ), ), array( 'type' => 'radio', 'label' => $this->getTranslator()->trans('Visibility:', array(), 'Admin.Theme.Panda'), 'name' => 'hide_on_mobile', 'default_value' => 0, 'values' => array( array( 'id' => 'hide_on_mobile_0', 'value' => 0, 'label' => $this->getTranslator()->trans('Visible', array(), 'Admin.Theme.Panda')), array( 'id' => 'hide_on_mobile_1', 'value' => 1, 'label' => $this->getTranslator()->trans('Hide on mobile (screen width < 992px)', array(), 'Admin.Theme.Panda')), array( 'id' => 'hide_on_mobile_2', 'value' => 2, 'label' => $this->getTranslator()->trans('Hide on PC (screen width > 992px)', array(), 'Admin.Theme.Panda')), ), 'validation' => 'isUnsignedInt', ), array( 'type' => 'text', 'label' => $this->getTranslator()->trans('Position:', array(), 'Admin.Theme.Panda'), 'name' => 'position', 'default_value' => 0, 'class' => 'fixed-width-sm' ), ), 'buttons' => array( array( 'type' => 'submit', 'title' => $this->getTranslator()->trans('Save', array(), 'Admin.Actions'), 'icon' => 'process-icon-save', 'class'=> 'pull-right' ), ), 'submit' => array( 'title' => $this->getTranslator()->trans('Save and stay', array(), 'Admin.Actions'), 'stay' => true ), ); if (Shop::isFeatureActive()) { $this->fields_form[0]['form']['input'][] = array( 'type' => 'shop', 'label' => $this->getTranslator()->trans('Shop association:', array(), 'Admin.Theme.Panda'), 'name' => 'checkBoxShopAsso', ); } $languages = Language::getLanguages(true); $default_lang = (int)Configuration::get('PS_LANG_DEFAULT'); foreach ($languages as $lang) { $this->fields_form[0]['form']['input']['image_multi_lang_'.$lang['id_lang']] = array( 'type' => 'file', 'label' => $this->getTranslator()->trans('Image', array(), 'Admin.Theme.Panda').' - '.$lang['name'].($default_lang == $lang['id_lang'] ? '('.$this->gettranslator()->trans('default language', array(), 'Admin.Theme.Panda').')' : '').':', 'name' => 'image_multi_lang_'.$lang['id_lang'], //'required' => ($default_lang == $lang['id_lang']), 'desc' => $this->getTranslator()->trans('Text would not show out, if you upload an image here. This module would not change image names for seo purpose, so ensure the image you are going to upload has an unique name. It is not recommended to upload an image for "In stock" stick, case it has 3 different status.', array(), 'Modules.Ststickers.Admin').''.$this->getTranslator()->trans(' Delete', array(), 'Admin.Theme.Panda').'
'; } } $helper = new HelperForm(); $helper->show_toolbar = false; $helper->module = $this; $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); $helper->default_form_language = $lang->id; $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; $helper->id = $sticker->id; $helper->table = 'st_sticker'; $helper->identifier = 'id_st_sticker'; $helper->submit_action = 'save'.$this->name; $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = array( 'fields_value' => $this->getFieldsValueSt($sticker,"fields_form"), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id ); return $helper; } public function fontOptions() { $google = array(); foreach($this->googleFonts as $v) $google[] = array('id'=>$v['family'],'name'=>$v['family']); return $google; } protected function initMapForm() { $id_st_sticker_map = (int)Tools::getValue('id_st_sticker_map'); $sticker = new StStickersMapClass($id_st_sticker_map); $this->fields_form[0]['form'] = array( 'legend' => array( 'title' => $this->getTranslator()->trans('Setting', array(), 'Admin.Theme.Panda'), 'icon' => 'icon-cogs' ), 'input' => array( array( 'type' => 'select', 'label' => $this->getTranslator()->trans('Sticker:', array(), 'Modules.Ststickers.Admin'), 'name' => 'id_st_sticker', 'required' => true, 'options' => array( 'query' => $this->getStickeryArray(), 'id' => 'id', 'name' => 'name', 'default' => array( 'value' => '', 'label' => $this->getTranslator()->trans('Select a sticker', array(), 'Modules.Ststickers.Admin') ) ), ), 'location' => array( 'type' => 'radio', 'label' => $this->getTranslator()->trans('Show on:', array(), 'Admin.Theme.Panda'), 'name' => 'location', 'default_value' => 0, 'values' => self::$location, ), 'category' => array( 'type' => 'select', 'label' => $this->getTranslator()->trans('Select a category', array(), 'Modules.Ststickers.Admin'), 'name' => 'id_category', 'class' => 'fixed-width-xxl', 'options' => array( 'query' => $this->getApplyCategory(), 'id' => 'id', 'name' => 'name', 'default' => array( 'value' => '', 'label' => $this->getTranslator()->trans('All', array(), 'Admin.Theme.Panda') ) ), ), 'manufacturer' => array( 'type' => 'select', 'label' => $this->getTranslator()->trans('Select a manufacturer', array(), 'Modules.Ststickers.Admin'), 'name' => 'id_manufacturer', 'class' => 'fixed-width-xxl', 'options' => array( 'query' => $this->getApplyManufacturer(), 'id' => 'id', 'name' => 'name', 'default' => array( 'value' => '', 'label' => $this->getTranslator()->trans('All', array(), 'Admin.Theme.Panda') ) ), ), 'products' => array( 'type' => 'text', 'label' => $this->getTranslator()->trans('Specific products:', array(), 'Modules.Ststickers.Admin'), 'name' => 'products', 'autocomplete' => false, 'class' => 'fixed-width-xxl', 'desc' => '', ), array( 'type' => 'switch', 'label' => $this->getTranslator()->trans('Status:', array(), 'Admin.Theme.Panda'), 'name' => 'active', 'is_bool' => true, 'default_value' => 1, 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->getTranslator()->trans('Enabled', array(), 'Admin.Theme.Panda') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->getTranslator()->trans('Disabled', array(), 'Admin.Theme.Panda') ) ), ), ), 'buttons' => array( array( 'type' => 'submit', 'title' => $this->getTranslator()->trans('Save', array(), 'Admin.Actions'), 'icon' => 'process-icon-save', 'class'=> 'pull-right' ), ), 'submit' => array( 'title' => $this->getTranslator()->trans('Save and stay', array(), 'Admin.Actions'), 'stay' => true ), ); $this->fields_form[0]['form']['input'][] = array( 'type' => 'html', 'id' => 'a_cancel', 'label' => '', 'name' => ''.$this->getTranslator()->trans('Back to list', array(), 'Admin.Theme.Panda').'', ); $products_html = ''; foreach(explode(',', trim($sticker->id_products, ',')) AS $id_product) { if (!(int)$id_product) { continue; } $product = new Product((int)$id_product, false, Context::getContext()->language->id); $products_html .= '