bootstrap = true; $this->table = 'configuration'; $this->className = 'Configuration'; $this->identifier = 'id_configuration'; parent::__construct(); } public function initContent() { $this->display = 'options'; $this->initToolbar(); parent::initContent(); } public function renderOptions() { $grcInfoJson = Configuration::get('QLO_GUEST_REGISTRATION_CARD_INFO'); $savedSections = array(); if ($grcInfoJson !== false && $grcInfoJson !== '') { $grcData = Tools::jsonDecode($grcInfoJson, true); if (is_array($grcData)) { $savedSections = $grcData; } } $allSelected = empty($savedSections); $nodes = array(); foreach (Order::getRegistrationCardInfo() as $sectionId => $section) { $sectionFields = isset($savedSections[$sectionId]) ? $savedSections[$sectionId] : array(); $fieldNodes = array(); foreach ($section['fields'] as $fieldId => $fieldName) { $fieldSelected = $allSelected || in_array($fieldId, $sectionFields); $fieldNodes[] = array( 'value' => $fieldId, 'name' => $fieldName, 'input_name' => 'grc_field_'.$sectionId, 'selected' => $fieldSelected, ); } $fieldsSelected = $allSelected || !empty(array_filter($fieldNodes, function ($n) { return $n['selected']; })); $nodes[] = array( 'value' => $sectionId, 'name' => $section['name'], 'input_name' => 'grc_section', 'selected' => $fieldsSelected, 'children' => $fieldNodes, ); } $tree = new HelperTree('grc-card-info-tree'); $tree->setData($nodes) ->setUseCheckBox(true) ->setAutoSelectChildren(true) ->setUseBulkActions(true); $this->context->smarty->assign(array( 'guest_reg_card_info_tree' => $tree->render(), 'guest_reg_card_form_action' => self::$currentIndex.'&token='.$this->token, 'guest_reg_card_preview_img_url' => $this->context->link->getBaseLink().'img/admin/guest_registration_preview.jpg', 'guest_reg_card_preview_title' => $this->l('Guest Registration Card Preview'), )); return $this->createTemplate('card_info_form.tpl')->fetch(); } public function initToolbarTitle() { $this->toolbar_title = array($this->l('Guest Registration Card')); } public function postProcess() { if (Tools::isSubmit('submitGrcCardInfo')) { $grcInfo = array(); foreach (array_keys(Order::getRegistrationCardInfo()) as $sectionId) { $fields = array_values(array_filter(array_map('intval', (array)Tools::getValue('grc_field_'.$sectionId, array())))); if (!empty($fields)) { $grcInfo[$sectionId] = $fields; } } if (empty($grcInfo)) { $this->errors[] = $this->l('Please select at least one field for the Guest Registration Card.'); return; } Configuration::updateValue('QLO_GUEST_REGISTRATION_CARD_INFO', Tools::jsonEncode($grcInfo)); Tools::redirectAdmin(self::$currentIndex.'&token='.$this->token.'&conf=4'); return; } parent::postProcess(); } }