Prestashop: Show products based on SQL

0

I need to show specific products through a sql that I already have and that works well.

JQuery works perfectly for me, but with a button and PHP I do not really know how to do it.

The fact is that I have 2 combos on the home page and the user must select one and then another, to give the button to search and show these products depending on the chosen in those two combos.

I do not know how to put that form and where I should call that button to bring me those products.

I understand that I do it in the PHP and afterwards from the tpl I call that function, but I do not know where to start.

Does Alguin throw me a little light?

This is the jquery code that works for me:

function mostrarproductosporlocalidadyespecialidad(id_localid){
$("#productoselegidos").html("");
var especialidad = $("#sespecialidad").val();
var poblacion = id_localid;
$("#productoselegidos").append("Especialidad: " + especialidad + " Poblacion: " + poblacion);

var params = {
    "especialidad" : especialidad,
    "poblacion" : poblacion
};

$.ajax({
    data: params,
    url: 'adminasesmed/obtenerproductos.php',
    type: 'post',
    /*datatype: 'json',*/
    success: function(response){
        /*Ojo a ese $.parseJSON porque es un bug en jQuery*/
        /*$.each($.parseJSON(response), function(index, data){  
            $("#productoselegidos").append("<br>Id de productos:" + data.id_product);
        });*/
        data = JSON.parse(response);
        console.log(data);
        for(i=0;i<data.length;i++){
            /*console.log(data[i].id_product);*/
            $("#productoselegidos").append("<div style='float:left'>" + 
                data[i].name + 
                "<br>" + 
                data[i].description_short + 
                "</div>");              
        }           
    }
})

}

Thanks

    
asked by jandresplp 24.01.2017 в 12:59
source

1 answer

0

I can not comment because I do not have enough points yet, but from PHP you should use the Prestashop Webservice. I do not know if you're doing it now or if you attack the database directly.

If you are doing it through the API, the URL to the image is in the field

id_default_image

To obtain it you would have to make a request to

/api/products/[Id del producto]

I hope I can help you.

    
answered by 28.04.2017 в 10:56