* @copyright 2007-2014 RSI * @license http://catalogo-onlinersi.net */ class MassPrice extends Module { private $_html = ""; private $_postErrors = []; public function __construct() { $this->name = "massprice"; $this->module_key = "c22aa30c1a5d33d5e8c7d59a1f412e38"; if (_PS_VERSION_ < "1.4.0.0") { $this->tab = "Tools"; } if (_PS_VERSION_ > "1.4.0.0" && _PS_VERSION_ < "1.5.0.0") { $this->tab = "administration"; $this->author = "RSI"; $this->need_instance = 1; } if (_PS_VERSION_ > "1.5.0.0") { $this->tab = "administration"; $this->author = "RSI"; } if (_PS_VERSION_ > "1.6.0.0") { $this->bootstrap = true; } $this->version = "4.0.0"; parent::__construct(); $this->displayName = $this->l("Mass price update"); $this->description = $this->l( "Mass price update by category-www.catalogo-onlinersi.net" ); if (_PS_VERSION_ < "1.5") { require _PS_MODULE_DIR_ . $this->name . "/backward_compatibility/backward.php"; } } public function install() { if ( !Configuration::updateValue("MASSPRICE_NBR", 1) || !parent::install() || !$this->registerHook("header") ) { return false; } if (!Configuration::updateValue("MASSPRICE_SKIP_CAT", 1)) { return false; } if (!Configuration::updateValue("MASSPRICE_REQUIERED1", 0)) { return false; } if (!Configuration::updateValue("MASSPRICE_MIN", "")) { return false; } if (!Configuration::updateValue("MASSPRICE_MAX", "")) { return false; } if (!Configuration::updateValue("MASSPRICE_SYMBOL", 0)) { return false; } if (!Configuration::updateValue("MASSPRICE_COMB", 0)) { return false; } if (!Configuration::updateValue("MASSPRICE_LAST", "")) { return false; } return true; } private function _displayInfo() { $this->context->smarty->assign( "last", Configuration::get("MASSPRICE_LAST") ); return $this->display(__FILE__, "views/templates/hook/infos.tpl"); } private function _displayAdds() { return $this->display(__FILE__, "views/templates/hook/adds.tpl"); } public function getConfigFieldsValues() { /*categories*/ /* $typec = Category::getCategories($this->context->language->id, true, false); $id_category = array(); foreach ($typec as $type) if (!is_null(Tools::getValue('skipcat_'.(int)$type['id_category']))) $id_category['skipcat_'.(int)$type['id_category']] = true; $types2 = Category::getCategories($this->context->language->id, true, false); $id_category = array(); foreach ($types2 as $type2) $id_category[] = $type2['id_category']; $id_category_post = array(); foreach ($id_category as $id) if (Tools::getValue('skipcat_'.(int)$id)) $id_category_post['skipcat_'.(int)$id] = true; $id_category_config = array(); if ($confs2 = Configuration::get('MASSPRICE_SKIP_CAT')) $confs2 = explode(',', Configuration::get('MASSPRICE_SKIP_CAT')); else $confs2 = array(); foreach ($confs2 as $conf2) $id_category_config['skipcat_'.(int)$conf2] = true;/* /*attributes*/ /*categories*/ /**/ $fields_values = [ "nbr" => Tools::getValue( "nbr", Configuration::get("MASSPRICE_NBR") ), "requiered1" => Tools::getValue( "requiered1", Configuration::get("MASSPRICE_REQUIERED1") ), "symbol" => Tools::getValue( "symbol", Configuration::get("MASSPRICE_SYMBOL") ), "comb" => Tools::getValue( "comb", Configuration::get("MASSPRICE_COMB") ), "min" => Tools::getValue( "min", Configuration::get("MASSPRICE_MIN") ), "max" => Tools::getValue( "max", Configuration::get("MASSPRICE_MAX") ), "last" => Tools::getValue( "last", Configuration::get("MASSPRICE_LAST") ), "skipcat" => Tools::getValue( "skipcat", explode(",", Configuration::get("MASSPRICE_SKIP_CAT")) ), ]; /*$fields_values = array_merge($fields_values, array_intersect($id_category_config, $id_category_config));*/ return $fields_values; } public function postProcess() { $errors = ""; $_html = ""; $skipcat = ""; $skipman = ""; $skipatt = ""; if (Tools::isSubmit("submitMassPrice")) { /*$types2 = Category::getCategories($this->context->language->id, true, false); $id_category = array(); foreach ($types2 as $type2) if (Tools::getValue('skipcat_'.(int)$type2['id_category'])) $id_category[] = $type2['id_category']; /*attributes*/ /* Configuration::updateValue('MASSPRICE_SKIP_CAT', implode(',', $id_category));*/ if ($skipcat = Tools::getValue("skipcat")) { Configuration::updateValue( "MASSPRICE_SKIP_CAT", implode(",", $skipcat) ); } elseif ( Shop::getContext() == Shop::CONTEXT_SHOP || Shop::getContext() == Shop::CONTEXT_GROUP ) { Configuration::deleteFromContext("MASSPRICE_SKIP_CAT"); } if ($nbr = Tools::getValue("nbr")) { Configuration::updateValue("MASSPRICE_NBR", $nbr); } elseif ( Shop::getContext() == Shop::CONTEXT_SHOP || Shop::getContext() == Shop::CONTEXT_GROUP ) { Configuration::deleteFromContext("MASSPRICE_NBR"); } if ($requiered1 = Tools::getValue("requiered1")) { Configuration::updateValue("MASSPRICE_REQUIERED1", $requiered1); } elseif ( Shop::getContext() == Shop::CONTEXT_SHOP || Shop::getContext() == Shop::CONTEXT_GROUP ) { Configuration::deleteFromContext("MASSPRICE_REQUIERED1"); } if ($symbol = Tools::getValue("symbol")) { Configuration::updateValue("MASSPRICE_SYMBOL", $symbol); } elseif ( Shop::getContext() == Shop::CONTEXT_SHOP || Shop::getContext() == Shop::CONTEXT_GROUP ) { Configuration::deleteFromContext("MASSPRICE_SYMBOL"); } if ($min = Tools::getValue("min")) { Configuration::updateValue("MASSPRICE_MIN", $min); } elseif ( Shop::getContext() == Shop::CONTEXT_SHOP || Shop::getContext() == Shop::CONTEXT_GROUP ) { Configuration::deleteFromContext("MASSPRICE_MIN"); } if ($max = Tools::getValue("max")) { Configuration::updateValue("MASSPRICE_MAX", $max); } elseif ( Shop::getContext() == Shop::CONTEXT_SHOP || Shop::getContext() == Shop::CONTEXT_GROUP ) { Configuration::deleteFromContext("MASSPRICE_MAX"); } if ($comb = Tools::getValue("comb")) { Configuration::updateValue("MASSPRICE_COMB", $comb); } elseif ( Shop::getContext() == Shop::CONTEXT_SHOP || Shop::getContext() == Shop::CONTEXT_GROUP ) { Configuration::deleteFromContext("MASSPRICE_COMB"); } if ($last = Tools::getValue("last")) { Configuration::updateValue("MASSPRICE_LAST", $last); } elseif ( Shop::getContext() == Shop::CONTEXT_SHOP || Shop::getContext() == Shop::CONTEXT_GROUP ) { Configuration::deleteFromContext("MASSPRICE_LAST"); } if ($symbol == 0) { $sy = "-"; } if ($symbol == 1) { $sy = "+"; } if ($symbol == 2) { $sy = $this->l("New value"); } if ($requiered1 == 0) { $re = $this->l("Amount"); } if ($requiered1 == 1) { $re = "%"; } if ($comb == 0) { $co = $this->l( "Dont update combinations, only update base price" ); } if ($comb == 1) { $co = $this->l("Update base price and combination price"); } if ($comb == 2) { $co = $this->l("Update combinations, dont update base price"); } $last = $this->l( "Price increment:" . (float) $nbr . ",Type of increment:" . $sy . " in " . $re . " - " . $co . " on categories ID:" . (string) Configuration::get("MASSPRICE_SKIP_CAT") ); Configuration::updateValue("MASSPRICE_LAST", $last); $this->updateall(); } return $this->_html; } public function renderForm() { /*manufacturers*/ /*categories*/ $root = Category::getRootCategory(); $selected_cat = explode(",", Configuration::get("MASSPRICE_SKIP_CAT")); $tree = new HelperTreeCategories("categories-treeview"); $tree ->setUseCheckBox(true) ->setAttribute("is_category_filter", $root->id) ->setRootCategory($root->id) ->setSelectedCategories($selected_cat) ->setUseSearch(true) ->setInputName("skipcat"); $categoryTreeCol1 = $tree->render(); $types2 = Category::getCategories( $this->context->language->id, true, false ); foreach ($types2 as $key => $type) { $types2[$key]["label"] = $type["name"]; } /*attributes*/ $options2 = [ [ "id_option" => "1", // The value of the 'value' attribute of the "; } } if (isset($categories[$id_category])) { foreach ($categories[$id_category] as $key => $row) { $this->recurseCategory( $categories, $categories[$id_category][$key], $key, $selectids_array ); }; } } }