diff --git a/modules/crossselling/crossselling.php b/modules/crossselling/crossselling.php index 31262888d..c4fc51a32 100755 --- a/modules/crossselling/crossselling.php +++ b/modules/crossselling/crossselling.php @@ -78,39 +78,21 @@ class CrossSelling extends Module if (Tools::isSubmit('submitCross')) { - if (Tools::getValue('displayPrice') != 0 AND Tools::getValue('displayPrice') != 1) + if (Tools::getValue('displayPrice') != 0 AND Tools::getValue('CROSSSELLING_DISPLAY_PRICE') != 1) $this->_html .= $this->displayError('Invalid displayPrice'); - else if (!($productNbr = Tools::getValue('productNbr')) || empty($productNbr)) + else if (!($productNbr = Tools::getValue('CROSSSELLING_NBR')) || empty($productNbr)) $this->_html .= $this->displayError('You must fill in the \'Products displayed\' field.'); elseif ((int)($productNbr) == 0) $this->_html .= $this->displayError('Invalid number.'); else { - Configuration::updateValue('CROSSSELLING_DISPLAY_PRICE', (int)Tools::getValue('displayPrice')); - Configuration::updateValue('CROSSSELLING_NBR', (int)Tools::getValue('productNbr')); + Configuration::updateValue('CROSSSELLING_DISPLAY_PRICE', (int)Tools::getValue('CROSSSELLING_DISPLAY_PRICE')); + Configuration::updateValue('CROSSSELLING_NBR', (int)Tools::getValue('CROSSSELLING_NBR')); $this->_clearCache('crossselling.tpl'); $this->_html .= $this->displayConfirmation($this->l('Settings updated successfully')); } } - $this->_html .= ' -
-
'.$this->l('Settings').' - -
- - - - -

'.$this->l('Show the price on the products in the block.').'

-
-
- -

'.$this->l('Define the number of products displayed in this block').'

-
-
-
-
'; - return $this->_html; + return $this->_html.$this->renderForm(); } public function hookHeader() @@ -253,4 +235,72 @@ class CrossSelling extends Module { $this->_clearCache('crossselling.tpl'); } -} + + public function renderForm() + { + $fields_form = array( + 'form' => array( + 'legend' => array( + 'title' => $this->l('Settings'), + 'icon' => 'icon-cogs' + ), + 'input' => array( + array( + 'type' => 'switch', + 'label' => $this->l('Display price on products'), + 'name' => 'CROSSSELLING_DISPLAY_PRICE', + 'desc' => $this->l('Show the price on the products in the block.'), + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ), + ), + array( + 'type' => 'text', + 'label' => $this->l('Number of products displayed'), + 'name' => 'CROSSSELLING_NBR', + 'class' => 'fixed-width-xs', + 'desc' => $this->l('Define the number of products displayed in this block.'), + ), + ), + 'submit' => array( + 'title' => $this->l('Save'), + 'class' => 'btn btn-primary') + ), + ); + + $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 = 'submitCross'; + $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 = array( + 'fields_value' => $this->getConfigFieldsValues(), + 'languages' => $this->context->controller->getLanguages(), + 'id_language' => $this->context->language->id + ); + + return $helper->generateForm(array($fields_form)); + } + + public function getConfigFieldsValues() + { + return array( + 'CROSSSELLING_NBR' => Tools::getValue('CROSSSELLING_NBR', Configuration::get('CROSSSELLING_NBR')), + 'CROSSSELLING_DISPLAY_PRICE' => Tools::getValue('CROSSSELLING_DISPLAY_PRICE', Configuration::get('CROSSSELLING_DISPLAY_PRICE')), + ); + } +} \ No newline at end of file