Commit c1f7e698df352de0612df45253467d74ae161630
1 parent
4f13b785
Version original del modulo
Showing
9 changed files
with
246 additions
and
239 deletions
FuncionesImaxAddCatbyFeature.php
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | class FuncionesImaxAddCatbyFeature { |
| 4 | - private $modulo; | |
| 5 | - | |
| 6 | - public function __construct($modulo) { | |
| 7 | - $this->modulo = $modulo; | |
| 8 | - } | |
| 4 | + | |
| 5 | + private $modulo; | |
| 6 | + public $context; | |
| 7 | + | |
| 8 | + public function __construct($modulo) { | |
| 9 | + $this->modulo = $modulo; | |
| 10 | + $this->context = Context::getContext(); | |
| 11 | + } | |
| 12 | + | |
| 13 | + /** | |
| 14 | + * Devuelve las categorias a mover para un producto determinado | |
| 15 | + * @param int $idProduct | |
| 16 | + * @return array | |
| 17 | + */ | |
| 18 | + public function getCategoriesByProductFeature($idProduct) { | |
| 19 | + $categories = array(); | |
| 20 | + $producto = new ProductCore($idProduct); | |
| 21 | + $features = $producto->getFeatures(); | |
| 22 | + $catFeatures = unserialize(Configuration::getGlobalValue($this->modulo->sufijo . 'CATS_FEATURE')); | |
| 23 | + if($features && $catFeatures) { | |
| 24 | + foreach($features AS $feature) { | |
| 25 | + foreach($catFeatures AS $catFeature) { | |
| 26 | + if($feature['id_feature_value'] == $catFeature['valorCaracteristicaSeleccionado']) { | |
| 27 | + $categories[] = $catFeature['tipoSeleccionado']; | |
| 28 | + break; | |
| 29 | + } | |
| 30 | + } | |
| 31 | + } | |
| 32 | + } | |
| 33 | + return $categories; | |
| 34 | + } | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 9 | 38 | |
| 10 | 39 | /** |
| 11 | 40 | * Agrega al producto las categorias pasadas. |
| ... | ... | @@ -15,12 +44,12 @@ class FuncionesImaxAddCatbyFeature { |
| 15 | 44 | public function agregarCategorias($producto, $categorias) { |
| 16 | 45 | $categoriasActuales = $producto->getCategories(); |
| 17 | 46 | $nuevasCategorias = array_diff($categorias, $categoriasActuales); |
| 18 | - foreach($nuevasCategorias as $categoria) { | |
| 47 | + foreach ($nuevasCategorias as $categoria) { | |
| 19 | 48 | $this->guardarMovimiento($producto->id, $categoria); |
| 20 | 49 | } |
| 21 | 50 | $producto->addToCategories($nuevasCategorias); |
| 22 | 51 | } |
| 23 | - | |
| 52 | + | |
| 24 | 53 | /** |
| 25 | 54 | * Anota una nueva categoria de producto. |
| 26 | 55 | * @param int $id_product |
| ... | ... | @@ -28,35 +57,35 @@ class FuncionesImaxAddCatbyFeature { |
| 28 | 57 | * @return boolean |
| 29 | 58 | */ |
| 30 | 59 | private function guardarMovimiento($id_product, $id_category) { |
| 31 | - $id_product = (int)$id_product; | |
| 32 | - $id_category = (int)$id_category; | |
| 33 | - | |
| 34 | - return Db::getInstance()->execute('INSERT IGNORE INTO `'._DB_PREFIX_.$this->modulo->sufijo."movimiento` (id_product, id_category) VALUES ('$id_product', '$id_category')"); | |
| 60 | + $id_product = (int) $id_product; | |
| 61 | + $id_category = (int) $id_category; | |
| 62 | + | |
| 63 | + return Db::getInstance()->execute('INSERT IGNORE INTO `' . _DB_PREFIX_ . $this->modulo->sufijo . "movimiento` (id_product, id_category) VALUES ('$id_product', '$id_category')"); | |
| 35 | 64 | } |
| 36 | - | |
| 65 | + | |
| 37 | 66 | /** |
| 38 | 67 | * Devuelve los ids de categoria a los que el producto fue agregado. |
| 39 | 68 | * @param int $id_product |
| 40 | 69 | * @return int[] |
| 41 | 70 | */ |
| 42 | 71 | private function cargarMovimientos($id_product) { |
| 43 | - $id_product = (int)$id_product; | |
| 44 | - | |
| 45 | - $movimientos = Db::getInstance()->executeS('SELECT id_category FROM `'._DB_PREFIX_.$this->modulo->sufijo."movimiento` WHERE id_product = '$id_product'"); | |
| 72 | + $id_product = (int) $id_product; | |
| 73 | + | |
| 74 | + $movimientos = Db::getInstance()->executeS('SELECT id_category FROM `' . _DB_PREFIX_ . $this->modulo->sufijo . "movimiento` WHERE id_product = '$id_product'"); | |
| 46 | 75 | return array_column($movimientos, 'id_category'); |
| 47 | 76 | } |
| 48 | - | |
| 77 | + | |
| 49 | 78 | /** |
| 50 | 79 | * Elimina los movimientos de un producto. |
| 51 | 80 | * @param int $id_product |
| 52 | 81 | * @return boolean |
| 53 | 82 | */ |
| 54 | 83 | private function eliminarMovimientos($id_product) { |
| 55 | - $id_product = (int)$id_product; | |
| 56 | - | |
| 57 | - return Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.$this->modulo->sufijo."movimiento` WHERE id_product = '$id_product'"); | |
| 84 | + $id_product = (int) $id_product; | |
| 85 | + | |
| 86 | + return Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . $this->modulo->sufijo . "movimiento` WHERE id_product = '$id_product'"); | |
| 58 | 87 | } |
| 59 | - | |
| 88 | + | |
| 60 | 89 | /** |
| 61 | 90 | * Quita al producto las categorias agregadas. |
| 62 | 91 | * @param Product $producto |
| ... | ... | @@ -64,37 +93,72 @@ class FuncionesImaxAddCatbyFeature { |
| 64 | 93 | public function deshacerMovimientos($producto) { |
| 65 | 94 | $idsCategoria = $this->cargarMovimientos($producto->id); |
| 66 | 95 | $num = count($idsCategoria); |
| 67 | - foreach($idsCategoria as $clave => $idCategoria) { | |
| 68 | - $producto->deleteCategory($idCategoria, ($clave == $num - 1)); | |
| 96 | + | |
| 97 | + foreach ($idsCategoria as $clave => $idCategoria) { | |
| 98 | + //$producto->deleteCategory($idCategoria, ($clave == $num - 1)); | |
| 99 | + $producto->deleteCategory($idCategoria, false); | |
| 69 | 100 | } |
| 70 | 101 | $this->eliminarMovimientos($producto->id); |
| 71 | 102 | } |
| 72 | - | |
| 103 | + | |
| 73 | 104 | /** |
| 74 | 105 | * Monta una lista de categorias recursivamente. |
| 75 | 106 | * @param array $categoria |
| 76 | 107 | * @param string $html |
| 77 | 108 | * @param int[] $categoriasSeleccionada |
| 78 | 109 | */ |
| 79 | - public function getHijosLista($categoria, &$html, $categoriasSeleccionada) { | |
| 110 | + public function getHijosSelect($categoria, &$respuesta) { | |
| 80 | 111 | $categoriasHijos = Category::getChildren($categoria['id_category'], $this->modulo->idLang); |
| 81 | - | |
| 82 | 112 | if (count($categoriasHijos)) { |
| 83 | - $html .= '<ul>'; | |
| 84 | 113 | foreach ($categoriasHijos AS $categoriaHijo) { |
| 85 | - if (in_array($categoriaHijo['id_category'], $categoriasSeleccionada)) { | |
| 86 | - $seleccionada = 'class="selected"'; | |
| 87 | - } | |
| 88 | - else { | |
| 89 | - $seleccionada = ''; | |
| 90 | - } | |
| 114 | + $respuesta[$categoriaHijo['id_category']] = $categoriaHijo['name'] . ' (' . $categoriaHijo['id_category'] . ')'; | |
| 115 | + $this->getHijosSelect($categoriaHijo, $respuesta); | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + } | |
| 91 | 120 | |
| 92 | - $html .= "<li id='{$categoriaHijo['id_category']}' $seleccionada>{$categoriaHijo['name']}"; | |
| 93 | - $this->getHijosLista($categoriaHijo, $html, $categoriasSeleccionada); | |
| 121 | + public function getFormCategorizacion($idTab) { | |
| 122 | + //Datos para js | |
| 123 | + $caracteristicas = Feature::getFeatures($this->modulo->idLang); | |
| 124 | + $caracteristicasFormateadas = array(0 => $this->modulo->l('- Seleccione uno -')); | |
| 125 | + $valoresCaracteristicaFormateados = array(); | |
| 126 | + foreach ($caracteristicas as $caracteristica) { | |
| 127 | + $caracteristicasFormateadas[$caracteristica['id_feature']] = $caracteristica['name']; | |
| 128 | + $valoresCaracteristica = FeatureValue::getFeatureValuesWithLang($this->modulo->idLang, $caracteristica['id_feature']); | |
| 129 | + if ($valoresCaracteristica) { | |
| 130 | + foreach ($valoresCaracteristica as $valorCaracteristica) { | |
| 131 | + if (!isset($valoresCaracteristicaFormateados[$caracteristica['id_feature']])) { | |
| 132 | + $valoresCaracteristicaFormateados[$caracteristica['id_feature']] = array(0 => $this->modulo->l('- Seleccione uno -')); | |
| 133 | + } | |
| 94 | 134 | |
| 95 | - $html .= '</li>'; | |
| 135 | + $valoresCaracteristicaFormateados[$caracteristica['id_feature']][$valorCaracteristica['id_feature_value']] = $valorCaracteristica['value']; | |
| 136 | + } | |
| 137 | + } else { | |
| 138 | + $valoresCaracteristicaFormateados[$caracteristica['id_feature']] = array(0 => $this->modulo->l('- Seleccione uno -')); | |
| 96 | 139 | } |
| 97 | - $html .= '</ul>'; | |
| 98 | 140 | } |
| 141 | + $tiposFormateados = array(); | |
| 142 | + $this->getHijosSelect(array('id_category' => $this->context->shop->id_category), $tiposFormateados); | |
| 143 | + $form = new imaxForm($this->modulo, $this->modulo->getPathUri()); | |
| 144 | + $form->createHidden("accion", "configurarCategorizacion"); | |
| 145 | + $form->createHidden("idTab", $idTab); | |
| 146 | + $form->addToForm(' | |
| 147 | + <script> | |
| 148 | + var caracteristicasFormateadas = ' . json_encode($caracteristicasFormateadas) . '; | |
| 149 | + var valoresCaracteristicaFormateados = ' . json_encode($valoresCaracteristicaFormateados) . '; | |
| 150 | + var tiposFormateados = ' . json_encode($tiposFormateados) . '; | |
| 151 | + var criteriosSeleccionados = ' . json_encode(unserialize(Configuration::getGlobalValue($this->modulo->sufijo . 'CATS_FEATURE'))) . '; | |
| 152 | + </script> | |
| 153 | + <table id="tablaCriteriosCategorizacion" class="table"> | |
| 154 | + <thead> | |
| 155 | + <tr><th>' . $this->modulo->l('Caracteristica') . '</th><th>' . $this->modulo->l('Valor caracteristica') . '</th><th>' . $this->modulo->l('Categoria') . '</th><th></th></tr> | |
| 156 | + </thead> | |
| 157 | + <tbody></tbody> | |
| 158 | + </table>'); | |
| 159 | + $form->createButton('agregarCriterio', $this->modulo->l('Nuevo')); | |
| 160 | + $form->createSubmitButton('save', $this->modulo->l('Guardar')); | |
| 161 | + return $form; | |
| 99 | 162 | } |
| 163 | + | |
| 100 | 164 | } | ... | ... |
config.xml
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | <module> |
| 3 | 3 | <name>imaxaddcatbyfeature</name> |
| 4 | 4 | <displayName><![CDATA[Informax add to category by feature]]></displayName> |
| 5 | - <version><![CDATA[1.1]]></version> | |
| 5 | + <version><![CDATA[1.2]]></version> | |
| 6 | 6 | <description><![CDATA[Informax add to category by feature]]></description> |
| 7 | 7 | <author><![CDATA[Informax]]></author> |
| 8 | 8 | <tab><![CDATA[administration]]></tab> | ... | ... |
configuration.php
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -$configuracion[$this->sufijo . 'CATS_NOVEDAD'] = serialize(array()); | |
| 4 | -$configuracion[$this->sufijo . 'DIAS_NOVEDAD'] = 7; | |
| 3 | +$configuracion[$this->sufijo . 'CATS_FEATURE'] = serialize(array()); | |
| 5 | 4 | $configuracion[$this->sufijo . 'TOKEN'] = md5(uniqid()); |
| 5 | +$configuracion[$this->sufijo . 'LAST_PRODUCT'] = 0; | |
| 6 | +$configuracion[$this->sufijo . 'NUM_ELEMENTOS'] = 100; | |
| 7 | + | |
| 6 | 8 | |
| 7 | 9 | $configuracion[$this->sufijo . 'LICENCIA'] = ''; |
| 8 | 10 | $configuracion[$this->sufijo . 'F_SERVER'] = 'http://licencia.informax.es/gestionarLicencias.php'; |
| ... | ... | @@ -12,6 +14,8 @@ $configuracion[$this->sufijo . 'F_CHECK'] = 1000; |
| 12 | 14 | |
| 13 | 15 | $hooks = array(); |
| 14 | 16 | $hooks[] = 'actionObjectProductAddAfter'; |
| 17 | +//$hooks[] = 'actionObjectProductUpdateAfter'; | |
| 18 | +$hooks[] = 'actionProductUpdate'; | |
| 15 | 19 | |
| 16 | 20 | |
| 17 | 21 | ... | ... |
css/css.css
imaxaddcatbyfeature.php
| ... | ... | @@ -19,7 +19,7 @@ class ImaxAddCatbyFeature extends Module { |
| 19 | 19 | public function __construct() { |
| 20 | 20 | $this->name = 'imaxaddcatbyfeature'; |
| 21 | 21 | $this->tab = 'administration'; |
| 22 | - $this->version = '1.1'; | |
| 22 | + $this->version = '1.2'; | |
| 23 | 23 | $this->author = 'Informax'; |
| 24 | 24 | $this->need_instance = 0; |
| 25 | 25 | $this->idManual = ''; |
| ... | ... | @@ -53,11 +53,9 @@ class ImaxAddCatbyFeature extends Module { |
| 53 | 53 | $directorioAdmin = getcwd(); |
| 54 | 54 | if (is_file(dirname(__FILE__) . '/' . $this->name . '_cron.php') && !@copy(dirname(__FILE__) . '/imaxaddcatbyfeature_cron.php', $directorioAdmin . '/imaxaddcatbyfeature_cron.php')) { |
| 55 | 55 | $this->_errors[] = $this->l('Ha fallado al copiar el fichero de cron'); |
| 56 | - return false; | |
| 57 | - } | |
| 56 | + } | |
| 58 | 57 | if (is_file(dirname(__FILE__) . '/' . $this->name . '_cron.php.imax') && !@copy(dirname(__FILE__) . '/imaxaddcatbyfeature_cron.php.imax', $directorioAdmin . '/imaxaddcatbyfeature_cron.php.imax')) { |
| 59 | - $this->_errors[] = $this->l('Ha fallado al copiar el fichero de cron ofuscado'); | |
| 60 | - return false; | |
| 58 | + $this->_errors[] = $this->l('Ha fallado al copiar el fichero de cron ofuscado'); | |
| 61 | 59 | } |
| 62 | 60 | |
| 63 | 61 | include(dirname(__FILE__) . '/configuration.php'); |
| ... | ... | @@ -133,8 +131,9 @@ class ImaxAddCatbyFeature extends Module { |
| 133 | 131 | $this->getTxtFiles(); |
| 134 | 132 | $this->addCSS('css.css'); |
| 135 | 133 | //$this->addJS('jquery.dynatree.min.js'); |
| 134 | + $this->addJqueryUI('ui.sortable'); | |
| 136 | 135 | $this->addJS('functions.js'); |
| 137 | - $this->addCSS('../skin/ui.dynatree.css'); | |
| 136 | + | |
| 138 | 137 | $this->addCSS('publi.css'); |
| 139 | 138 | $this->_html .= $this->createHelpHeader(); |
| 140 | 139 | if (!empty($_POST)) |
| ... | ... | @@ -158,13 +157,31 @@ class ImaxAddCatbyFeature extends Module { |
| 158 | 157 | $html .= $this->displayError($this->l('Ha ocurrido un error al guardar la licencia.')); |
| 159 | 158 | } |
| 160 | 159 | break; |
| 161 | - | |
| 162 | 160 | case 'configuracion': |
| 163 | - if (Configuration::updateGlobalValue(self::prefijo . 'DIAS_NOVEDAD', trim(Tools::getValue('diasNovedad', 7))) && | |
| 164 | - Configuration::updateGlobalValue(self::prefijo . 'CATS_NOVEDAD', serialize(explode(',', Tools::getValue('catList'))))) { | |
| 165 | - $html .= $this->displayConfirmation($this->l('Configuracion guardada correctamente.')); | |
| 161 | + if (Configuration::updateGlobalValue(self::prefijo . 'NUM_ELEMENTOS', (int) (Tools::getValue('numElementos')))) { | |
| 162 | + $html .= $this->displayConfirmation($this->l('Numero de elementos guardado correctamente.')); | |
| 163 | + } else { | |
| 164 | + $html .= $this->displayError($this->l('Ha ocurrido un error al guardar el numero de elementos.')); | |
| 165 | + } | |
| 166 | + break; | |
| 167 | + case 'generar_token': | |
| 168 | + if (Configuration::updateGlobalValue(self::prefijo . 'TOKEN', md5(uniqid()))) { | |
| 169 | + $html .= $this->displayConfirmation($this->l('Token regenerado correctamente.')); | |
| 170 | + } else { | |
| 171 | + $html .= $this->displayError($this->l('Ha ocurrido un error al regenerar el token.')); | |
| 172 | + } | |
| 173 | + break; | |
| 174 | + case 'configurarCategorizacion': | |
| 175 | + $criteriosOrdenados = array(); | |
| 176 | + $criterios = Tools::getValue('categorizacion', array()); | |
| 177 | + foreach ($criterios as $criterio) { | |
| 178 | + $criteriosOrdenados[(int) $criterio['orden']] = $criterio; | |
| 179 | + } | |
| 180 | + | |
| 181 | + if (Configuration::updateGlobalValue(self::prefijo . 'CATS_FEATURE', serialize($criteriosOrdenados))) { | |
| 182 | + $html = $this->displayConfirmation($this->l('Criterios guardados correctamente.')); | |
| 166 | 183 | } else { |
| 167 | - $html .= $this->displayError($this->l('Ha ocurrido un error al guardar la configuracion.')); | |
| 184 | + $html = $this->displayError($this->l('Ha ocurrido un error.')); | |
| 168 | 185 | } |
| 169 | 186 | break; |
| 170 | 187 | |
| ... | ... | @@ -186,10 +203,11 @@ class ImaxAddCatbyFeature extends Module { |
| 186 | 203 | private function _configuracion() { |
| 187 | 204 | include_once(dirname(__FILE__) . '/functionsForm.php'); |
| 188 | 205 | include_once(dirname(__FILE__) . '/imaxAcordeon.php'); |
| 189 | - $diasNovedad = Configuration::getGlobalValue(self::prefijo . 'DIAS_NOVEDAD'); | |
| 190 | - $catsNovedad = unserialize(Configuration::getGlobalValue(self::prefijo . 'CATS_NOVEDAD')); | |
| 206 | + $catsFeature = unserialize(Configuration::getGlobalValue(self::prefijo . 'CATS_FEATURE')); | |
| 191 | 207 | $token = Configuration::getGlobalValue(self::prefijo . 'TOKEN'); |
| 192 | - $arbol = ''; | |
| 208 | + $numElementos = Configuration::getGlobalValue(self::prefijo . 'NUM_ELEMENTOS'); | |
| 209 | + $html = ''; | |
| 210 | + $respuesta = array(); | |
| 193 | 211 | // |
| 194 | 212 | |
| 195 | 213 | $acordeon = new imaxAcordeon($this->_path); |
| ... | ... | @@ -197,11 +215,11 @@ class ImaxAddCatbyFeature extends Module { |
| 197 | 215 | $form = new imaxForm($this, $this->_path); |
| 198 | 216 | $form->createHidden("accion", "configuracion"); |
| 199 | 217 | $form->createHidden("idTab", "1"); |
| 200 | - $form->createHidden("catList", ""); | |
| 201 | - $form->addToForm($this->l('Buscador:') .$this->crearSelectCategorias()); | |
| 202 | - | |
| 218 | + $form->createFormTextGroup('numElementos', $numElementos, $this->l('Numero de elementos a procesar'), $this->l('Numero de elementos a procesar')); | |
| 203 | 219 | $form->createSubmitButton('opcionesConfiguracion', $this->l('Guardar')); |
| 204 | - $html = $acordeon->renderAcordeon($this->l('Configuracion'), $form->renderForm()); | |
| 220 | + $html .= $acordeon->renderAcordeon($this->l('Configuracion'), $form->renderForm()); | |
| 221 | + | |
| 222 | + $html .= $acordeon->renderAcordeon($this->l('Categorizacion'), $this->getFunciones()->getFormCategorizacion(1)->renderForm()); | |
| 205 | 223 | |
| 206 | 224 | unset($form); |
| 207 | 225 | $form = new imaxForm($this, $this->_path); |
| ... | ... | @@ -233,46 +251,77 @@ class ImaxAddCatbyFeature extends Module { |
| 233 | 251 | } |
| 234 | 252 | |
| 235 | 253 | public function hookActionObjectProductAddAfter($params) { |
| 236 | - //Si el producto es nuevo le agregamos categorias | |
| 237 | - $cats = unserialize(Configuration::getGlobalValue(self::prefijo . 'CATS_NOVEDAD')); | |
| 238 | - die(); | |
| 239 | - /* if($cats && time() - strtotime($params['object']->date_add) <= Configuration::getGlobalValue(self::prefijo.'DIAS_NOVEDAD') * 3600) { | |
| 240 | - $this->getFunciones()->agregarCategorias($params['object'], $cats); | |
| 241 | - } */ | |
| 254 | + $cats = $this->getFunciones()->getCategoriesByProductFeature($params['object']->id); | |
| 255 | + $this->getFunciones()->deshacerMovimientos($params['object']); | |
| 256 | + if ($cats) { | |
| 257 | + $this->getFunciones()->agregarCategorias($params['object'], $cats); | |
| 258 | + } | |
| 259 | + } | |
| 260 | + public function hookActionProductUpdate($params) { | |
| 261 | + $params['object'] = $params['product']; | |
| 262 | + $this->hookActionObjectProductUpdateAfter($params); | |
| 263 | + } | |
| 264 | + | |
| 265 | + public function hookActionObjectProductUpdateAfter($params) { | |
| 266 | + $cats = $this->getFunciones()->getCategoriesByProductFeature($params['object']->id); | |
| 267 | + $this->getFunciones()->deshacerMovimientos($params['object']); | |
| 268 | + if ($cats) { | |
| 269 | + $this->getFunciones()->agregarCategorias($params['object'], $cats); | |
| 270 | + } | |
| 242 | 271 | } |
| 243 | 272 | |
| 244 | 273 | /** |
| 245 | - * Elimina las categorias agregadas a los productos que ya no son novedad. | |
| 274 | + * Aรฑade o elimina las categorias a los productos que tienen o no las caracteristicas asociadas | |
| 246 | 275 | * @return int La cantidad de productos procesados. |
| 247 | 276 | */ |
| 248 | - /* public function procesar() { | |
| 249 | - $dias = (int)Configuration::getGlobalValue(self::prefijo.'DIAS_NOVEDAD'); | |
| 250 | - $productos = Db::getInstance()->executeS(' | |
| 251 | - SELECT DISTINCT m.id_product FROM `'._DB_PREFIX_.self::prefijo.'movimiento` m | |
| 252 | - INNER JOIN `'._DB_PREFIX_."product` p ON m.id_product = p.id_product | |
| 253 | - WHERE DATEDIFF(NOW(), date_add) > $dias"); | |
| 254 | - foreach($productos as $producto) { | |
| 255 | - $this->getFunciones()->deshacerMovimientos(new Product($producto['id_product'])); | |
| 256 | - } | |
| 257 | - | |
| 258 | - return count($productos); | |
| 259 | - } */ | |
| 260 | - | |
| 261 | 277 | public function procesar() { |
| 262 | - if (!function_exists('procesar_')) { | |
| 263 | - $function = $this->getFunction(); | |
| 264 | - eval(gzuncompress(base64_decode($function))); | |
| 278 | + $lastProduct = (int) Configuration::getGlobalValue(self::prefijo . 'LAST_PRODUCT'); | |
| 279 | + $numElementos = (int) Configuration::getGlobalValue(self::prefijo . 'NUM_ELEMENTOS'); | |
| 280 | + if (!$numElementos) { | |
| 281 | + $numElementos = 100; | |
| 282 | + Configuration::updateGlobalValue(self::prefijo . 'NUM_ELEMENTOS', $numElementos); | |
| 265 | 283 | } |
| 266 | - if (function_exists('procesar_')) { | |
| 267 | - return procesar_($this); | |
| 284 | + $sql = ' SELECT id_product ' | |
| 285 | + . ' FROM ' . _DB_PREFIX_ . 'product ' | |
| 286 | + . ' WHERE ' | |
| 287 | + . ' id_product > ' . $lastProduct . '' | |
| 288 | + . ' LIMIT 0,' . $numElementos; | |
| 289 | + $result = Db::getInstance()->executeS($sql); | |
| 290 | + if (!$result) { | |
| 291 | + Configuration::updateGlobalValue(self::prefijo . 'LAST_PRODUCT', 0); | |
| 292 | + } else { | |
| 293 | + foreach ($result AS $elemento) { | |
| 294 | + $producto = new Product($elemento['id_product']); | |
| 295 | + $this->getFunciones()->deshacerMovimientos($producto); | |
| 296 | + $cats = $this->getFunciones()->getCategoriesByProductFeature($elemento['id_product']); | |
| 297 | + if ($cats) { | |
| 298 | + $this->getFunciones()->agregarCategorias($producto, $cats); | |
| 299 | + } | |
| 300 | + | |
| 301 | + Configuration::updateGlobalValue(self::prefijo . 'LAST_PRODUCT', $elemento['id_product']); | |
| 302 | + } | |
| 268 | 303 | } |
| 269 | 304 | |
| 270 | - echo $this->l('Este modulo no tiene una licencia valida: ') . $this->name; | |
| 271 | - echo '<br />'; | |
| 272 | - echo $this->l('Contacte con nosotros para obtener una licencia valida'); | |
| 273 | - die(); | |
| 305 | + return count($result); | |
| 274 | 306 | } |
| 275 | 307 | |
| 308 | + /* | |
| 309 | + public function procesar() { | |
| 310 | + if (!function_exists('procesar_')) { | |
| 311 | + $function = $this->getFunction(); | |
| 312 | + eval(gzuncompress(base64_decode($function))); | |
| 313 | + } | |
| 314 | + if (function_exists('procesar_')) { | |
| 315 | + return procesar_($this); | |
| 316 | + } | |
| 317 | + | |
| 318 | + echo $this->l('Este modulo no tiene una licencia valida: ') . $this->name; | |
| 319 | + echo '<br />'; | |
| 320 | + echo $this->l('Contacte con nosotros para obtener una licencia valida'); | |
| 321 | + die(); | |
| 322 | + } | |
| 323 | + */ | |
| 324 | + | |
| 276 | 325 | public function l($msg, $modulo = '', $locale = null) { |
| 277 | 326 | if ($modulo == '') { |
| 278 | 327 | $modulo = 'traducciones' . strtolower($this->name); |
| ... | ... | @@ -309,7 +358,7 @@ class ImaxAddCatbyFeature extends Module { |
| 309 | 358 | $form->createHidden("accion", "configurarCriteriosNovedad"); |
| 310 | 359 | $form->createHidden("idTab", $idTab); |
| 311 | 360 | $form->createFormTextGroup('numDiasNovedad', $numDiasNovedad, $this->modulo->l('Numero de dias a restar para los productos no nuevos')); |
| 312 | - // $form->addToForm($this->crearSelectCategorias()); | |
| 361 | + // $form->addToForm($this->crearSelectCategorias()); | |
| 313 | 362 | /* $form->addToForm(' |
| 314 | 363 | <script> |
| 315 | 364 | var caracteristicasFormateadas = ' . json_encode($caracteristicasFormateadas) . '; |
| ... | ... | @@ -329,66 +378,4 @@ class ImaxAddCatbyFeature extends Module { |
| 329 | 378 | return $form; |
| 330 | 379 | } |
| 331 | 380 | |
| 332 | - /** | |
| 333 | - * Devuelve el html de las option de categorias. | |
| 334 | - * @return string | |
| 335 | - */ | |
| 336 | - public function crearSelectCategorias() { | |
| 337 | - $html = '<option value="0">' . $this->l('Todos') . '</option>'; | |
| 338 | - //$html .= '<option selected="selected" value="' . Configuration::get('PS_HOME_CATEGORY') . '">' . $this->l('Inicio') . '</option>'; | |
| 339 | - $num = 0; | |
| 340 | - $categorias = $this->getHomeCategories($this->idLang); | |
| 341 | - foreach ($categorias AS $categoria) { | |
| 342 | - $html .= '<option class="imaxcategory" value="' . $categoria['id_category'] . '" >' . $categoria['name'] ." :: " . $categoria['id_category'] . '</option>'; | |
| 343 | - $this->getHijos($categoria, $html, $this->idLang, $num); | |
| 344 | - } | |
| 345 | - | |
| 346 | - return $html; | |
| 347 | - } | |
| 348 | - | |
| 349 | - private function getHijos($categoria, &$html, $id_lang = 1, &$num) { | |
| 350 | - $numInterno = $num; | |
| 351 | - $sqlHijos = "SELECT | |
| 352 | - DISTINCT c.id_category, c.id_parent, cl.name | |
| 353 | - FROM | |
| 354 | - " . _DB_PREFIX_ . "category AS c | |
| 355 | - INNER JOIN " . _DB_PREFIX_ . "category_lang AS cl | |
| 356 | - ON | |
| 357 | - cl.id_category = c.id_category AND | |
| 358 | - cl.id_lang = " . $this->idLang . " AND | |
| 359 | - cl.id_shop = c.id_shop_default | |
| 360 | - WHERE | |
| 361 | - c.id_parent=" . $categoria['id_category'] . " | |
| 362 | - AND c.id_shop_default = " . $this->idShop; | |
| 363 | - $categoriasHijos = Db::getInstance()->executeS($sqlHijos); | |
| 364 | - $num++; | |
| 365 | - foreach ($categoriasHijos AS $categoriaHijo) { | |
| 366 | - $html .= "<option class='imaxcategory_" . $num . "' value='" . $categoriaHijo['id_category'] . "'>" . $categoriaHijo['name'] ." :: " . $categoriaHijo['id_category'] . '</option>'; | |
| 367 | - $objRespueta = $this->getHijos($categoriaHijo, $html, $id_lang, $num); | |
| 368 | - } | |
| 369 | - $num = $numInterno; | |
| 370 | - } | |
| 371 | - | |
| 372 | - public function getHomeCategories($id_lang, $id_shop = false, $active = true) { | |
| 373 | - if (!Validate::isBool($active)) | |
| 374 | - die(Tools::displayError()); | |
| 375 | - $query = 'SELECT ' | |
| 376 | - . ' c.`id_category`, cl.`name`, cl.`link_rewrite`, cs.`id_shop` ' | |
| 377 | - . ' FROM ' | |
| 378 | - . ' `' . _DB_PREFIX_ . 'category` c ' | |
| 379 | - . ' LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ' | |
| 380 | - . ' ON (c.`id_category` = cl.`id_category`) ' | |
| 381 | - . ' INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ' | |
| 382 | - . ' ON (cs.`id_category` = c.`id_category` ) ' | |
| 383 | - . ' WHERE ' | |
| 384 | - . ' `id_lang` = ' . $id_lang . ' ' | |
| 385 | - . ($id_shop ? ' AND cs.id_shop=' . $id_shop : ' ') | |
| 386 | - . ' AND c.`is_root_category` = 1 ' | |
| 387 | - . ' AND `active` = ' . $active | |
| 388 | - . ' GROUP BY c.`id_category` ' | |
| 389 | - . ' ORDER BY cs.`position` ASC '; | |
| 390 | - $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); | |
| 391 | - return $result; | |
| 392 | - } | |
| 393 | - | |
| 394 | 381 | } | ... | ... |
imaxaddcatbyfeature_cron.php
| ... | ... | @@ -5,7 +5,7 @@ include_once(dirname(__FILE__).'../../init.php'); |
| 5 | 5 | include_once(dirname(__FILE__).'/../modules/imaxaddcatbyfeature/imaxaddcatbyfeature.php'); |
| 6 | 6 | |
| 7 | 7 | $token = $_GET['token']; |
| 8 | -$tokenLocal = Configuration::get(imaxnovedades::prefijo.'TOKEN'); | |
| 8 | +$tokenLocal = Configuration::get(imaxaddcatbyfeature::prefijo.'TOKEN'); | |
| 9 | 9 | if (empty($token) || $token != $tokenLocal) { |
| 10 | 10 | die('Token no valido'); |
| 11 | 11 | } | ... | ... |
js/functions.js
| 1 | 1 | $(function () { |
| 2 | - $("#arbolCategorias").dynatree({ | |
| 3 | - checkbox: true, | |
| 4 | - selectMode: 2, | |
| 5 | - debugLevel: 0, | |
| 6 | - onDblClick: function (node, event) { | |
| 7 | - //Marcar una opciรณn al hacerle doble click | |
| 8 | - node.toggleSelect(); | |
| 9 | - }, | |
| 10 | - onKeydown: function (node, event) { | |
| 11 | - //Marcar la opciรณn activa usando la barra espaciadora | |
| 12 | - if (event.which == 32) { | |
| 13 | - node.toggleSelect(); | |
| 14 | - return false; | |
| 15 | - } | |
| 16 | - }, | |
| 17 | - // The following options are only required, if we have more than one tree on one page: | |
| 18 | - // initId: "treeData", | |
| 19 | - cookieId: "dynatree-Cb3", | |
| 20 | - idPrefix: "dynatree-Cb3-" | |
| 21 | - }); | |
| 22 | - | |
| 23 | - //Expandir los nodos activos | |
| 24 | - var arbol = $("#arbolCategorias").dynatree("getTree"); | |
| 25 | - var marcados = arbol.getSelectedNodes(false); | |
| 26 | - for (var i = 0, len = marcados.length; i < len; i++) { | |
| 27 | - marcados[i].makeVisible(); | |
| 28 | - } | |
| 29 | - | |
| 30 | - //Buscador | |
| 31 | - $('input[name="buscador"]').keyup(function () { | |
| 32 | - var texto = $(this).val(); | |
| 33 | - var arbol = $("#arbolCategorias").dynatree("getTree"); | |
| 34 | - arbol.getRoot().toDict(true, function (dict) { | |
| 35 | - if (dict.title !== null) { | |
| 36 | - var nodo = arbol.getNodeByKey(dict.key); | |
| 37 | - if (texto !== '' && dict.title.toLowerCase().search(texto.toLowerCase()) >= 0) { | |
| 38 | - //Lo marcamos | |
| 39 | - nodo.makeVisible(); | |
| 40 | - $(nodo.span).addClass('imax_marcado'); | |
| 41 | - } | |
| 42 | - else { | |
| 43 | - //Lo desmarcamos | |
| 44 | - $(nodo.span).removeClass('imax_marcado'); | |
| 45 | - } | |
| 46 | - } | |
| 47 | - }); | |
| 48 | - }); | |
| 49 | 2 | |
| 50 | - //Botรณn enviar | |
| 51 | - $('button[name="opcionesConfiguracion"]').click(function () { | |
| 52 | - //Asรญ accedo a los ids de los check marcados | |
| 53 | - var arbolCat = $("#arbolCategorias").dynatree("getTree"); | |
| 54 | - var marcadosCat = arbolCat.getSelectedNodes(false); | |
| 3 | + | |
| 55 | 4 | |
| 56 | - var catString = ""; | |
| 57 | - for (var x in marcadosCat) { | |
| 58 | - catString += marcadosCat[x].data.key + ","; | |
| 59 | - } | |
| 60 | - if (catString.length > 0) { | |
| 61 | - catString = catString.substring(0, catString.length - 1); | |
| 62 | - } | |
| 63 | - $('[name="catList"]').val(catString); | |
| 64 | - $(this).parent().submit(); | |
| 65 | - }); | |
| 66 | -}); | |
| 67 | 5 | |
| 68 | 6 | |
| 69 | 7 | |
| 70 | -//Agregamos los criterios de desactivacion | |
| 71 | - $('#tablaCriteriosDesactivacion tbody').sortable({ | |
| 8 | +//Agregamos los criterios de categorizacion | |
| 9 | + $('#tablaCriteriosCategorizacion tbody').sortable({ | |
| 72 | 10 | stop: rellenarOrden |
| 73 | 11 | }); |
| 12 | + console.log(criteriosSeleccionados); | |
| 74 | 13 | for(var i in criteriosSeleccionados) { |
| 75 | - agregarFilaCriterioDesactivacion(criteriosSeleccionados[i]['caracteristicaSeleccionada'], criteriosSeleccionados[i]['valorCaracteristicaSeleccionado'], criteriosSeleccionados[i]['tipoSeleccionado']); | |
| 14 | + agregarFilaCriterioCategorizacion(criteriosSeleccionados[i]['caracteristicaSeleccionada'], criteriosSeleccionados[i]['valorCaracteristicaSeleccionado'], criteriosSeleccionados[i]['tipoSeleccionado']); | |
| 76 | 15 | } |
| 77 | 16 | $('button[name="agregarCriterio"]').click(function() { |
| 78 | - agregarFilaCriterioDesactivacion(); | |
| 17 | + agregarFilaCriterioCategorizacion(); | |
| 79 | 18 | }); |
| 80 | - | |
| 19 | +}); | |
| 81 | 20 | |
| 82 | 21 | /** |
| 83 | 22 | * Pone valor al input de orden. |
| 84 | 23 | */ |
| 85 | 24 | function rellenarOrden() { |
| 86 | 25 | var orden = 0; |
| 87 | - $('#tablaCriteriosDesactivacion input[name*="orden"]').each(function() { | |
| 26 | + $('#tablaCriteriosCategorizacion input[name*="orden"]').each(function() { | |
| 88 | 27 | $(this).val(orden); |
| 89 | 28 | orden++; |
| 90 | 29 | }); |
| 91 | 30 | } |
| 92 | 31 | |
| 93 | 32 | /** |
| 94 | - * Agrega una fila de desactivacion en la tabla. | |
| 33 | + * Agrega una fila de categorizacion en la tabla. | |
| 95 | 34 | * @param {int} caracteristicaSeleccionada |
| 96 | 35 | * @param {int} valorCaracteristicaSeleccionado |
| 97 | 36 | * @param {int} tipoSeleccionado |
| 98 | 37 | */ |
| 99 | -function agregarFilaCriterioDesactivacion(caracteristicaSeleccionada, valorCaracteristicaSeleccionado, tipoSeleccionado) { | |
| 38 | +function agregarFilaCriterioCategorizacion(caracteristicaSeleccionada, valorCaracteristicaSeleccionado, tipoSeleccionado) { | |
| 100 | 39 | var indice = -1; |
| 101 | - $('#tablaCriteriosDesactivacion').find('td:first-child').children('select[name^="desactivacion"]').each(function() { | |
| 40 | + $('#tablaCriteriosCategorizacion').find('td:first-child').children('select[name^="categorizacion"]').each(function() { | |
| 102 | 41 | var nombreTemp = $(this).attr('name').split('['); |
| 103 | 42 | var indiceTemp = nombreTemp[1].substr(0, nombreTemp[1].length - 1); |
| 104 | 43 | if(indiceTemp > indice) { |
| ... | ... | @@ -108,15 +47,15 @@ function agregarFilaCriterioDesactivacion(caracteristicaSeleccionada, valorCarac |
| 108 | 47 | indice++; |
| 109 | 48 | |
| 110 | 49 | var html = '<tr>'; |
| 111 | - html += '<td>' + generarSelectDesactivacion('caracteristicaSeleccionada', indice, caracteristicasFormateadas, caracteristicaSeleccionada) + '</td>'; | |
| 112 | - html += '<td>' + generarSelectDesactivacion('valorCaracteristicaSeleccionado', indice, (typeof valoresCaracteristicaFormateados[caracteristicaSeleccionada] !== 'undefined' ? valoresCaracteristicaFormateados[caracteristicaSeleccionada] : { 0: '- Seleccione uno -' }), valorCaracteristicaSeleccionado) + '</td>'; | |
| 113 | - html += '<td>' + generarSelectDesactivacion('tipoSeleccionado', indice, tiposFormateados, tipoSeleccionado) + '</td>'; | |
| 114 | - html += '<td><input type="hidden" name="desactivacion[' + indice + '][orden]" value=""/> <input class="btn btn-default" type="button" name="eliminarFilaCriterioDesactivacion" value="-"/></td>'; | |
| 50 | + html += '<td>' + generarSelectCategorizacion('caracteristicaSeleccionada', indice, caracteristicasFormateadas, caracteristicaSeleccionada) + '</td>'; | |
| 51 | + html += '<td>' + generarSelectCategorizacion('valorCaracteristicaSeleccionado', indice, (typeof valoresCaracteristicaFormateados[caracteristicaSeleccionada] !== 'undefined' ? valoresCaracteristicaFormateados[caracteristicaSeleccionada] : { 0: '- Seleccione uno -' }), valorCaracteristicaSeleccionado) + '</td>'; | |
| 52 | + html += '<td>' + generarSelectCategorizacion('tipoSeleccionado', indice, tiposFormateados, tipoSeleccionado) + '</td>'; | |
| 53 | + html += '<td><input type="hidden" name="categorizacion[' + indice + '][orden]" value=""/> <input class="btn btn-default" type="button" name="eliminarFilaCriterioCategorizacion" value="-"/></td>'; | |
| 115 | 54 | html += '</tr>'; |
| 116 | 55 | |
| 117 | 56 | var fila = $(html); |
| 118 | 57 | //Eliminar fila |
| 119 | - fila.find('input[name="eliminarFilaCriterioDesactivacion"]').click(function() { | |
| 58 | + fila.find('input[name="eliminarFilaCriterioCategorizacion"]').click(function() { | |
| 120 | 59 | $(this).parent().parent().remove(); |
| 121 | 60 | }); |
| 122 | 61 | //Modificar el select de valores |
| ... | ... | @@ -125,10 +64,29 @@ function agregarFilaCriterioDesactivacion(caracteristicaSeleccionada, valorCarac |
| 125 | 64 | var nombreTemp = $(this).attr('name').split('['); |
| 126 | 65 | var indiceTemp = nombreTemp[1].substr(0, nombreTemp[1].length - 1); |
| 127 | 66 | fila.find('select[name*="valorCaracteristicaSeleccionado"]').remove(); |
| 128 | - parent.append(generarSelectDesactivacion('valorCaracteristicaSeleccionado', indiceTemp, (typeof valoresCaracteristicaFormateados[$(this).val()] !== 'undefined' ? valoresCaracteristicaFormateados[$(this).val()] : { 0: '- Seleccione uno -' }))); | |
| 67 | + parent.append(generarSelectCategorizacion('valorCaracteristicaSeleccionado', indiceTemp, (typeof valoresCaracteristicaFormateados[$(this).val()] !== 'undefined' ? valoresCaracteristicaFormateados[$(this).val()] : { 0: '- Seleccione uno -' }))); | |
| 129 | 68 | }); |
| 130 | 69 | |
| 131 | - $('#tablaCriteriosDesactivacion tbody').append(fila); | |
| 70 | + $('#tablaCriteriosCategorizacion tbody').append(fila); | |
| 132 | 71 | |
| 133 | 72 | rellenarOrden(); |
| 134 | 73 | } |
| 74 | + | |
| 75 | + | |
| 76 | +/** | |
| 77 | + * Devuelve un select generado con los datos. | |
| 78 | + * @param {String} nombre | |
| 79 | + * @param {int} indice | |
| 80 | + * @param {Object} datos | |
| 81 | + * @param {String} seleccionado | |
| 82 | + * @returns {String} | |
| 83 | + */ | |
| 84 | +function generarSelectCategorizacion(nombre, indice, datos, seleccionado) { | |
| 85 | + var html = '<select name="categorizacion[' + indice + '][' + nombre + ']">'; | |
| 86 | + for (var value in datos) { | |
| 87 | + html += '<option value="' + value + '" ' + (value == seleccionado ? 'selected="selected"' : '') + '>' + datos[value] + '</option>'; | |
| 88 | + } | |
| 89 | + html += '</select>'; | |
| 90 | + | |
| 91 | + return html; | |
| 92 | +} | |
| 135 | 93 | \ No newline at end of file | ... | ... |
sql-install.php
| ... | ... | @@ -8,12 +8,3 @@ $sql[] = "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_.self::prefijo."movimiento` ( |
| 8 | 8 | ) |
| 9 | 9 | COLLATE='utf8_general_ci' |
| 10 | 10 | ENGINE=MyIsam;"; |
| 11 | - | |
| 12 | - | |
| 13 | -$sql[] = "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_.self::prefijo."addCatFeature` ( | |
| 14 | - `id_feature_value` INT(10) NOT NULL, | |
| 15 | - `id_category` INT(10) NOT NULL, | |
| 16 | - PRIMARY KEY (`id_feature_value`, `id_category`) | |
| 17 | - ) | |
| 18 | - COLLATE='utf8_general_ci' | |
| 19 | - ENGINE=MyIsam;"; | |
| 20 | 11 | \ No newline at end of file | ... | ... |