Jump to content

Almost solved - Product filter module of a query and show results


Recommended Posts

I have a small problem that I have not yet been able to find the solution, I keep looking and trying so it is possible that in a few days I will find it, but let's see if I get it here before.

The question is this.

The prestashop is 1.7

I have a developed module that adds lots of expiration to the products, uses its own table with its own data, the id of the product, expiration date and lot .....

I have developed a module that searches and filters this table according to a date, type the facets module, but there is a problem, at the end after the explanation.

$sql = "select id_producto as id from "._DB_PREFIX_."lotes_caducidad  where fecha_caducidad  = '".$date."' group by id_producto";

I put a date type box in the sidebar and when the value changes it calls an ajax and a url

$('input[type="date"]').change(function(){
        
        $fecha = this.value;
        $.ajax({
            type: 'POST',
            data : "{}",
            url:'modules/filterlotes/sajax.php?fecha='+$fecha,
            dataType: "json",
            success : function(response) {
                $('#js-product-list').html(response)
                $('.total-products').html('')
            },
        });
          
    });

When calling the file you have the orders to search all the products of the category where the user is currently

$products_partial = Product::getProducts($id_lang, 0,0, 'name', 'asc', $id_category = $cat);
        $result = Product::getProductsProperties($this->context->language->id, $products_partial);

once a read is information is done a search and only the id that have lots of expiration with the chosen date are added to the array of final products

if(count($rows_l) > 0){
            foreach($rows_l as $pr){
                $clave = array_search($pr['id'], array_column($result, 'id_product'));
                $productos[] = $presenter->present(
                    $presentationSettings,
                    $assembler->assembleProduct($result[$clave]),
                    $this->context->language
                );
            }
        }else{
            $productos = [];
        }

Once filtered and added to the array I add it to the smarty variables and return the template or tpl file in Json

$products = $productos;
        $this->context->smarty->assign('products', $products);
echo json_encode($this->fetch($this->templateFile));

then as we have seen above the tpl file

{if isset($products)}
  <DIV class="products row">
    {foreach from=$products item="product"}
      {include file="catalog/_partials/miniatures/product.tpl" product=$product}
    {/foreach}
  </DIV>

{else}


  <DIV class="products">
      <H1>{l s='No hay productos' d='filterlotes'}</H1>
  </DIV>
 

{/if}

add it to div

$('#js-product-list').html(response)

Well after telling all this, here is my problem.The problem is that when I show the products, filtered, when I give them to organize by name, quantity or another order this filter is lost and they are always the same again.

How can I filter and change the order of the filtered products?

It is possible that all this is doing wrong, that there must be another way to use the filters and display them, I hope that someone can see and correct me.

If someone wants to see the operation

https://xativalowcost.com/presta17/3-women

Dates of lots 21/02/2018 and 01/03/2018

 

Thanks in advance

and nothing if someone can use this code to make their own filter

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...