Пример #1
0
    private function getEditTemplateTabHtml($templates, $mode, $title)
    {
        if (!$this->integrated) {
            return '';
        }
        if ($mode == 'add') {
            $id = 0;
            if ($templates == null) {
                foreach ($this->active_languages as $language) {
                    $template = PP::getProductPropertiesByTemplateId($id);
                    $template['name'] = '';
                    $template['auto_desc'] = 1;
                    $template['description'] = '';
                    $templates[$language['id_lang']][$id] = $template;
                }
            }
        } else {
            $id = (int) Tools::getValue('id');
        }
        if ($templates == null) {
            $templates = PP::getAllTemplates();
        }
        $template = $templates[$this->default_language_id][$id];
        $ms = PP::resolveMS($template['pp_bo_measurement_system']);
        $all_properties = $this->getAllProperties($ms);
        $property_types = $this->getPropertyTypes();
        $translations = $this->getTranslations('EditTemplate');
        $buttons = array(array('title' => $this->l('Cancel'), 'type' => 'submit', 'name' => 'cancelSaveTemplate', 'icon' => 'process-icon-cancel'));
        $helper = $this->createHelperForm('pp_template_form', $title, 'submitSaveTemplate', 'icon-edit');
        $form = array('input' => array(array('type' => 'div', 'label' => $this->l('ID'), 'name' => $id, 'class' => 'control-text', 'condition' => $mode == 'edit'), array('type' => 'text', 'label' => $this->l('name'), 'name' => 'name_input', 'lang' => true), array('type' => 'text', 'label' => $this->l('description'), 'name' => 'description_input', 'lang' => true, 'desc' => $this->l('leave blank to use auto generated description')), array('type' => 'radio', 'label' => $translations['s_pp_qty_policy'], 'name' => 'pp_qty_policy', 'desc' => $this->l('ordered quantity specifies number of items (pieces, packs, etc.) or one item of the specified number of whole or fractional units (kg, m, ft, etc.)'), 'values' => array(array('id' => 'pp_qty_policy_0', 'value' => 0, 'label' => $translations['s_pp_qty_policy_0']), array('id' => 'pp_qty_policy_1', 'value' => 1, 'label' => $translations['s_pp_qty_policy_1']), array('id' => 'pp_qty_policy_2', 'value' => 2, 'label' => $translations['s_pp_qty_policy_2']), array('id' => 'pp_qty_policy_3', 'value' => 3, 'label' => $translations['s_pp_qty_policy_ext']))), array('type' => 'radio', 'label' => $translations['s_pp_qty_mode'], 'name' => 'pp_qty_mode', 'desc' => $this->l('product quantity can be exactly measured or only approximately (the exact amount cannot be ordered) - only if quantity policy is set to units'), 'values' => array(array('id' => 'pp_qty_mode_0', 'value' => 0, 'label' => $translations['s_pp_qty_mode_0']), array('id' => 'pp_qty_mode_1', 'value' => 1, 'label' => $translations['s_pp_qty_mode_1']))), array('type' => 'radio', 'label' => $translations['s_pp_display_mode'], 'name' => 'pp_display_mode', 'desc' => $translations['s_pp_display_mode_1_long'], 'values' => array(array('id' => 'pp_display_mode_0', 'value' => 0, 'label' => $translations['s_pp_display_mode_0']), array('id' => 'pp_display_mode_1', 'value' => 1, 'label' => $translations['s_pp_display_mode_1'])), 'checkboxes' => array(array('values' => array('query' => array(array('id' => 'retail_price', 'name' => $translations['s_pp_display_mode_2'], 'val' => '1')), 'id' => 'id', 'name' => 'name')), array('values' => array('query' => array(array('id' => 'base_unit_price', 'name' => $translations['s_pp_display_mode_4'], 'val' => '1')), 'id' => 'id', 'name' => 'name')))), array('type' => 'radio', 'label' => $translations['s_pp_price_display_mode'], 'name' => 'pp_price_display_mode', 'desc' => $this->l('show calculated price separately, display it the position of the product price or hide the calculated price'), 'values' => array(array('id' => 'pp_price_display_mode_0', 'value' => 0, 'label' => $translations['s_pp_price_display_mode_0']), array('id' => 'pp_price_display_mode_1', 'value' => 1, 'label' => $translations['s_pp_price_display_mode_1']), array('id' => 'pp_price_display_mode_16', 'value' => 16, 'label' => $translations['s_pp_price_display_mode_16']))), $this->createHelperFormSelect('pp_price_text', array('label' => $translations['s_pp_price_text'], 'desc' => $this->l('displayed after the product\'s price')), self::PROPERTY_TYPE_GENERAL, $helper, $template, $all_properties, $property_types), $this->createHelperFormSelect('pp_qty_text', array('label' => $translations['s_pp_qty_text'], 'desc' => $this->l('displayed after the product\'s quantity')), self::PROPERTY_TYPE_GENERAL, $helper, $template, $all_properties, $property_types), $this->createHelperFormSelect('pp_unity_text', array('label' => $translations['s_pp_unity_text'], 'desc' => $this->l('displayed for products with unit price greater than zero')), self::PROPERTY_TYPE_GENERAL, $helper, $template, $all_properties, $property_types), array('type' => 'text', 'label' => $translations['s_pp_unit_price_ratio'], 'name' => 'unit_price_ratio', 'class' => 'fixed-width-xl', 'desc' => $this->l('used to auto calculate unit price in product catalog')), array('type' => 'text', 'label' => $translations['s_pp_minimal_price_ratio'], 'name' => 'minimal_price_ratio', 'class' => 'fixed-width-xl', 'desc' => $this->l('used to calculate minimum price for quantity less than the specified threshold')), array('type' => 'text', 'label' => $translations['s_pp_minimal_quantity'], 'name' => 'minimal_quantity', 'class' => 'fixed-width-xl', 'desc' => $this->l('the minimum quantity to buy a product (leave blank to use default)')), array('type' => 'text', 'label' => $translations['s_pp_default_quantity'], 'name' => 'default_quantity', 'class' => 'fixed-width-xl', 'desc' => $this->l('the initial quantity to buy a product (leave blank to use default)')), array('type' => 'text', 'label' => $translations['s_pp_qty_step'], 'name' => 'qty_step', 'class' => 'fixed-width-xl', 'desc' => $this->l('quantity step (leave blank to use default)')), $this->createHelperFormSelect('pp_explanation', array('label' => $translations['s_pp_explanation']), self::PROPERTY_TYPE_BUY_BLOCK_TEXT, $helper, $template, $all_properties, $property_types), array('type' => 'text', 'label' => $this->l('CSS classes'), 'name' => 'pp_css', 'desc' => $this->l('specify valid CSS classes separated by space (these classes will be added to HTML for products using this template)') . '
							   <br/>' . sprintf($this->l('add your classes definitions in the "%s" file'), PSM::normalizePath('themes/' . _THEME_NAME_ . '/css/modules/pproperties/custom.css'))), array('type' => 'radio', 'label' => $this->l('display available quantities mode'), 'name' => 'pp_bo_qty_available_display', 'desc' => $this->l('display available quantities on the product page based on the template configuration (only if enabled in preferences)') . ($template['pp_bo_qty_available_display'] == 0 ? '<br>' . ($template['pp_qty_available_display'] == 2 ? $this->l('-- available quantities will be hidden on the product page for current template --') : $this->l('-- available quantities will be displayed on the product page for current template --')) : ''), 'values' => array(array('id' => 'pp_bo_qty_available_display_0', 'value' => 0, 'label' => $this->l('auto')), array('id' => 'pp_bo_qty_available_display_1', 'value' => 1, 'label' => $this->l('visible')), array('id' => 'pp_bo_qty_available_display_2', 'value' => 2, 'label' => $this->l('hidden')))), array('type' => 'radio', 'label' => $this->l('measurement system'), 'name' => 'pp_bo_measurement_system', 'desc' => $this->l('unit measurement system used by this template (default - use measurement system defined in Settings)'), 'values' => array(array('id' => 'pp_bo_measurement_system_0', 'value' => (int) PP::PP_MS_DEFAULT, 'label' => $this->l('default')), array('id' => 'pp_bo_measurement_system_1', 'value' => (int) PP::PP_MS_METRIC, 'label' => $this->l('metric')), array('id' => 'pp_bo_measurement_system_2', 'value' => (int) PP::PP_MS_NON_METRIC, 'label' => $this->l('non metric')))), array('type' => 'radio', 'label' => $this->l('visible in catalog'), 'name' => 'pp_bo_hidden', 'desc' => $this->l('hidden template is not visible in the product catalog, but still used in the shop'), 'values' => array(array('id' => 'pp_bo_hidden_0', 'value' => 0, 'label' => $this->l('visible')), array('id' => 'pp_bo_hidden_1', 'value' => 1, 'label' => $this->l('hidden')))), array('type' => 'hidden', 'name' => 'id'), array('type' => 'hidden', 'name' => 'mode')), 'buttons' => $buttons);
        $helper->fields_value['id'] = $id;
        $helper->fields_value['mode'] = $mode;
        $helper->fields_value['name_input'] = array();
        $helper->fields_value['description_input'] = array();
        foreach ($this->active_languages as $language) {
            $id_lang = $language['id_lang'];
            $helper->fields_value['name_input'][$id_lang] = isset($templates[$id_lang]) ? PP::safeOutputValue($templates[$id_lang][$id]['name']) : '';
            $helper->fields_value['description_input'][$id_lang] = isset($templates[$id_lang]) ? PP::safeOutputValue($templates[$id_lang][$id]['auto_desc'] || $mode == 'copy' ? '' : $templates[$id_lang][$id]['description']) : '';
        }
        $helper->fields_value['pp_qty_mode'] = $template['pp_qty_mode'];
        $helper->fields_value['pp_display_mode'] = (int) (($template['pp_display_mode'] & 1) == 1);
        $helper->fields_value['pp_display_mode_retail_price'] = (int) (($template['pp_display_mode'] & 2) == 2);
        $helper->fields_value['pp_display_mode_base_unit_price'] = (int) (($template['pp_display_mode'] & 4) == 4);
        $helper->fields_value['pp_price_display_mode'] = $template['pp_price_display_mode'];
        $helper->fields_value['unit_price_ratio'] = (double) $template['pp_unit_price_ratio'] > 0 ? PP::formatQty($template['pp_unit_price_ratio']) : '';
        $helper->fields_value['minimal_price_ratio'] = (double) $template['pp_minimal_price_ratio'] > 0 ? PP::formatQty($template['pp_minimal_price_ratio']) : '';
        $helper->fields_value['minimal_quantity'] = (double) $template['pp_minimal_quantity'] > 0 ? PP::formatQty($template['pp_minimal_quantity']) : '';
        $helper->fields_value['default_quantity'] = (double) $template['pp_default_quantity'] > 0 ? PP::formatQty($template['pp_default_quantity']) : '';
        $helper->fields_value['qty_step'] = (double) $template['pp_qty_step'] > 0 ? PP::formatQty($template['pp_qty_step']) : '';
        $helper->fields_value['pp_css'] = $template['pp_css'];
        $helper->fields_value['pp_bo_qty_available_display'] = $template['pp_bo_qty_available_display'];
        $helper->fields_value['pp_bo_measurement_system'] = $template['pp_bo_measurement_system'];
        $helper->fields_value['pp_bo_hidden'] = $template['pp_bo_hidden'];
        $dimensions = isset($template['pp_ext_method']) && isset($template['pp_ext_prop']) ? count($template['pp_ext_prop']) : 0;
        if ($dimensions == 0) {
            $value = 0;
        } elseif ($dimensions == 1) {
            $value = 3;
        } else {
            $value = $template['pp_ext_method'];
        }
        $helper->fields_value['pp_ext_method'] = $value;
        $helper->fields_value['pp_ext_method_fallback'] = $value;
        $helper->fields_value['pp_ext_policy'] = isset($template['pp_ext_policy']) ? $template['pp_ext_policy'] : 0;
        if ($template['pp_qty_policy'] == 2 && $helper->fields_value['pp_ext_method'] > 0) {
            $helper->fields_value['pp_qty_policy'] = 3;
        } else {
            $helper->fields_value['pp_qty_policy'] = $template['pp_qty_policy'];
        }
        $translations = $this->getTranslations('ppExt');
        $dimensions_form = array('legend' => array('title' => $this->l('Dimensions')), 'multidimensional-feature' => array('text' => $this->l('this feature is disabled if calculation method is not specified'), 'disabled' => $this->l('This feature is disabled. To enable this feature please install the multidimensional plugin from'), 'readme_url' => $this->multidimensional_plugin ? $this->multidimensional_plugin->readme_url() : '', 'readme_pdf' => $this->l('Multidimensional plugin user guide')), 'input' => array(array('type' => 'select', 'label' => $this->l('calculation method'), 'name' => 'pp_ext_method', 'options' => array('query' => array(array('id' => 0, 'name' => '&nbsp;'), array('id' => 1, 'name' => $translations['s_multiplication']), array('id' => 2, 'name' => $translations['s_summation']), array('id' => 3, 'name' => $translations['s_single_dimension'])), 'id' => 'id', 'name' => 'name')), array('type' => 'hidden', 'name' => 'pp_ext_method_fallback'), $this->createHelperFormSelect('pp_ext_title', array('label' => $this->l('dimensions block title'), 'form_group_class' => 'dimensions-toggle'), self::DIMENSIONS, $helper, $template, $all_properties, $property_types), $this->createHelperFormSelect('pp_ext_property', array('label' => $this->l('calculation result label'), 'desc' => $this->l('leave blank to hide calculation result'), 'form_group_class' => 'dimensions-toggle'), self::DIMENSIONS, $helper, $template, $all_properties, $property_types), $this->createHelperFormSelect('pp_ext_text', array('label' => $this->l('calculation result text'), 'form_group_class' => 'dimensions-toggle'), array(self::PROPERTY_TYPE_GENERAL, self::DIMENSIONS), $helper, $template, $all_properties, $property_types), array('type' => 'radio', 'label' => $this->l('dimensions policy'), 'name' => 'pp_ext_policy', 'desc' => $this->l('dimensions can be specified by the customer (default) or used by the packs calculator or used as the product properties affecting price, visible in the shop and editable only in the back office'), 'form_group_class' => 'dimensions-toggle', 'values' => array(array('id' => 'pp_ext_policy_0', 'value' => 0, 'label' => $this->l('default')), array('id' => 'pp_ext_policy_1', 'value' => 1, 'label' => $this->l('packs calculator')), array('id' => 'pp_ext_policy_2', 'value' => 2, 'label' => $this->l('product properties'))))), 'buttons' => $buttons);
        $dimensions_form['dimensions-table'] = array('th' => array($this->l('dimension'), $this->l('quantity text *'), $this->l('minimum quantity'), $this->l('maximum quantity'), $this->l('default quantity'), $this->l('quantity step'), $this->l('quantity ratio'), $this->l('order quantity text **')), 'tbody' => array());
        $max_dimensions = isset($template['pp_ext_prop']) ? count($template['pp_ext_prop']) : 3;
        if ($max_dimensions < 3) {
            $max_dimensions = 3;
        }
        for ($dimension_index = 1; $dimension_index <= $max_dimensions; $dimension_index++) {
            $td = array();
            $value = PP::getTemplateExtProperty($template, $dimension_index, 'property');
            $td[] = $this->createHelperFormSelect('dimension_' . $dimension_index, array('data_type' => 'dimension_', 'data_position' => $dimension_index), self::PROPERTY_TYPE_EXT, $helper, $value, $all_properties, $property_types);
            $value = PP::getTemplateExtProperty($template, $dimension_index, 'text');
            $td[] = $this->createHelperFormSelect('dimension_text_' . $dimension_index, array('data_type' => 'dimension_text_', 'data_position' => $dimension_index), array(self::PROPERTY_TYPE_GENERAL, self::DIMENSIONS), $helper, $value, $all_properties, $property_types);
            $td[] = array('type' => 'text', 'name' => 'dimension_minimum_quantity_' . $dimension_index, 'data_type' => 'dimension_minimum_quantity_', 'data_position' => $dimension_index);
            $td[] = array('type' => 'text', 'name' => 'dimension_maximum_quantity_' . $dimension_index, 'data_type' => 'dimension_maximum_quantity_', 'data_position' => $dimension_index);
            $td[] = array('type' => 'text', 'name' => 'dimension_default_quantity_' . $dimension_index, 'data_type' => 'dimension_default_quantity_', 'data_position' => $dimension_index);
            $td[] = array('type' => 'text', 'name' => 'dimension_qty_step_' . $dimension_index, 'data_type' => 'dimension_qty_step_', 'data_position' => $dimension_index);
            $td[] = array('type' => 'text', 'name' => 'dimension_qty_ratio_' . $dimension_index, 'data_type' => 'dimension_qty_ratio_', 'data_position' => $dimension_index);
            $helper->fields_value['dimension_minimum_quantity_' . $dimension_index] = (double) PP::getTemplateExtProperty($template, $dimension_index, 'minimum_quantity') > 0 ? PP::formatQty(PP::getTemplateExtProperty($template, $dimension_index, 'minimum_quantity')) : '';
            $helper->fields_value['dimension_maximum_quantity_' . $dimension_index] = (double) PP::getTemplateExtProperty($template, $dimension_index, 'maximum_quantity') > 0 ? PP::formatQty(PP::getTemplateExtProperty($template, $dimension_index, 'maximum_quantity')) : '';
            $helper->fields_value['dimension_default_quantity_' . $dimension_index] = (double) PP::getTemplateExtProperty($template, $dimension_index, 'default_quantity') > 0 ? PP::formatQty(PP::getTemplateExtProperty($template, $dimension_index, 'default_quantity')) : '';
            $helper->fields_value['dimension_qty_step_' . $dimension_index] = (double) PP::getTemplateExtProperty($template, $dimension_index, 'qty_step') > 0 ? PP::formatQty(PP::getTemplateExtProperty($template, $dimension_index, 'qty_step')) : '';
            $helper->fields_value['dimension_qty_ratio_' . $dimension_index] = (double) PP::getTemplateExtProperty($template, $dimension_index, 'qty_ratio') > 0 ? PP::formatQty(PP::getTemplateExtProperty($template, $dimension_index, 'qty_ratio')) : '';
            $value = PP::getTemplateExtProperty($template, $dimension_index, 'order_text');
            $td[] = $this->createHelperFormSelect('dimension_order_text_' . $dimension_index, array('data_type' => 'dimension_order_text_', 'data_position' => $dimension_index), array(self::PROPERTY_TYPE_GENERAL, self::DIMENSIONS), $helper, $value, $all_properties, $property_types);
            $dimensions_form['dimensions-table']['tbody'][] = array('tr' => array('td' => $td));
        }
        $dimensions_form['help-block'] = array('class' => 'dimensions-toggle', 'text' => array('*&nbsp;&nbsp;&nbsp;' . $this->l('quantity text is used on the product page in the shop'), '**&nbsp;&nbsp;' . $this->l('order quantity text is used in order and invoice')));
        if ($this->multidimensional_plugin) {
            $dimensions_form['multidimensionalAdmin'] = 'multidimensionalAdmin';
        }
        $forms = array('form' => $form, 'dimensions_form' => $dimensions_form);
        $hook_forms = Hook::exec('ppropertiesAdmin', array('mode' => 'displayEditTemplateForm', 'id_pp_template' => $id), null, true);
        if (is_array($hook_forms)) {
            foreach ($hook_forms as $hook_module => $hook_form) {
                if (isset($hook_form['form'])) {
                    if (!isset($hook_form['form']['buttons'])) {
                        $hook_form['form']['buttons'] = $buttons;
                    }
                    $forms[$hook_module . '_form'] = $hook_form['form'];
                }
            }
        }
        $html = $this->generateForm($helper, $forms, array('id_pp_template' => $id, 'multidimensional' => $this->multidimensional_plugin, 'script' => array('multidimensional')));
        return $html;
    }