OSCommerce - Listado de productos por fabricante en sección administrador

Después de varias horas de estar haciendo pruebas para que quedará la modificación en la instalación de oscommerce para un cliente, por fin termine con el código. No es perfecto, pero funciona.

La petición fue la siguiente: realizar búsquedas en la sección del catalogo, ya sea por el modelo del producto o por el fabricante (marca) del mismo.

Para la búsqueda en el campo search utilicé una contribución, que ya estaba en oscommerce.org: Admin Categories/Products Search Improvement.

Para el segundo caso, no encontré algo que funcionará, vi un post en el foro que mencionaba que ya habia contribuciones, pero o no la encontré o no estaba lo que necesitaba.

Manos al código y aqui las instrucciones, son varios pasos y en realidad el unico archivo que modifique fue /catalog/admin/categories.php:

  1. Incluir el arreglo para el combobox. Aproximadamente en la linea 742.

    BUSCAR:
  2. if (isset($HTTP_GET_VARS['pID'])) {
    echo tep_image_submit('button_update.gif', IMAGE_UPDATE);
    } else {
    echo tep_image_submit('button_insert.gif', IMAGE_INSERT);
    }
    echo '&nbsp;&nbsp;<a href="' . tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . (isset($HTTP_GET_VARS['pID']) ? '&pID=' . $HTTP_GET_VARS['pID'] : '')) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';
    ?></td>
    </tr>
    </table></form>
    <?php
    }
    } else {

    AGREGAR:

    //Listado Fabricante
    $manufacturers_array = array(array('id' => '', 'text' => TEXT_NONE));
    $manufacturers_query = tep_db_query("select manufacturers_id, manufacturers_name from " . TABLE_MANUFACTURERS . " order by manufacturers_name");
    while ($manufacturers = tep_db_fetch_array($manufacturers_query)) {
    $manufacturers_array[] = array('id' => $manufacturers['manufacturers_id'],
    'text' => $manufacturers['manufacturers_name']);
    }
    // *********

  3. Incluir el combobox en la forma. Aproximadamente linea 782.

    BUSCAR:
  4. <?php
    echo tep_draw_form('goto', FILENAME_CATEGORIES, '', 'get');
    echo HEADING_TITLE_GOTO . ' ' . tep_draw_pull_down_menu('cPath', tep_get_category_tree(), $current_category_id, 'onChange="this.form.submit();"');

    AGREGAR:

    //Listado fabricante

    echo TEXT_PRODUCTS_MANUFACTURER . ' ' . tep_draw_pull_down_menu('mID', $manufacturers_array, $HTTP_GET_VARS['mID'], 'onChange="this.form.submit();"') . '<br>';

  5. Agregamos una condicional para el caso de tener un id de fabricante. Aproximadamente linea 806.

    BUSCAR:
  6. $categories_count = 0;
    $rows = 0;
    if (isset($HTTP_GET_VARS['search'])) {
    $search = tep_db_prepare_input($HTTP_GET_VARS['search']);
    $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id, c.sort_order, c.date_added, c.last_modified from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and cd.categories_name like '%" . tep_db_input($search) . "%' order by c.sort_order, cd.categories_name");

    AGREGAR:

    //Listado Fabricante
    } elseif (isset($HTTP_GET_VARS['mID'])) {
    $manufacturer = tep_db_prepare_input($HTTP_GET_VARS['mID']);
    $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.parent_id, c.sort_order, c.date_added, c.last_modified from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' and cd.categories_name like '%" . tep_db_input($manufacturer) . "%' order by c.sort_order, cd.categories_name");
    // ****

  7. Modificamos una condicional existente para agregar una subcategoria. Aproximadamente linea 824.

    BUSCAR:
  8. if (isset($HTTP_GET_VARS['search'])) $cPath= $categories['parent_id'];

    REEEMPLAZAR CON:

    //Listado Fabricantes
    if (isset($HTTP_GET_VARS['search']) or isset($HTTP_GET_VARS['mID'])) $cPath= $categories['parent_id'];

  9.  Agregamos una condicional para la busqueda de los productos. Aproximadamente linea 847.

    BUSCAR:
  10. <?php
    }

    $products_count = 0;
    if (isset($HTTP_GET_VARS['search'])) {
    $products_query = tep_db_query("select p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status, p2c.categories_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "' and p.products_id = p2c.products_id and (pd.products_name like '%" . tep_db_input($search) . "%' or p.products_model like '%" . tep_db_input($search) . "%') order by pd.products_name");

    AGREGAR:

    //Listado Fabricantes
    } elseif (isset($HTTP_GET_VARS['mID'])) {
    $products_query = tep_db_query("select m.manufacturers_id, p.manufacturers_id, p.products_id, pd.products_name, p.products_quantity, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_status from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_MANUFACTURERS . " m where p.products_status = '1' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "' and p.manufacturers_id = m.manufacturers_id and m.manufacturers_id = '" . (int)$HTTP_GET_VARS['mID'] . "' order by pd.products_name");
    // *************

  11. Colocamos codigo para encontrar el id de la categoria segun el producto seleccionado. Aproximadamente linea 868.

    BUSCAR:
  12. // Get categories_id for product if search
    if (isset($HTTP_GET_VARS['search'])) $cPath = $products['categories_id'];

    AGREGAR:

    // Listado Fabricante
    // Get categories_id for product if manufacturers
    if (isset($HTTP_GET_VARS['mID'])) {
    $category_manufacturer_query = tep_db_query("select p2c.products_id, p2c.categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p2c.products_id = " . $products['products_id'] );
    $category_manufacturer = tep_db_fetch_array($category_manufacturer_query);
    $cPath = $category_manufacturer['categories_id'];
    }
    // *****************

La contribución ya esta en oscommerce.org http://www.oscommerce.com/community/contributions,4746

Listo!

Comentarios

Entradas más populares de este blog

Yahoo! UI (yui) TabView como menu horizontal.

Truco: usar Firefox en el portal IDSE del IMSS

Visual Web Express Edition con MS Access Membership