Orientujecie się czy można w module - "Lista producentów na stronie głównej" wyświetlić tylko kilka najważniejszych producentów ? chciałbym wpisać id_manufacturer na sztywno, bez dodatkowych funkcjonalnosci w BO.
plik php z mojego szablonu ma nastepującą postać
Question
Habakuk34
Orientujecie się czy można w module - "Lista producentów na stronie głównej" wyświetlić tylko kilka najważniejszych producentów ? chciałbym wpisać id_manufacturer na sztywno, bez dodatkowych funkcjonalnosci w BO.
plik php z mojego szablonu ma nastepującą postać
use PrestaShop\PrestaShop\Core\Module\WidgetInterface; if (!defined('_PS_VERSION_')) { exit; } class TtBrandlogo extends Module implements WidgetInterface { protected $templateFile; public function __construct() { $this->name = 'ttbrandlogo'; $this->tab = 'front_office_features'; $this->version = '1.0.1'; $this->author = 'TemplateTrip'; $this->need_instance = 1; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->getTranslator()->trans('TT - Brand Logo', [], 'Modules.ttbrandlogo.Admin'); $this->description = $this->getTranslator()->trans('Displays Brand logo on homepage.', [], 'Modules.ttbrandlogo.Admin'); $this->ps_versions_compliancy = ['min' => '1.7.0.0', 'max' => _PS_VERSION_]; $this->templateFile = 'module:ttbrandlogo/views/templates/hook/ttbrandlogo.tpl'; } public function install() { Configuration::updateValue('TTBRAND_NAME', 0); Configuration::updateValue('TT_BRAND_ITEMS', 10); return parent::install() && $this->registerHook('displayHome') && $this->registerHook('displayHeader') && $this->registerHook('displayMegamenuBrand'); } public function uninstall() { return parent::uninstall() && Configuration::deleteByName('TTBRAND_NAME')&& Configuration::deleteByName('TT_BRAND_ITEMS'); } public function getContent() { $output = ''; if (Tools::isSubmit('submitTTBlockBrandLogos')) { $ttBrandItems = Tools::getValue('TT_BRAND_ITEMS'); if (!$ttBrandItems || empty($ttBrandItems)) { $output .= $this->displayError( $this->trans('Please complete the "Manufacture to display" field.', [], 'Modules.ttbrandlogo.Admin' ) ); } elseif (0 === (int)$ttBrandItems) { $output .= $this->displayError( $this->trans('Invalid number.', [], 'Modules.ttbrandlogo.Admin' ) ); } else { Configuration::updateValue('TTBRAND_NAME', (int)(Tools::getValue('TTBRAND_NAME'))); Configuration::updateValue('TT_BRAND_ITEMS',(int)$ttBrandItems); $this->_clearCache('*'); $output .= $this->displayConfirmation($this->trans('The settings have been updated.',[],'Admin.Notifications.Success')); } } return $output.$this->renderForm(); } public function hookActionObjectManufacturerUpdateAfter() { $this->_clearCache('*'); } public function hookActionObjectManufacturerAddAfter() { $this->_clearCache('*'); } public function hookActionObjectManufacturerDeleteAfter() { $this->_clearCache('*'); } protected function getCacheId($hookName = null) { return parent::getCacheId().'|'.$hookName; } public function renderForm() { $fields_form = [ 'form' => [ 'legend' => [ 'title' => $this->trans( 'Settings', [], 'Admin.Global' ), 'icon' => 'icon-cogs' ], 'input' => [ [ 'type' => 'switch', 'label' => $this->getTranslator()->trans('Display Manufacture Name', [], 'Modules.ttbrandlogo.Admin'), 'name' => 'TTBRAND_NAME', 'is_bool' => true, 'values' => [ [ 'id' => 'active_on', 'value' => 1, 'label' => $this->getTranslator()->trans('Yes', [], 'Admin.Global') ], [ 'id' => 'active_off', 'value' => 0, 'label' => $this->getTranslator()->trans('No', [], 'Admin.Global') ] ], ], [ 'type' => 'text', 'label' => $this->l('Manufacture to display'), 'name' => 'TT_BRAND_ITEMS', 'desc' => $this->l(''), ], ], 'submit' => [ 'title' => $this->trans( 'Save', [], 'Admin.Actions' ), ], ], ]; $helper = new HelperForm(); $helper->show_toolbar = false; $helper->table = $this->table; $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->identifier = $this->identifier; $helper->submit_action = 'submitTTBlockBrandLogos'; $helper->currentIndex = $this->context->link->getAdminLink( 'AdminModules', false ) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name; $helper->token = Tools::getAdminTokenLite('AdminModules'); $helper->tpl_vars = [ 'fields_value' => $this->getConfigFieldsValues(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id ]; return $helper->generateForm([$fields_form]); } public function getConfigFieldsValues() { return [ 'TTBRAND_NAME' => (int)Tools::getValue('TTBRAND_NAME', Configuration::get('TTBRAND_NAME')), 'TT_BRAND_ITEMS' => (int)Tools::getValue('TT_BRAND_ITEMS', Configuration::get('TT_BRAND_ITEMS')), ]; } public function getWidgetVariables($hookName = null, array $configuration = []) { $brands = Manufacturer::getManufacturers(false, (int)Context::getContext()->language->id); foreach ($brands as &$brand) { $brand['image'] = $this->context->language->iso_code.'-default'; $brand['link'] = $this->context->link->getManufacturerLink($brand); $fileExist = file_exists( _PS_MANU_IMG_DIR_ . $brand['id_manufacturer'] . '-' . ImageType::getFormattedName('medium').'.jpg' ); if ($fileExist) { $brand['image'] = $brand['id_manufacturer']; } } return [ 'brands' => $brands, 'hookName' => $hookName, 'configuration' => $configuration, 'page_link' => $this->context->link->getPageLink('manufacturer'), 'brandname' => Configuration::get('TTBRAND_NAME'), 'display_link_brand' => Configuration::get('PS_DISPLAY_SUPPLIERS'), 'brand_items' => Configuration::get('TT_BRAND_ITEMS'), ]; } public function hookDisplayHeader() { $this->context->controller->addCSS($this->_path .'views/css/front.css'); } public function renderWidget($hookName = null, array $configuration = []) { $cacheId = $this->getCacheId('ttbrandlogo'); $isCached = $this->isCached($this->templateFile, $cacheId); if (!$isCached) { $this->smarty->assign($this->getWidgetVariables($hookName, $configuration)); } return $this->fetch($this->templateFile, $cacheId); } }
Link to comment
Share on other sites
3 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now