* @copyright Project-Pro * @license Proprietary - paid license */ if (!defined('_PS_VERSION_')) { exit; } require_once dirname(__FILE__) . '/classes/CustomFeatureTabRule.php'; class CustomFeatureTab extends Module { public function __construct() { $this->name = 'customfeaturetab'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'Project-Pro'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Karty cech produktu'); $this->description = $this->l('Dodaje dodatkowe zakładki na karcie produktu w zależności od przypisanych cech.'); $this->ps_versions_compliancy = array('min' => '1.7.0.0', 'max' => _PS_VERSION_); } public function install() { return parent::install() && $this->installDb() && $this->installTab() && $this->registerHook('displayProductExtraContent'); } public function uninstall() { return $this->uninstallDb() && $this->uninstallTab() && parent::uninstall(); } private function installDb() { $sql = array(); $sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'custom_feature_tab` ( `id_custom_feature_tab` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, `id_feature` INT(11) UNSIGNED NOT NULL, `id_feature_value` INT(11) UNSIGNED NOT NULL, `position` INT(11) UNSIGNED NOT NULL DEFAULT 0, `active` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, `date_add` DATETIME NOT NULL, `date_upd` DATETIME NOT NULL, PRIMARY KEY (`id_custom_feature_tab`), INDEX `idx_feature_value` (`id_feature`, `id_feature_value`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;'; $sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'custom_feature_tab_lang` ( `id_custom_feature_tab` INT(11) UNSIGNED NOT NULL, `id_lang` INT(11) UNSIGNED NOT NULL, `title` VARCHAR(255) NOT NULL, `content` TEXT, PRIMARY KEY (`id_custom_feature_tab`, `id_lang`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;'; foreach ($sql as $query) { if (!Db::getInstance()->execute($query)) { return false; } } return true; } private function uninstallDb() { return Db::getInstance()->execute('DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'custom_feature_tab_lang`') && Db::getInstance()->execute('DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'custom_feature_tab`'); } private function installTab() { $tab = new Tab(); $tab->class_name = 'AdminCustomFeatureTab'; $tab->module = $this->name; $tab->id_parent = (int) Tab::getIdFromClassName('AdminCatalog'); $tab->icon = 'description'; $languages = Language::getLanguages(false); foreach ($languages as $lang) { $tab->name[$lang['id_lang']] = 'Karty cech produktu'; } return $tab->add(); } private function uninstallTab() { $idTab = (int) Tab::getIdFromClassName('AdminCustomFeatureTab'); if ($idTab) { $tab = new Tab($idTab); return $tab->delete(); } return true; } public function getContent() { Tools::redirectAdmin($this->context->link->getAdminLink('AdminCustomFeatureTab')); } /** * Hook: displayProductExtraContent * Returns extra tabs for products that match feature rules. */ public function hookDisplayProductExtraContent($params) { $product = $params['product']; $idLang = (int) $this->context->language->id; $productFeatures = Product::getFeaturesStatic((int) $product->id); if (empty($productFeatures)) { return array(); } $rules = CustomFeatureTabRule::getMatchingRules($productFeatures, $idLang); if (empty($rules)) { return array(); } $tabs = array(); foreach ($rules as $rule) { $extraContent = new PrestaShop\PrestaShop\Core\Product\ProductExtraContent(); $extraContent->setTitle($rule['title']); $extraContent->setContent($rule['content']); $tabs[] = $extraContent; } return $tabs; } }