public function getCustomListCategoriesEmpty()
    {
        $this->table = 'category';
        $this->lang = true;
        $this->className = 'Category';
        $this->identifier = 'id_category';
        $this->_orderBy = 'id_category';
        $this->_orderWay = 'DESC';
        $this->_list_index = 'index.php?controller=AdminCategories';
        $this->_list_token = Tools::getAdminTokenLite('AdminCategories');
        $this->addRowAction('edit');
        $this->addRowAction('delete');
        $this->addRowAction('view');
        $this->addRowActionSkipList('delete', array(Category::getTopCategory()->id));
        $this->addRowActionSkipList('edit', array(Category::getTopCategory()->id));
        $this->fields_list = array('id_category' => array('title' => $this->l('ID'), 'width' => 50), 'name' => array('title' => $this->l('Name'), 'filter_key' => 'b!name'), 'description' => array('title' => $this->l('Description')), 'active' => array('title' => $this->l('Status'), 'type' => 'bool', 'active' => 'status', 'width' => 50));
        $this->clearFilters();
        $this->_join = Shop::addSqlAssociation('category', 'a');
        $this->_filter = ' AND a.`id_category` NOT IN (
			SELECT DISTINCT(cp.id_category)
			FROM `' . _DB_PREFIX_ . 'category_product` cp
		)
		AND a.`id_category` != ' . (int) Category::getTopCategory()->id;
        $this->tpl_list_vars = array('sub_title' => $this->l('List of empty categories:'));
        return $this->renderList();
    }
 private function getCategories($radio = false)
 {
     $root_category = Category::getRootCategory();
     $root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name);
     $selected_cat = $radio ? array(Category::getRootCategory()->id) : GiveItCategory::getCategories();
     $category_values = array('trads' => array('Root' => $root_category, 'selected' => $this->module_instance->l('selected'), 'Collapse All' => $this->module_instance->l('Collapse All'), 'Expand All' => $this->module_instance->l('Expand All'), 'Check All' => $this->module_instance->l('Check All'), 'Uncheck All' => $this->module_instance->l('Uncheck All')), 'selected_cat' => $selected_cat, 'input_name' => 'categoryBox[]', 'use_radio' => $radio, 'use_search' => false, 'disabled_categories' => array(4), 'top_category' => version_compare(_PS_VERSION_, '1.5', '<') ? $this->getTopCategory() : Category::getTopCategory(), 'use_context' => true);
     $this->context->smarty->assign(array('category_values' => $category_values));
 }
 public function init()
 {
     parent::init();
     // context->shop is set in the init() function, so we move the _category instanciation after that
     if (($id_category = Tools::getvalue('id_category')) && $this->action != 'select_delete') {
         $this->_category = new Category($id_category);
     } else {
         if (Shop::getContext() == Shop::CONTEXT_SHOP) {
             $this->_category = new Category($this->context->shop->id_category);
         } elseif (count(Category::getCategoriesWithoutParent()) > 1 && Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && count(Shop::getShops(true, null, true)) != 1) {
             $this->_category = Category::getTopCategory();
         } else {
             $this->_category = new Category(Configuration::get('PS_HOME_CATEGORY'));
         }
     }
     $count_categories_without_parent = count(Category::getCategoriesWithoutParent());
     if (Tools::isSubmit('id_category')) {
         $id_parent = $this->_category->id;
     } elseif (!Shop::isFeatureActive() && $count_categories_without_parent > 1) {
         $id_parent = (int) Configuration::get('PS_ROOT_CATEGORY');
     } elseif (Shop::isFeatureActive() && $count_categories_without_parent == 1) {
         $id_parent = (int) Configuration::get('PS_HOME_CATEGORY');
     } elseif (Shop::isFeatureActive() && $count_categories_without_parent > 1 && Shop::getContext() != Shop::CONTEXT_SHOP) {
         if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && count(Shop::getShops(true, null, true)) == 1) {
             $id_parent = $this->context->shop->id_category;
         } else {
             $id_parent = (int) Configuration::get('PS_ROOT_CATEGORY');
         }
     } else {
         $id_parent = $this->context->shop->id_category;
     }
     $this->_select = 'sa.position position';
     $this->original_filter = $this->_filter .= ' AND `id_parent` = ' . (int) $id_parent . ' ';
     $this->_use_found_rows = false;
     if (Shop::getContext() == Shop::CONTEXT_SHOP) {
         $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` sa ON (a.`id_category` = sa.`id_category` AND sa.id_shop = ' . (int) $this->context->shop->id . ') ';
     } else {
         $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` sa ON (a.`id_category` = sa.`id_category` AND sa.id_shop = a.id_shop_default) ';
     }
     // we add restriction for shop
     if (Shop::getContext() == Shop::CONTEXT_SHOP && Shop::isFeatureActive()) {
         $this->_where = ' AND sa.`id_shop` = ' . (int) Context::getContext()->shop->id;
     }
     // if we are not in a shop context, we remove the position column
     if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) {
         unset($this->fields_list['position']);
     }
     // shop restriction : if category is not available for current shop, we redirect to the list from default category
     if (Validate::isLoadedObject($this->_category) && !$this->_category->isAssociatedToShop() && Shop::getContext() == Shop::CONTEXT_SHOP) {
         $this->redirect_after = self::$currentIndex . '&id_category=' . (int) $this->context->shop->getCategory() . '&token=' . $this->token;
         $this->redirect();
     }
 }
    /**
     * Get Each parent category of this category until the root category
     *
     * @param integer $id_lang Language ID
     * @return array Corresponding categories
     */
    public function _getParentsCategories($id_current = NULL)
    {
        $context = Context::getContext()->cloneContext();
        $context->shop = clone $context->shop;
        $id_lang = $context->language->id;
        $categories = null;
        if (count(Category::getCategoriesWithoutParent()) > 1 && Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && count(Shop::getShops(true, null, true)) != 1) {
            $context->shop->id_category = Category::getTopCategory()->id;
        } elseif (!$context->shop->id) {
            $context->shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
        }
        $id_shop = $context->shop->id;
        while (true) {
            $sql = '
			SELECT c.*, cl.*
			FROM `' . _DB_PREFIX_ . 'category` c
			LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl
				ON (c.`id_category` = cl.`id_category`
				AND `id_lang` = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl') . ')';
            if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) {
                $sql .= '
			LEFT JOIN `' . _DB_PREFIX_ . 'category_shop` cs
				ON (c.`id_category` = cs.`id_category` AND cs.`id_shop` = ' . (int) $id_shop . ')';
            }
            $sql .= '
			WHERE c.`id_category` = ' . (int) $id_current;
            if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) {
                $sql .= '
				AND cs.`id_shop` = ' . (int) $context->shop->id;
            }
            $root_category = Category::getRootCategory();
            if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP && (!Tools::isSubmit('id_category') || (int) Tools::getValue('id_category') == (int) $root_category->id || (int) $root_category->id == (int) $context->shop->id_category)) {
                $sql .= '
					AND c.`id_parent` != 0';
            }
            $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
            if (isset($result[0])) {
                $categories[] = $result[0];
            } else {
                if (!$categories) {
                    $categories = array();
                }
            }
            if (!$result || $result[0]['id_category'] == $context->shop->id_category) {
                return $categories;
            }
            $id_current = $result[0]['id_parent'];
        }
    }
Example #5
0
/**
 * Return path to a product category
 *
 * @param string $urlBase Start URL
 * @param integer $id_category Start category
 * @param string $path Current path
 * @param string $highlight String to highlight (in XHTML/CSS)
 * @param string $type Category type (products/cms)
 */
