Problems with Category List / Products

Asked

Viewed 31 times

1

I have work on a product screen with categories and subcategories, but I have found some problems:

WHAT I WANT TO DO:

I simply want to have a page with the list of products. On the side will be displayed the main categories and available subcategories. Having seen that. Already managed to list and currently it is displaying the products correctly but it is only when I click on the specific category, for example:

LIST OF PRODUCTS

  • MAGAZINES
    -- That is to say
    -- Behold
    -- Vogue

  • HQ’s
    -- DC
    -- Marvel

Everything on this list is categories: Magazines, HQ’s, DC, Behold, etc. They should all be like a filter.

WHAT’S GOING WRONG:

The page of produtos.php has the query that only searches the products of the specific category, that is, if I click on the subcategory Marvel, it will return the products that have the category Marvel. Okay? But if I click MAGAZINES or HQ’s she will not return anything and I want to return all of her products, that is, if I click on MAGAZINES she will return all products (I mean, Veja and Vogue), but the page contains the query to return specific products and not all products of a category.

WHAT I ONCE THOUGHT OF DOING:

I thought I’d make maybe one if/else which would validate if the option clicked was "MAGAZINE/COMICS" and would change the SQL query instructions but still I could not complete the logic of it.

I’ll leave 2 things here: category list code and product list code:

List of Categories:

<aside class="content-category col-lg-3">
     <h3>Lista de Produtos</h3>
          <ul class="list-category">
                    <?php
                    $QueryCategorias = $db->Executar("SELECT * FROM pro_categorias WHERE adm_id= $adm_id AND excluido = 0 AND depth = 0 ORDER BY pro_cat_nome ASC");
                    while ($ListaCategorias = $QueryCategorias->fetch_object()):
                        $QuerySubCategorias = $db->Executar("SELECT * FROM pro_categorias WHERE adm_id = $adm_id AND excluido = 0 AND parent_id = $ListaCategorias->pro_cat_id");
                        ?>
                    <li class="cat-item">
                        <?= $ListaCategorias->pro_cat_nome; ?>
                        <?php if($QuerySubCategorias): ?>
                            <ul class="sublist-category">
                                <a href="<?= $tdir ?>/produtos/<?= $adm_id ?>/<?= $ListaCategorias->pro_cat_id ?>#produtos">
                                    Todos
                                </a>
                                <?php while ($ListaSubCategorias = $QuerySubCategorias->fetch_object()): ?>
                                    <li class="subcat-item">
                                        <a href="<?= $tdir ?>/produtos/<?= $adm_id ?>/<?= $ListaSubCategorias->pro_cat_id ?>#produtos">
                                            <?= $ListaSubCategorias->pro_cat_nome; ?>
                                        </a>
                                    </li>
                                <?php endwhile; ?>
                            </ul>
                        <?php endif; ?>
                    </li>
                    <?php endwhile; ?>
                </ul>
            </aside>

List of Products:

<div class="produtoWrapper">
          <?php /*PRODUTOS*/
                        $produtos = $db->Consultar("produto_pro", "pro_id, pro_nome, pro_descricao, pro_avatar", "WHERE adm_id = $adm_id AND categoria_id = $pro_cat_id AND excluido = 0 ORDER BY pro_nome");
                        if ($produtos) {
                            foreach ($produtos as $produto) {

                                if (isset($lista_prioridade) && in_array($produto['pro_id'], $lista_prioridade)) continue;

                                $thumbnail = returnThumbnailURL($Dominio, $produto['pro_avatar']);
                                $produto['pro_descricao'] = strip_tags($produto['pro_descricao']);
                                $produto_nome = $produto['pro_nome'];
                                if (sizeof($produto['pro_nome']) > 20) $produto_nome .= "...";
                                ?>

                                <div class="col-md-4">
                                    <div class="thumbnail no-padding">
                                        <a href="<?= $tdir ?>/item/<?= $adm_id ?>/<?= $produto['pro_id'] ?>#item">
                                            <img src="<?= $thumbnail ?>" alt="<?= $produto_nome ?>">
                                        </a>
                                        <div class="produto-descricao">
                                            <p>
                                                <a href="<?= $tdir ?>/item/<?= $adm_id ?>/<?= $produto['pro_id'] ?>#item"><?= $produto_nome ?></a>
                                            </p>
                                            <!--<p class="small"><?= substr($produto['pro_descricao'], 0, 50); ?></p>-->
                                        </div>
                                    </div>
                                </div>
                            <?php }
                        } ?>
</div

And another thing to help you understand is the structure and relationship of the tables involved in this:

Structure and Relationships/Database:

In the bank I have a table that used the categories, each category has a id, one parent_id and a depth

the parent_id tells which parent category she is associated with and the depth indicates the level of the category

  • Electronic has parent_id = null and Depth = 0
  • Informatics is subcategory of Electronics so it has parent_id = 1 (pq id of Electronics in the database is 1) and Depth = 1
  • Monitors is a subcategory of the Informatics subcategory and therefore has parent_id = 10 (because the Informatics id in the database is 10) and Depth = 2

This is the idea of relationship of the categories in the table.

Well, that was it, I need a lot of help because I’ve been hitting myself with it for some time and I’ve tried some solutions but none of them worked.

Any doubt just comment that I answer.

Grateful!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.