function getPath($urlBase, $id_category, $path = '', $highlight = '', $categoryType = 'catalog', $home = false)
{
    $context = Context::getContext();
    if ($categoryType == 'catalog') {
        $category = Db::getInstance()->getRow('
		SELECT id_category, level_depth, nleft, nright
		FROM ' . _DB_PREFIX_ . 'category
		WHERE id_category = ' . (int) $id_category);
        if (isset($category['id_category'])) {
            $sql = 'SELECT c.id_category, cl.name, cl.link_rewrite
					FROM ' . _DB_PREFIX_ . 'category c
					LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = c.id_category' . Shop::addSqlRestrictionOnLang('cl') . ')
					WHERE c.nleft <= ' . (int) $category['nleft'] . '
						AND c.nright >= ' . (int) $category['nright'] . '
						AND cl.id_lang = ' . (int) $context->language->id . ($home ? ' AND c.id_category=' . $id_category : '') . '
						AND c.id_category != ' . (int) Category::getTopCategory()->id . '
					GROUP BY c.id_category
					ORDER BY c.level_depth ASC
					LIMIT ' . (!$home ? (int) ($category['level_depth'] + 1) : 1);
            $categories = Db::getInstance()->executeS($sql);
            $fullPath = '';
            $n = 1;
            $nCategories = (int) sizeof($categories);
            foreach ($categories as $category) {
                $link = Context::getContext()->link->getAdminLink('AdminCategories');
                $edit = '<a href="' . $link . '&id_category=' . (int) $category['id_category'] . '&' . ($category['id_category'] == 1 || $home ? 'viewcategory' : 'updatecategory') . '" title="' . ($category['id_category'] == Category::getRootCategory()->id_category ? 'Home' : 'Modify') . '"><i class="icon-' . ($category['id_category'] == Category::getRootCategory()->id_category || $home ? 'home' : 'pencil') . '"></i></a> ';
                $fullPath .= $edit . ($n < $nCategories ? '<a href="' . $urlBase . '&id_category=' . (int) $category['id_category'] . '&viewcategory&token=' . Tools::getAdminToken('AdminCategories' . (int) Tab::getIdFromClassName('AdminCategories') . (int) $context->employee->id) . '" title="' . htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8') . '">' : '') . (!empty($highlight) ? str_ireplace($highlight, '<span class="highlight">' . htmlentities($highlight, ENT_NOQUOTES, 'UTF-8') . '</span>', $category['name']) : $category['name']) . ($n < $nCategories ? '</a>' : '') . ($n++ != $nCategories || !empty($path) ? ' > ' : '');
            }
            return $fullPath . $path;
        }
    } elseif ($categoryType == 'cms') {
        $category = new CMSCategory($id_category, $context->language->id);
        if (!$category->id) {
            return $path;
        }
        $name = $highlight != null ? str_ireplace($highlight, '<span class="highlight">' . $highlight . '</span>', CMSCategory::hideCMSCategoryPosition($category->name)) : CMSCategory::hideCMSCategoryPosition($category->name);
        $edit = '<a href="' . $urlBase . '&id_cms_category=' . $category->id . '&addcategory&token=' . Tools::getAdminToken('AdminCmsContent' . (int) Tab::getIdFromClassName('AdminCmsContent') . (int) $context->employee->id) . '">
				<i class="icon-pencil"></i></a> ';
        if ($category->id == 1) {
            $edit = '<li><a href="' . $urlBase . '&id_cms_category=' . $category->id . '&viewcategory&token=' . Tools::getAdminToken('AdminCmsContent' . (int) Tab::getIdFromClassName('AdminCmsContent') . (int) $context->employee->id) . '">
					<i class="icon-home"></i></a></li> ';
        }
        $path = $edit . '<li><a href="' . $urlBase . '&id_cms_category=' . $category->id . '&viewcategory&token=' . Tools::getAdminToken('AdminCmsContent' . (int) Tab::getIdFromClassName('AdminCmsContent') . (int) $context->employee->id) . '">
		' . $name . '</a></li> > ' . $path;
        if ($category->id == 1) {
            return substr($path, 0, strlen($path) - 3);
        }
        return getPath($urlBase, $category->id_parent, $path, '', 'cms');
    }
}
Example #6
0
 public static function getRootCategory($id_lang = null, Shop $shop = null)
 {
     $context = Context::getContext();
     if (is_null($id_lang)) {
         $id_lang = $context->language->id;
     }
     if (!$shop) {
         if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) {
             $shop = new Shop(Configuration::get('PS_SHOP_DEFAULT'));
         } else {
             $shop = $context->shop;
         }
     } else {
         return new Category($shop->getCategory(), $id_lang);
     }
     $is_more_than_one_root_category = count(Category::getCategoriesWithoutParent()) > 1;
     if (Shop::isFeatureActive() && $is_more_than_one_root_category && Shop::getContext() != Shop::CONTEXT_SHOP) {
         $category = Category::getTopCategory($id_lang);
     } else {
         $category = new Category($shop->getCategory(), $id_lang);
     }
     return $category;
 }
    /**
     *
     * @param array $root array with the name and ID of the tree root category, if null the Shop's root category will be used
     * @param type $selected_cat array of selected categories
     *					Format
     *						Array
     * 					(
     *							 [0] => 1
     *						 [1] => 2
     *					)
     * 					OR
     *					Array
     *					(
     *						 [1] => Array
     *							  (
     *									[id_category] => 1
     *									[name] => Home page
     *							  )
     *					)
     * @param string $input_name name of input
     * @param bool $use_radio use radio tree or checkbox tree
     * @param bool $use_search display a find category search box
     * @param array $disabled_categories
     * @param bool $use_in_popup
     * @param bool $use_shop_context
     * @return string
     */
    public function renderCategoryTree($root = null, $selected_cat = array(), $input_name = 'categoryBox', $use_radio = false, $use_search = false, $disabled_categories = array(), $use_in_popup = false, $use_shop_context = false)
    {
        $translations = array('selected' => $this->l('Selected'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All'), 'Check All' => $this->l('Check All'), 'Uncheck All' => $this->l('Uncheck All'), 'search' => $this->l('Find a category'));
        $top_category = Category::getTopCategory();
        if (Tools::isSubmit('id_shop')) {
            $id_shop = Tools::getValue('id_shop');
        } else {
            if (Context::getContext()->shop->id) {
                $id_shop = Context::getContext()->shop->id;
            } else {
                if (!Shop::isFeatureActive()) {
                    $id_shop = Configuration::get('PS_SHOP_DEFAULT');
                } else {
                    $id_shop = 0;
                }
            }
        }
        $shop = new Shop($id_shop);
        $root_category = Category::getRootCategory(null, $shop);
        $disabled_categories[] = $top_category->id;
        if (!$root) {
            $root = array('name' => $root_category->name, 'id_category' => $root_category->id);
        }
        if (!$use_radio) {
            $input_name = $input_name . '[]';
        }
        if ($use_search) {
            $this->context->controller->addJs(_PS_JS_DIR_ . 'jquery/plugins/autocomplete/jquery.autocomplete.js');
        }
        $html = '
		<script type="text/javascript">
			var inputName = \'' . addcslashes($input_name, '\'') . '\';' . "\n";
        if (count($selected_cat) > 0) {
            if (isset($selected_cat[0])) {
                $html .= '			var selectedCat = "' . implode(',', array_map('intval', $selected_cat)) . '";' . "\n";
            } else {
                $html .= '			var selectedCat = "' . implode(',', array_map('intval', array_keys($selected_cat))) . '";' . "\n";
            }
        } else {
            $html .= '			var selectedCat = \'\';' . "\n";
        }
        $html .= '			var selectedLabel = \'' . $translations['selected'] . '\';
			var home = \'' . addcslashes($root['name'], '\'') . '\';
			var use_radio = ' . (int) $use_radio . ';';
        $html .= '</script>';
        $html .= '
		<div class="category-filter">
			<a class="btn btn-link" href="#" id="collapse_all"><i class="icon-collapse"></i> ' . $translations['Collapse All'] . '</a>
			<a class="btn btn-link" href="#" id="expand_all"><i class="icon-expand"></i> ' . $translations['Expand All'] . '</a>
			' . (!$use_radio ? '
				<a class="btn btn-link" href="#" id="check_all"><i class="icon-check"></i> ' . $translations['Check All'] . '</a>
				<a class="btn btn-link" href="#" id="uncheck_all"><i class="icon-check-empty"></i> ' . $translations['Uncheck All'] . '</a>' : '') . ($use_search ? '
				<div class="row">
					<label class="control-label col-lg-6" for="search_cat">' . $translations['search'] . ' :</label>
					<div class="col-lg-6">
						<input type="text" name="search_cat" id="search_cat"/>
					</div>
				</div>' : '') . '</div>';
        $home_is_selected = false;
        foreach ($selected_cat as $cat) {
            if (is_array($cat)) {
                $disabled = in_array($cat['id_category'], $disabled_categories);
                if ($cat['id_category'] != $root['id_category']) {
                    $html .= '<input ' . ($disabled ? 'disabled="disabled"' : '') . ' type="hidden" name="' . $input_name . '" value="' . $cat['id_category'] . '" >';
                } else {
                    $home_is_selected = true;
                }
            } else {
                $disabled = in_array($cat, $disabled_categories);
                if ($cat != $root['id_category']) {
                    $html .= '<input ' . ($disabled ? 'disabled="disabled"' : '') . ' type="hidden" name="' . $input_name . '" value="' . $cat . '" >';
                } else {
                    $home_is_selected = true;
                }
            }
        }
        $root_input = '';
        if ($root['id_category'] != $top_category->id || Tools::isSubmit('ajax') && Tools::getValue('action') == 'getCategoriesFromRootCategory') {
            $root_input = '
				<p class="checkbox"><i class="icon-folder-open"></i><label>
					<input type="' . (!$use_radio ? 'checkbox' : 'radio') . '" name="' . $input_name . '" value="' . $root['id_category'] . '" ' . ($home_is_selected ? 'checked' : '') . ' onclick="clickOnCategoryBox($(this));" />' . $root['name'] . '</label></p>';
        }
        $html .= '
			<div class="container">
				<div class="well">
					<ul id="categories-treeview">
						<li id="' . $root['id_category'] . '" class="hasChildren">
							<span class="folder">' . $root_input . ' </span>
							<ul>
								<li><span class="placeholder">&nbsp;</span></li>
						  	</ul>
						</li>
					</ul>
				</div>
			</div>';
        if ($use_search) {
            $html .= '<script type="text/javascript">searchCategory();</script>';
        }
        return $html;
    }
 function renderCriterionForm($id_criterion = 0)
 {
     $types = ProductCommentCriterion::getTypes();
     $query = array();
     foreach ($types as $key => $value) {
         $query[] = array('id' => $key, 'label' => $value);
     }
     $criterion = new ProductCommentCriterion((int) $id_criterion);
     $selected_categories = $criterion->getCategories();
     $product_table_values = Product::getSimpleProducts($this->context->language->id);
     $selected_products = $criterion->getProducts();
     foreach ($product_table_values as $key => $product) {
         if (false !== array_search($product['id_product'], $selected_products)) {
             $product_table_values[$key]['selected'] = 1;
         }
     }
     if (version_compare(_PS_VERSION_, '1.6', '<')) {
         $field_category_tree = array('type' => 'categories_select', 'name' => 'categoryBox', 'label' => $this->l('Criterion will be restricted to the following categories'), 'category_tree' => $this->initCategoriesAssociation(null, $id_criterion));
     } else {
         $field_category_tree = array('type' => 'categories', 'label' => $this->l('Criterion will be restricted to the following categories'), 'name' => 'categoryBox', 'desc' => $this->l('Mark the boxes of categories to which this criterion applies.'), 'tree' => array('use_search' => false, 'id' => 'categoryBox', 'use_checkbox' => true, 'selected_categories' => $selected_categories), 'values' => array('trads' => array('Root' => Category::getTopCategory(), 'selected' => $this->l('Selected'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All'), 'Check All' => $this->l('Check All'), 'Uncheck All' => $this->l('Uncheck All')), 'selected_cat' => $selected_categories, 'input_name' => 'categoryBox[]', 'use_radio' => false, 'use_search' => false, 'disabled_categories' => array(), 'top_category' => Category::getTopCategory(), 'use_context' => true));
     }
     $fields_form_1 = array('form' => array('legend' => array('title' => $this->l('Add new criterion'), 'icon' => 'icon-cogs'), 'input' => array(array('type' => 'hidden', 'name' => 'id_product_comment_criterion'), array('type' => 'text', 'lang' => true, 'label' => $this->l('Criterion name'), 'name' => 'name'), array('type' => 'select', 'name' => 'id_product_comment_criterion_type', 'label' => $this->l('Application scope of the criterion'), 'options' => array('query' => $query, 'id' => 'id', 'name' => 'label')), $field_category_tree, array('type' => 'products', 'label' => $this->l('The criterion will be restricted to the following products'), 'name' => 'ids_product', 'values' => $product_table_values), array('type' => 'switch', 'is_bool' => true, 'label' => $this->l('Active'), 'name' => 'active', 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))))), 'submit' => array('title' => $this->l('Save'), 'class' => 'btn btn-default pull-right', 'name' => 'submitEditCriterion')));
     $helper = new HelperForm();
     $helper->show_toolbar = false;
     $helper->table = $this->name;
     $lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
     $helper->default_form_language = $lang->id;
     $helper->module = $this;
     $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 = 'submitEditCriterion';
     $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->getCriterionFieldsValues($id_criterion), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id);
     return $helper->generateForm(array($fields_form_1));
 }
 public function processAdd()
 {
     $id_category = (int) Tools::getValue('id_category');
     $id_parent = (int) Tools::getValue('id_parent');
     // if true, we are in a root category creation
     if (!$id_parent) {
         $_POST['is_root_category'] = $_POST['level_depth'] = 1;
         $_POST['id_parent'] = $id_parent = (int) Configuration::get('PS_ROOT_CATEGORY');
     }
     if ($id_category) {
         if ($id_category != $id_parent) {
             if (!Category::checkBeforeMove($id_category, $id_parent)) {
                 $this->errors[] = Tools::displayError('The category cannot be moved here.');
             }
         } else {
             $this->errors[] = Tools::displayError('The category cannot be a parent of itself.');
         }
     }
     $object = parent::processAdd();
     //if we create a you root category you have to associate to a shop before to add sub categories in. So we redirect to AdminCategories listing
     if ($object && Tools::getValue('is_root_category')) {
         Tools::redirectAdmin(self::$currentIndex . '&id_category=' . (int) Category::getTopCategory()->id . '&token=' . Tools::getAdminTokenLite('AdminCategories') . '&conf=3');
     }
     return $object;
 }
Example #10
0
 public function getProductsSelectForm()
 {
     $root_category = Category::getRootCategory();
     $root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name);
     $selected_cat = Tools::getValue('id_category', Category::getRootCategory()->id);
     $category_values = array('trads' => array('Root' => $root_category, 'selected' => $this->module_instance->l('selected', 'project.view'), 'Collapse All' => $this->module_instance->l('Collapse All', 'project.view'), 'Expand All' => $this->module_instance->l('Expand All', 'project.view')), 'selected_cat' => array($selected_cat), 'input_name' => 'id_category', 'use_radio' => true, 'use_search' => false, 'disabled_categories' => array(4), 'top_category' => version_compare(_PS_VERSION_, '1.5', '<') ? $this->module_instance->getTopCategory() : Category::getTopCategory(), 'use_context' => true);
     $this->context->smarty->assign(array('category_values' => $category_values));
 }
 public function renderForm()
 {
     $this->initToolbar();
     $obj = $this->loadObject(true);
     $id_shop = Context::getContext()->shop->id;
     $selected_categories = array(isset($obj->id_parent) && $obj->isParentCategoryAvailable($id_shop) ? (int) $obj->id_parent : (int) Tools::getValue('id_parent', Category::getRootCategory()->id));
     $unidentified = new Group(Configuration::get('PS_UNIDENTIFIED_GROUP'));
     $guest = new Group(Configuration::get('PS_GUEST_GROUP'));
     $default = new Group(Configuration::get('PS_CUSTOMER_GROUP'));
     $unidentified_group_information = sprintf($this->l('%s - All people without a valid customer account.'), '<b>' . $unidentified->name[$this->context->language->id] . '</b>');
     $guest_group_information = sprintf($this->l('%s - Customer who placed an order with the guest checkout.'), '<b>' . $guest->name[$this->context->language->id] . '</b>');
     $default_group_information = sprintf($this->l('%s - All people who have created an account on this site.'), '<b>' . $default->name[$this->context->language->id] . '</b>');
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     $image = _PS_CAT_IMG_DIR_ . $obj->id . '.jpg';
     $image_url = ImageManager::thumbnail($image, $this->table . '_' . (int) $obj->id . '.' . $this->imageType, 350, $this->imageType, true, true);
     $image_size = file_exists($image) ? filesize($image) / 1000 : false;
     $this->fields_form = array('tinymce' => true, 'legend' => array('title' => $this->l('Category'), 'icon' => 'icon-tags'), 'input' => array(array('type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'lang' => true, 'required' => true, 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'switch', 'label' => $this->l('Displayed'), 'name' => 'active', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'categories', 'label' => $this->l('Parent category'), 'name' => 'id_parent', 'tree' => array('id' => 'categories-tree', 'selected_categories' => $selected_categories, 'disabled_categories' => !Tools::isSubmit('add' . $this->table) ? array($this->_category->id) : null)), array('type' => 'textarea', 'label' => $this->l('Description'), 'name' => 'description', 'autoload_rte' => true, 'lang' => true, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'file', 'label' => $this->l('Image'), 'name' => 'image', 'display_image' => true, 'image' => $image_url ? $image_url : false, 'size' => $image_size, 'delete_url' => self::$currentIndex . '&' . $this->identifier . '=' . $this->_category->id . '&token=' . $this->token . '&deleteImage=1', 'hint' => $this->l('Upload a category logo from your computer.')), array('type' => 'text', 'label' => $this->l('Meta title'), 'name' => 'meta_title', 'lang' => true, 'hint' => $this->l('Forbidden characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => $this->l('Meta description'), 'name' => 'meta_description', 'lang' => true, 'hint' => $this->l('Forbidden characters:') . ' <>;=#{}'), array('type' => 'tags', 'label' => $this->l('Meta keywords'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => $this->l('To add "tags," click in the field, write something, and then press "Enter."') . '&nbsp;' . $this->l('Forbidden characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => $this->l('Friendly URL'), 'name' => 'link_rewrite', 'lang' => true, 'required' => true, 'hint' => $this->l('Only letters, numbers, underscore (_) and the minus (-) character are allowed.')), array('type' => 'group', 'label' => $this->l('Group access'), 'name' => 'groupBox', 'values' => Group::getGroups(Context::getContext()->language->id), 'info_introduction' => $this->l('You now have three default customer groups.'), 'unidentified' => $unidentified_group_information, 'guest' => $guest_group_information, 'customer' => $default_group_information, 'hint' => $this->l('Mark all of the customer groups which you would like to have access to this category.'))), 'submit' => array('title' => $this->l('Save'), 'name' => 'submitAdd' . $this->table . 'AndBackToParent'));
     $this->tpl_form_vars['shared_category'] = Validate::isLoadedObject($obj) && $obj->hasMultishopEntries();
     $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL');
     $this->tpl_form_vars['displayBackOfficeCategory'] = Hook::exec('displayBackOfficeCategory');
     // Display this field only if multistore option is enabled
     if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && Tools::isSubmit('add' . $this->table . 'root')) {
         $this->fields_form['input'][] = array('type' => 'switch', 'label' => $this->l('Root Category'), 'name' => 'is_root_category', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'is_root_on', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'is_root_off', 'value' => 0, 'label' => $this->l('No'))));
         unset($this->fields_form['input'][2], $this->fields_form['input'][3]);
     }
     // Display this field only if multistore option is enabled AND there are several stores configured
     if (Shop::isFeatureActive()) {
         $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association'), 'name' => 'checkBoxShopAsso');
     }
     // remove category tree and radio button "is_root_category" if this category has the root category as parent category to avoid any conflict
     if ($this->_category->id_parent == Category::getTopCategory()->id && Tools::isSubmit('updatecategory')) {
         foreach ($this->fields_form['input'] as $k => $input) {
             if (in_array($input['name'], array('id_parent', 'is_root_category'))) {
                 unset($this->fields_form['input'][$k]);
             }
         }
     }
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     $image = ImageManager::thumbnail(_PS_CAT_IMG_DIR_ . '/' . $obj->id . '.jpg', $this->table . '_' . (int) $obj->id . '.' . $this->imageType, 350, $this->imageType, true);
     $this->fields_value = array('image' => $image ? $image : false, 'size' => $image ? filesize(_PS_CAT_IMG_DIR_ . '/' . $obj->id . '.jpg') / 1000 : false);
     // Added values of object Group
     $category_groups_ids = $obj->getGroups();
     $groups = Group::getGroups($this->context->language->id);
     // if empty $carrier_groups_ids : object creation : we set the default groups
     if (empty($category_groups_ids)) {
         $preselected = array(Configuration::get('PS_UNIDENTIFIED_GROUP'), Configuration::get('PS_GUEST_GROUP'), Configuration::get('PS_CUSTOMER_GROUP'));
         $category_groups_ids = array_merge($category_groups_ids, $preselected);
     }
     foreach ($groups as $group) {
         $this->fields_value['groupBox_' . $group['id_group']] = Tools::getValue('groupBox_' . $group['id_group'], in_array($group['id_group'], $category_groups_ids));
     }
     $this->fields_value['is_root_category'] = (bool) Tools::isSubmit('add' . $this->table . 'root');
     return parent::renderForm();
 }
Example #12
0
 public function renderForm()
 {
     $order_states = OrderState::getOrderStates($this->context->language->id);
     $currency = new Currency((int) Configuration::get('PS_CURRENCY_DEFAULT'));
     $root_category = Category::getRootCategory();
     $root_category = array('id_category' => $root_category->id, 'name' => $root_category->name);
     if (Tools::getValue('categoryBoxSource')) {
         $selected_categories_source = Tools::getValue('categoryBoxSource');
     } else {
         $selected_categories_source = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY_SOURCE'));
     }
     if (Tools::getValue('categoryBox')) {
         $selected_categories = Tools::getValue('categoryBox');
     } else {
         $selected_categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY'));
     }
     $fields_form_1 = array('form' => array('legend' => array('title' => $this->l('Settings'), 'icon' => 'icon-cogs'), 'input' => array(array('type' => 'text', 'label' => $this->l('Ratio'), 'name' => 'point_rate', 'prefix' => $currency->sign, 'suffix' => $this->l('= 1 reward point.')), array('type' => 'text', 'label' => $this->l('1 point ='), 'name' => 'point_value', 'prefix' => $currency->sign, 'suffix' => $this->l('for the discount.')), array('type' => 'text', 'label' => $this->l('1 point ='), 'name' => 'point_percent', 'prefix' => '%'), array('type' => 'text', 'label' => $this->l('Validity period of a point'), 'name' => 'validity_period', 'suffix' => $this->l('days')), array('type' => 'text', 'label' => $this->l('Voucher details'), 'name' => 'voucher_details', 'lang' => true), array('type' => 'text', 'label' => $this->l('Minimum amount in which the voucher can be used'), 'name' => 'minimal', 'prefix' => $currency->sign, 'class' => 'fixed-width-sm'), array('type' => 'switch', 'is_bool' => true, 'label' => $this->l('Apply taxes on the voucher'), 'name' => 'PS_LOYALTY_TAX', 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'select', 'label' => $this->l('Points are awarded when the order is'), 'name' => 'id_order_state_validation', 'options' => array('query' => $order_states, 'id' => 'id_order_state', 'name' => 'name')), array('type' => 'select', 'label' => $this->l('Points are cancelled when the order is'), 'name' => 'id_order_state_cancel', 'options' => array('query' => $order_states, 'id' => 'id_order_state', 'name' => 'name')), array('type' => 'switch', 'is_bool' => true, 'label' => $this->l('Give points on discounted products'), 'name' => 'PS_LOYALTY_NONE_AWARD', 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'categories', 'label' => $this->l('The following categories can be used for generate loyalty points:'), 'name' => 'categoryBoxSource', 'desc' => $this->l('Mark the boxes of categories which generates loyalty points.'), 'tree' => array('use_search' => false, 'id' => 'categoryBoxSource', 'use_checkbox' => true, 'selected_categories' => $selected_categories_source), 'values' => array('trads' => array('Root' => $root_category, 'selected' => $this->l('Selected'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All'), 'Check All' => $this->l('Check All'), 'Uncheck All' => $this->l('Uncheck All')), 'selected_cat' => $selected_categories_source, 'input_name' => 'categoryBoxSource[]', 'use_radio' => false, 'use_search' => false, 'disabled_categories' => array(), 'top_category' => Category::getTopCategory(), 'use_context' => true)), array('type' => 'categories', 'label' => $this->l('Vouchers created by the loyalty system can be used in the following categories:'), 'name' => 'categoryBox', 'desc' => $this->l('Mark the boxes of categories in which loyalty vouchers can be used.'), 'tree' => array('use_search' => false, 'id' => 'categoryBox', 'use_checkbox' => true, 'selected_categories' => $selected_categories), 'values' => array('trads' => array('Root' => $root_category, 'selected' => $this->l('Selected'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All'), 'Check All' => $this->l('Check All'), 'Uncheck All' => $this->l('Uncheck All')), 'selected_cat' => $selected_categories, 'input_name' => 'categoryBox[]', 'use_radio' => false, 'use_search' => false, 'disabled_categories' => array(), 'top_category' => Category::getTopCategory(), 'use_context' => true)), array('type' => 'switch', 'is_bool' => true, 'label' => $this->l('Auto-voucher'), 'desc' => $this->l('Create voucher automatically on order state change.'), 'name' => 'PS_LOYALTY_AUTOVOUCHER', 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'switch', 'is_bool' => true, 'label' => $this->l('Send e-mail on auto-voucher'), 'desc' => $this->l('Send e-mail to customer when new voucher is created.'), 'name' => 'PS_LOYALTY_AUTOVOUCHER_EMAIL', 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))))), 'submit' => array('title' => $this->l('Save'))));
     $fields_form_2 = array('form' => array('legend' => array('title' => $this->l('Loyalty points progression'), 'icon' => 'icon-cogs'), 'input' => array(array('type' => 'text', 'label' => $this->l('Initial'), 'name' => 'default_loyalty_state', 'lang' => true), array('type' => 'text', 'label' => $this->l('Unavailable'), 'name' => 'none_award_loyalty_state', 'lang' => true), array('type' => 'text', 'label' => $this->l('Converted'), 'name' => 'convert_loyalty_state', 'lang' => true), array('type' => 'text', 'label' => $this->l('Validation'), 'name' => 'validation_loyalty_state', 'lang' => true), array('type' => 'text', 'label' => $this->l('Cancelled'), 'name' => 'cancel_loyalty_state', 'lang' => true)), 'submit' => array('title' => $this->l('Save'))));
     $helper = new HelperForm();
     $helper->module = $this;
     $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 = 'submitLoyalty';
     $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_1, $fields_form_2));
 }
 public function renderForm()
 {
     $this->initToolbar();
     $obj = $this->loadObject(true);
     $id_shop = Context::getContext()->shop->id;
     $selected_categories = array(isset($obj->id_parent) && $obj->isParentCategoryAvailable($id_shop) ? (int) $obj->id_parent : (int) Tools::getValue('id_parent', Category::getRootCategory()->id));
     $unidentified = new Group(Configuration::get('PS_UNIDENTIFIED_GROUP'));
     $guest = new Group(Configuration::get('PS_GUEST_GROUP'));
     $default = new Group(Configuration::get('PS_CUSTOMER_GROUP'));
     $unidentified_group_information = sprintf($this->l('%s - All people without a valid customer account.'), '<b>' . $unidentified->name[$this->context->language->id] . '</b>');
     $guest_group_information = sprintf($this->l('%s - Customer who placed an order with the guest checkout.'), '<b>' . $guest->name[$this->context->language->id] . '</b>');
     $default_group_information = sprintf($this->l('%s - All people who have created an account on this site.'), '<b>' . $default->name[$this->context->language->id] . '</b>');
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     $image = _PS_CAT_IMG_DIR_ . $obj->id . '.jpg';
     $image_url = ImageManager::thumbnail($image, $this->table . '_' . (int) $obj->id . '.' . $this->imageType, 350, $this->imageType, true, true);
     $image_size = file_exists($image) ? filesize($image) / 1000 : false;
     $imageType = 'png';
     $image_icon = _PS_IMG_DIR_ . '/c_icon/' . $obj->id . '.png';
     if (!file_exists($image_icon)) {
         $imageType = 'jpg';
         $image_icon = _PS_IMG_DIR_ . '/c_icon/' . $obj->id . '.jpg';
     }
     if (file_exists($image_icon)) {
         $image_url_icon = ImageManager::thumbnail($image_icon, (int) $obj->id . '.' . $imageType, 50, $imageType, true, true);
         $image_size_icon = file_exists($image_icon) ? filesize($image_icon) / 1000 : false;
     } else {
         $image_url_icon = '';
         $image_size_icon = false;
     }
     $cities = Db::getInstance()->executeS("\n            SELECT `c`.`id_city`,`cl`.`name`\n            FROM `" . _DB_PREFIX_ . "city` `c`\n            LEFT JOIN `" . _DB_PREFIX_ . "city_lang` `cl` ON (`c`.`id_city`=`cl`.`id_city`)\n            WHERE `cl`.`id_lang` = 1 AND `c`.`rg`<>''\n            ORDER BY `c`.`sort` DESC, `cl`.`name`\n        ");
     /*        $cities_j=array();
             foreach($cities as $val){
                 array_push($cities_j[$val['id_city']],0);
                 $cities_j[$val['id_city']]=$val['name'];
             }*/
     $cities = json_encode($cities);
     //  print_r($cities);exit();
     $this->fields_form = array('tinymce' => true, 'legend' => array('title' => $this->l('Category'), 'icon' => 'icon-tags'), 'input' => array(array('type' => 'text', 'label' => $this->l('Name'), 'name' => 'name', 'lang' => true, 'required' => true, 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => $this->l('Title name'), 'name' => 'title_name', 'lang' => true, 'required' => false, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => $this->l('Стоимость доставки для товаров данной категории'), 'name' => 'price_category', 'required' => false, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'price_city_type', 'label' => $this->l('Добавить уникальную цену для города?'), 'name' => 'prices_city', 'required' => false, 'cities' => $cities), array('type' => 'switch', 'label' => 'Общая', 'name' => 'is_all', 'hint' => $this->l('Это общая категория'), 'values' => array(array('id' => 'is_all_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" />'), array('id' => 'is_all_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" />'))), array('type' => 'switch', 'label' => 'Выводить ссылкой', 'name' => 'is_link', 'hint' => $this->l('Если отключено то в левом меню по клику на категорию разворачиваются дочерние категории.'), 'values' => array(array('id' => 'is_link_on', 'value' => 1, 'label' => '<img src="../img/admin/enabled.gif" alt="' . $this->l('Enabled') . '" title="' . $this->l('Enabled') . '" />'), array('id' => 'is_link_off', 'value' => 0, 'label' => '<img src="../img/admin/disabled.gif" alt="' . $this->l('Disabled') . '" title="' . $this->l('Disabled') . '" />'))), array('type' => 'switch', 'label' => $this->l('Displayed'), 'name' => 'active', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'switch', 'label' => $this->l('Hide_on_menu'), 'name' => 'hide_on_menu', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'switch', 'label' => $this->l('Скрыть в левом меню?'), 'name' => 'hide_on_left', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'switch', 'label' => $this->l('Относится к комплектам'), 'name' => 'refers_to_decor', 'hint' => $this->l('Товары данной категории относятся к декоративным комплектам.'), 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'categories', 'label' => $this->l('Parent category'), 'name' => 'id_parent', 'tree' => array('id' => 'categories-tree', 'selected_categories' => $selected_categories, 'disabled_categories' => !Tools::isSubmit('add' . $this->table) ? array($this->_category->id) : null)), array('type' => 'textarea', 'label' => $this->l('Description'), 'name' => 'description', 'autoload_rte' => true, 'lang' => true, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'file', 'label' => $this->l('Image'), 'name' => 'image', 'display_image' => true, 'image' => $image_url ? $image_url : false, 'size' => $image_size, 'delete_url' => self::$currentIndex . '&' . $this->identifier . '=' . $this->_category->id . '&token=' . $this->token . '&deleteImage=1', 'hint' => $this->l('Upload a category logo from your computer.')), array('type' => 'file', 'label' => $this->l('Иконка габаритов'), 'name' => 'image_icon', 'display_image' => true, 'image' => $image_url_icon ? $image_url_icon : false, 'size' => $image_size_icon, 'delete_url' => self::$currentIndex . '&' . $this->identifier . '=' . $this->_category->id . '&token=' . $this->token . '&deleteImageIcon=1', 'hint' => $this->l('Upload a category logo from your computer.')), array('type' => 'text', 'label' => $this->l('Meta title'), 'name' => 'meta_title', 'lang' => true, 'hint' => $this->l('Forbidden characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => $this->l('Meta description'), 'name' => 'meta_description', 'lang' => true, 'hint' => $this->l('Forbidden characters:') . ' <>;=#{}'), array('type' => 'tags', 'label' => $this->l('Meta keywords'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => $this->l('To add "tags," click in the field, write something, and then press "Enter."') . '&nbsp;' . $this->l('Forbidden characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => $this->l('Friendly URL'), 'name' => 'link_rewrite', 'lang' => true, 'required' => true, 'hint' => $this->l('Only letters, numbers, underscore (_) and the minus (-) character are allowed.')), array('type' => 'group', 'label' => $this->l('Group access'), 'name' => 'groupBox', 'values' => Group::getGroups(Context::getContext()->language->id), 'info_introduction' => $this->l('You now have three default customer groups.'), 'unidentified' => $unidentified_group_information, 'guest' => $guest_group_information, 'customer' => $default_group_information, 'hint' => $this->l('Mark all of the customer groups which you would like to have access to this category.'))), 'submit' => array('title' => $this->l('Save'), 'name' => 'submitAdd' . $this->table . 'AndBackToParent'));
     $this->tpl_form_vars['shared_category'] = Validate::isLoadedObject($obj) && $obj->hasMultishopEntries();
     $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL');
     $this->tpl_form_vars['displayBackOfficeCategory'] = Hook::exec('displayBackOfficeCategory');
     // Display this field only if multistore option is enabled
     if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && Tools::isSubmit('add' . $this->table . 'root')) {
         $this->fields_form['input'][] = array('type' => 'switch', 'label' => $this->l('Root Category'), 'name' => 'is_root_category', 'required' => false, 'is_bool' => true, 'values' => array(array('id' => 'is_root_on', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'is_root_off', 'value' => 0, 'label' => $this->l('No'))));
         unset($this->fields_form['input'][2], $this->fields_form['input'][3]);
     }
     // Display this field only if multistore option is enabled AND there are several stores configured
     if (Shop::isFeatureActive()) {
         $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association'), 'name' => 'checkBoxShopAsso');
     }
     // remove category tree and radio button "is_root_category" if this category has the root category as parent category to avoid any conflict
     if ($this->_category->id_parent == Category::getTopCategory()->id && Tools::isSubmit('updatecategory')) {
         foreach ($this->fields_form['input'] as $k => $input) {
             if (in_array($input['name'], array('id_parent', 'is_root_category'))) {
                 unset($this->fields_form['input'][$k]);
             }
         }
     }
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     $image = ImageManager::thumbnail(_PS_CAT_IMG_DIR_ . '/' . $obj->id . '.jpg', $this->table . '_' . (int) $obj->id . '.' . $this->imageType, 350, $this->imageType, true);
     $this->fields_value = array('image' => $image ? $image : false, 'size' => $image ? filesize(_PS_CAT_IMG_DIR_ . '/' . $obj->id . '.jpg') / 1000 : false);
     // Added values of object Group
     $category_groups_ids = $obj->getGroups();
     $groups = Group::getGroups($this->context->language->id);
     // if empty $carrier_groups_ids : object creation : we set the default groups
     if (empty($category_groups_ids)) {
         $preselected = array(Configuration::get('PS_UNIDENTIFIED_GROUP'), Configuration::get('PS_GUEST_GROUP'), Configuration::get('PS_CUSTOMER_GROUP'));
         $category_groups_ids = array_merge($category_groups_ids, $preselected);
     }
     foreach ($groups as $group) {
         $this->fields_value['groupBox_' . $group['id_group']] = Tools::getValue('groupBox_' . $group['id_group'], in_array($group['id_group'], $category_groups_ids));
     }
     $this->fields_value['is_root_category'] = (bool) Tools::isSubmit('add' . $this->table . 'root');
     return parent::renderForm();
 }
Example #14
0
 public function renderForm()
 {
     $this->context->controller->addCSS($this->_path . 'css/yamarket.css', 'all');
     $this->context->controller->addJS($this->_path . 'js/yamarket.js', 'all');
     $offer_type = Tools::getValue('YAMARKET_EXPORT_TYPE', Configuration::get('YAMARKET_EXPORT_TYPE'));
     $root_category = Category::getRootCategory();
     if (!$root_category->id) {
         $root_category->id = 0;
         $root_category->name = $this->l('Root');
     }
     $root_category = array('id_category' => (int) $root_category->id, 'name' => $root_category->name);
     $selected_cat = array();
     foreach (Tools::getValue('categoryBox', $this->selected_cats) as $row) {
         $selected_cat[] = $row;
     }
     $fields_form = array('form' => array('legend' => array('title' => $this->l('Settings'), 'icon' => 'icon-cogs'), 'input' => array(array('type' => 'text', 'label' => $this->l('Company Name'), 'name' => 'YAMARKET_COMPANY_NAME', 'required' => true), array('type' => 'text', 'label' => $this->l('Local delivery cost'), 'name' => 'YAMARKET_DELIVERY_PRICE', 'required' => true), array('type' => 'radio', 'label' => $this->l('Description'), 'name' => 'YAMARKET_DESC_TYPE', 'class' => 't', 'values' => array(array('id' => 'YAMARKET_DESC_TYPE_normal', 'value' => 0, 'label' => $this->l('Normal')), array('id' => 'YAMARKET_DESC_TYPE_short', 'value' => 1, 'label' => $this->l('Short')))), array('type' => 'radio', 'label' => $this->l('Offer type'), 'name' => 'YAMARKET_EXPORT_TYPE', 'class' => 't', 'desc' => '<p style="clear:both">' . $this->l('Offer type, see descriptions on') . '<br>
                                <a class="action_module" href="http://help.yandex.ru/partnermarket/offers.xml#base">http://help.yandex.ru/partnermarket/offers.xml#base</a><br>
                                <a class="action_module" href="http://help.yandex.ru/partnermarket/offers.xml#vendor">http://help.yandex.ru/partnermarket/offers.xml#vendor</a>
                                </p>', 'values' => array(array('id' => 'YAMARKET_EXPORT_TYPE_simple', 'value' => 0, 'label' => $this->l('Simplified')), array('id' => 'YAMARKET_EXPORT_TYPE_vendor', 'value' => 1, 'label' => $this->l('Vendor.model')))), array('type' => 'text', 'label' => $this->l('Country of origin attribute name'), 'name' => 'YAMARKET_COUNTRY_OF_ORIGIN'), array('type' => 'text', 'label' => $this->l('Model attribute name'), 'name' => 'YAMARKET_MODEL_NAME', 'desc' => $this->l('Leave empty to use product name as model name')), array('type' => 'categories', 'label' => $this->l('Categories to export:'), 'name' => 'categoryBox', 'values' => array('trads' => array('Root' => $root_category, 'selected' => $this->l('Selected'), 'Check all' => $this->l('Check all'), 'Check All' => $this->l('Check All'), 'Uncheck All' => $this->l('Uncheck All'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All')), 'selected_cat' => $selected_cat, 'input_name' => 'categoryBox[]', 'use_radio' => false, 'use_search' => false, 'disabled_categories' => array(), 'top_category' => Category::getTopCategory(), 'use_context' => true), 'tree' => array('id' => 'categories-tree', 'use_checkbox' => true, 'use_search' => false, 'selected_categories' => $selected_cat, 'input_name' => 'categoryBox[]'), 'selected_cat' => $selected_cat), array('type' => 'text', 'label' => '&lt;sales_notes&gt;', 'name' => 'YAMARKET_SALES_NOTES', 'size' => 50, 'desc' => $this->l('50 characters max')), array('type' => 'checkbox', 'label' => $this->l('Delivery settings'), 'name' => 'YAMARKET_DELIVERY', 'desc' => $this->l('Details: ') . '<a class="action_module" href="https://help.yandex.ru/partnermarket/delivery.xml">help.yandex.ru/partnermarket/delivery.xml</a>', 'values' => array('query' => array(array('id' => 'DELIVERY', 'name' => '&lt;delivery&gt;', 'val' => '1'), array('id' => 'PICKUP', 'name' => '&lt;pickup&gt;', 'val' => '1'), array('id' => 'STORE', 'name' => '&lt;store&gt;', 'val' => '1')), 'id' => 'id', 'name' => 'name'))), 'submit' => array('title' => $this->l('Save'))));
     $helper = new HelperForm();
     $helper->show_toolbar = false;
     $this->fields_form = array();
     $helper->table = $this->table;
     $lang = new Language((int) Configuration::get('PS_LANG_DEFAULT'));
     $helper->default_form_language = $lang->id;
     $helper->identifier = $this->identifier;
     $helper->submit_action = 'submit' . $this->name;
     $helper->token = Tools::getAdminTokenLite('AdminModules');
     $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
     $helper->tpl_vars = array('fields_value' => $this->getConfigFieldsValues(), 'languages' => $this->context->controller->getLanguages(), 'id_language' => $this->context->language->id);
     $output = $helper->generateForm(array($fields_form));
     return $output;
 }
    public function initFieldsForm()
    {
        $obj = $this->loadObject(true);
        $scene_image_types = ImageType::getImagesTypes('scenes');
        $large_scene_image_type = null;
        $thumb_scene_image_type = null;
        foreach ($scene_image_types as $scene_image_type) {
            if ($scene_image_type['name'] == 'scene_default') {
                $large_scene_image_type = $scene_image_type;
            }
            if ($scene_image_type['name'] == 'm_scene_default') {
                $thumb_scene_image_type = $scene_image_type;
            }
        }
        $fields_form = array('legend' => array('title' => $this->l('Image Maps'), 'image' => '../img/admin/photo.gif'), 'submit' => array('title' => $this->l('Save'), 'class' => 'button'), 'input' => array(array('type' => 'description', 'name' => 'description', 'label' => $this->l('How to map products in the image:'), 'text' => $this->l('When a customer hovers over the image with the mouse, a pop-up appears displaying a brief description of the product.') . $this->l('The customer can then click to open the product\'s full product page.') . $this->l('To achieve this, please define the \'mapping zone\' that, when hovered over, will display the pop-up.') . $this->l('Left-click with your mouse to draw the four-sided mapping zone, then release.') . $this->l('Then, begin typing the name of the associated product. A list of products appears.') . $this->l('Click the appropriate product, then click OK. Repeat these steps for each mapping zone you wish to create.') . $this->l('When you have finished mapping zones, click Save Image Map.')), array('type' => 'text', 'label' => $this->l('Image map name:'), 'name' => 'name', 'lang' => true, 'size' => 48, 'required' => true, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'radio', 'label' => $this->l('Status:'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled'))))));
        $this->fields_form = $fields_form;
        $image_to_map_desc = '';
        $image_to_map_desc .= $this->l('Format:') . ' JPG, GIF, PNG. ' . $this->l('File size:') . ' ' . Tools::getMaxUploadSize() / 1024 . '' . $this->l('kB max.') . ' ' . sprintf($this->l('If larger than the image size setting, the image will be reduced to %1$d x %2$dpx (width x height).'), $large_scene_image_type['width'], $large_scene_image_type['height']) . $this->l('If smaller than the image size setting, a white background will be added in order to achieve the correct image size.') . '<br />' . $this->l('Note: To change image dimensions, please change the \'large_scene\' image type settings to the desired size (in Back Office > Preferences > Images).');
        if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_ . $obj->id . '-scene_default.jpg')) {
            $this->addJqueryPlugin('autocomplete');
            $this->addJqueryPlugin('imgareaselect');
            $this->addJs(_PS_JS_DIR_ . 'admin-scene-cropping.js');
            $image_to_map_desc .= '<br /><img id="large_scene_image" style="clear:both;border:1px solid black;" alt="" src="' . _THEME_SCENE_DIR_ . $obj->id . '-scene_default.jpg" /><br />';
            $image_to_map_desc .= '
						<div id="ajax_choose_product" style="display:none; padding:6px; padding-top:2px; width:600px;">
							' . $this->l('Begin typing the first letters of the product name, then select the product from the drop-down list:') . '
								<br /><input type="text" value="" id="product_autocomplete_input" /> 
								<input type="button" class="button" value="' . $this->l('OK') . '" onclick="$(this).prev().search();" />
								<input type="button" class="button" value="' . $this->l('Delete') . '" onclick="undoEdit();" />
						</div>
				';
            if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_ . 'thumbs/' . $obj->id . '-thumb_scene.jpg')) {
                $image_to_map_desc .= '<br/>
					<img id="large_scene_image" style="clear:both;border:1px solid black;" alt="" src="' . _THEME_SCENE_DIR_ . 'thumbs/' . $obj->id . '-m_scene_default.jpg" />
					<br />';
            }
            $img_alt_desc = '';
            $img_alt_desc .= $this->l('If you want to use a thumbnail other than one generated from simply reducing the mapped image, please upload it here.') . '<br />' . $this->l('Format:') . ' JPG, GIF, PNG. ' . $this->l('Filesize:') . ' ' . Tools::getMaxUploadSize() / 1024 . '' . $this->l('kB max.') . ' ' . sprintf($this->l('Automatically resized to %1$d x %2$dpx (width x height).'), $thumb_scene_image_type['width'], $thumb_scene_image_type['height']) . '.<br />' . $this->l('Note: To change image dimensions, please change the \'thumb_scene\' image type settings to the desired size (in Back Office > Preferences > Images).');
            $input_img_alt = array('type' => 'file', 'label' => $this->l('Alternative thumbnail:'), 'name' => 'thumb', 'desc' => $img_alt_desc);
            $selected_cat = array();
            if (Tools::isSubmit('categories')) {
                foreach (Tools::getValue('categories') as $row) {
                    $selected_cat[] = $row;
                }
            } else {
                if ($obj->id) {
                    foreach (Scene::getIndexedCategories($obj->id) as $row) {
                        $selected_cat[] = $row['id_category'];
                    }
                }
            }
            $root_category = Category::getRootCategory();
            if (!$root_category->id) {
                $root_category->id = 0;
                $root_category->name = $this->l('Root');
            }
            $root_category = array('id_category' => (int) $root_category->id, 'name' => $root_category->name);
            $trads = array('Root' => $root_category, 'selected' => $this->l('selected'), 'Check all' => $this->l('Check all'), 'Check All' => $this->l('Check All'), 'Uncheck All' => $this->l('Uncheck All'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All'), 'search' => $this->l('Search a category'));
            $this->fields_form['input'][] = array('type' => 'categories', 'label' => $this->l('Categories:'), 'name' => 'categories', 'values' => array('trads' => $trads, 'selected_cat' => $selected_cat, 'input_name' => 'categories[]', 'use_radio' => false, 'use_search' => true, 'disabled_categories' => array(4), 'top_category' => Category::getTopCategory(), 'use_context' => true));
        } else {
            $image_to_map_desc .= '<br/><span class="bold">' . $this->l('Please add a picture to continue mapping the image.') . '</span><br/><br/>';
        }
        if (Shop::isFeatureActive()) {
            $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso');
        }
        $this->fields_form['input'][] = array('type' => 'file', 'label' => $this->l('Image to be mapped:'), 'name' => 'image', 'display_image' => true, 'desc' => $image_to_map_desc);
        if (isset($input_img_alt)) {
            $this->fields_form['input'][] = $input_img_alt;
        }
    }
 public function renderForm()
 {
     $this->initToolbar();
     $obj = $this->loadObject(true);
     $id_shop = Context::getContext()->shop->id;
     $selected_cat = array(isset($obj->id_parent) && $obj->isParentCategoryAvailable($id_shop) ? (int) $obj->id_parent : (int) Tools::getValue('id_parent', Category::getRootCategory()->id));
     $unidentified = new Group(Configuration::get('PS_UNIDENTIFIED_GROUP'));
     $guest = new Group(Configuration::get('PS_GUEST_GROUP'));
     $default = new Group(Configuration::get('PS_CUSTOMER_GROUP'));
     $unidentified_group_information = sprintf($this->l('%s - All people without a validated customer account.'), '<b>' . $unidentified->name[$this->context->language->id] . '</b>');
     $guest_group_information = sprintf($this->l('%s - Customer who placed an order with the Guest Checkout.'), '<b>' . $guest->name[$this->context->language->id] . '</b>');
     $default_group_information = sprintf($this->l('%s - All people who have created an account on this site.'), '<b>' . $default->name[$this->context->language->id] . '</b>');
     $root_category = Category::getRootCategory();
     $root_category = array('id_category' => $root_category->id, 'name' => $root_category->name);
     $this->fields_form = array('tinymce' => true, 'legend' => array('title' => $this->l('Category'), 'image' => '../img/admin/tab-categories.gif'), 'input' => array(array('type' => 'text', 'label' => $this->l('Name:'), 'name' => 'name', 'lang' => true, 'size' => 48, 'required' => true, 'class' => 'copy2friendlyUrl', 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'radio', 'label' => $this->l('Displayed:'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array(array('id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled')))), array('type' => 'categories', 'label' => $this->l('Parent category:'), 'name' => 'id_parent', 'values' => array('trads' => array('Root' => $root_category, 'selected' => $this->l('selected'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All')), 'selected_cat' => $selected_cat, 'input_name' => 'id_parent', 'use_radio' => true, 'use_search' => false, 'disabled_categories' => array(4), 'top_category' => Category::getTopCategory(), 'use_context' => true)), array('type' => 'radio', 'label' => $this->l('Root Category:'), 'name' => 'is_root_category', 'required' => false, 'is_bool' => true, 'class' => 't', 'values' => array(array('id' => 'is_root_on', 'value' => 1, 'label' => $this->l('Yes')), array('id' => 'is_root_off', 'value' => 0, 'label' => $this->l('No')))), array('type' => 'textarea', 'label' => $this->l('Description:'), 'name' => 'description', 'lang' => true, 'rows' => 10, 'cols' => 100, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}'), array('type' => 'file', 'label' => $this->l('Image:'), 'name' => 'image', 'display_image' => true, 'desc' => $this->l('Upload category logo from your computer')), array('type' => 'text', 'label' => $this->l('Meta title:'), 'name' => 'meta_title', 'lang' => true, 'hint' => $this->l('Forbidden characters:') . ' <>;=#{}'), array('type' => 'text', 'label' => $this->l('Meta description:'), 'name' => 'meta_description', 'lang' => true, 'hint' => $this->l('Forbidden characters:') . ' <>;=#{}'), array('type' => 'tags', 'label' => $this->l('Meta keywords:'), 'name' => 'meta_keywords', 'lang' => true, 'hint' => $this->l('Forbidden characters:') . ' <>;=#{}', 'desc' => $this->l('To add "tags" click in the field, write something, then press "Enter"')), array('type' => 'text', 'label' => $this->l('Friendly URL:'), 'name' => 'link_rewrite', 'lang' => true, 'required' => true, 'hint' => $this->l('Only letters and the minus (-) character are allowed')), array('type' => 'group', 'label' => $this->l('Group access:'), 'name' => 'groupBox', 'values' => Group::getGroups(Context::getContext()->language->id), 'info_introduction' => $this->l('You now have three default customer groups.'), 'unidentified' => $unidentified_group_information, 'guest' => $guest_group_information, 'customer' => $default_group_information, 'desc' => $this->l('Mark all customer groups you want to give access to this category'))), 'submit' => array('title' => $this->l('Save'), 'class' => 'button'));
     $this->tpl_form_vars['shared_category'] = Validate::isLoadedObject($obj) && $obj->hasMultishopEntries();
     $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int) Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL');
     if (Shop::isFeatureActive()) {
         $this->fields_form['input'][] = array('type' => 'shop', 'label' => $this->l('Shop association:'), 'name' => 'checkBoxShopAsso');
     }
     // remove category tree and radio button "is_root_category" if this category has the root category as parent category to avoid any conflict
     if ($this->_category->id_parent == Category::getTopCategory()->id && Tools::isSubmit('updatecategory')) {
         foreach ($this->fields_form['input'] as $k => $input) {
             if (in_array($input['name'], array('id_parent', 'is_root_category'))) {
                 unset($this->fields_form['input'][$k]);
             }
         }
     }
     if (Tools::isSubmit('add' . $this->table . 'root')) {
         unset($this->fields_form['input'][2], $this->fields_form['input'][3]);
     }
     if (!($obj = $this->loadObject(true))) {
         return;
     }
     $image = ImageManager::thumbnail(_PS_CAT_IMG_DIR_ . '/' . $obj->id . '.jpg', $this->table . '_' . (int) $obj->id . '.' . $this->imageType, 350, $this->imageType, true);
     $this->fields_value = array('image' => $image ? $image : false, 'size' => $image ? filesize(_PS_CAT_IMG_DIR_ . '/' . $obj->id . '.jpg') / 1000 : false);
     // Added values of object Group
     $category_groups_ids = $obj->getGroups();
     $groups = Group::getGroups($this->context->language->id);
     // if empty $carrier_groups_ids : object creation : we set the default groups
     if (empty($category_groups_ids)) {
         $preselected = array(Configuration::get('PS_UNIDENTIFIED_GROUP'), Configuration::get('PS_GUEST_GROUP'), Configuration::get('PS_CUSTOMER_GROUP'));
         $category_groups_ids = array_merge($category_groups_ids, $preselected);
     }
     foreach ($groups as $group) {
         $this->fields_value['groupBox_' . $group['id_group']] = Tools::getValue('groupBox_' . $group['id_group'], in_array($group['id_group'], $category_groups_ids));
     }
     return parent::renderForm();
 }
 public function fieldsetCategory($children = true)
 {
     $root_category = Category::getRootCategory();
     $selected_cat = array($this->object->id_category);
     //array(5); // array((isset($obj->id_parent) && $obj->isParentCategoryAvailable($id_shop))? (int)$obj->id_parent : (int)Tools::getValue('id_parent', Category::getRootCategory()->id));
     $root_category_id = $root_category->id_category;
     $root_category = array('id_category' => $root_category->id_category, 'name' => $root_category->name);
     $fields = array('legend' => array('title' => $this->l('Product Category'), 'class' => 'fieldset-product-category', 'image' => $this->getPstPictureUrl('product_category.png', 'type')), 'input' => array(array('type' => 'categories', 'label' => $this->l('Choose a category:'), 'tree' => array('id' => 'categories-tree', 'selected_categories' => $selected_cat, 'root_category' => $root_category_id, 'use_search' => true), 'name' => 'id_category', 'values' => array('trads' => array('search' => $this->l('Search'), 'Root' => $root_category, 'selected' => $this->l('selected'), 'Collapse All' => $this->l('Collapse All'), 'Expand All' => $this->l('Expand All')), 'selected_cat' => $selected_cat, 'input_name' => 'id_category', 'disabled_categories' => array(), 'use_radio' => true, 'use_search' => false, 'top_category' => Category::getTopCategory()))));
     if ($children) {
         $fields['input'][] = array('type' => 'radio', 'class' => 't', 'label' => $this->l('Display childs ? :'), 'container_class' => 'display_prod_cat_childs', 'required' => false, 'name' => 'display_prod_cat_childs', 'desc' => $this->l('Display all sub categories'), 'is_bool' => true, 'values' => array(array('id' => 'display_prod_cat_childs_on', 'value' => 1, 'label' => $this->l('Enabled')), array('id' => 'display_prod_cat_childs_off', 'value' => 0, 'label' => $this->l('Disabled'))));
     }
     $this->fields_form[] = array('class' => 'product_category box-hide', 'form' => $fields);
 }