How to search with Prestashop web service

I am trying to use Prestashop web service to create an app for my store. To find products, we know that we can use

http://store_url/api/search?query=keywords&language=1

      

But if I'm looking for something, it won't give me more than 10 results. I've tried using &limit

and &display

. But nothing works.

If there is an alternative, please let me know.

+3


source to share


2 answers


After breaking down the wall a lot, I found work around. So the problem with this file is in / classes / webservice,

WebserviceSpecificManagementSearch.php

      

Around line 87 you will find

$results = Search::find($this->wsObject->urlFragments['language'], $this->wsObject->urlFragments['query'], 1,1, 'position', 'desc', true, false);

      

This last but second argument tells the search functions that this is an ajax search. CREATING A LIE DOES NOT WORK .

Instead, you need to go to /classes/Search.php and look for the "find" function. Starting at line 278, you will find this:

if ($ajax)
    {
        $sql = 'SELECT DISTINCT p.id_product, pl.name pname, cl.name cname,
                    cl.link_rewrite crewrite, pl.link_rewrite prewrite '.$score.'
                FROM '._DB_PREFIX_.'product p
                INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (
                    p.`id_product` = pl.`id_product`
                    AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
                )
                '.Shop::addSqlAssociation('product', 'p').'
                INNER JOIN `'._DB_PREFIX_.'category_lang` cl ON (
                    product_shop.`id_category_default` = cl.`id_category`
                    AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
                )
                WHERE p.`id_product` '.$product_pool.'
                ORDER BY position DESC LIMIT 10');
        return $db->executeS($sql);
    }

      

As you can see, the results are capped at 10. So you need a way to tell the function that it calls the WebService. So I did it. It's pretty simple. Instead



ORDER BY position DESC LIMIT 10'

      

using:

ORDER BY position DESC LIMIT '.(($isWS)? '10000': '10')

      

The $ isWS variable is of type Boolean. So you will have to change your search function declaration to this:

public static function find($id_lang, $expr, $page_number = 1, $page_size = 1, $order_by = 'position',
    $order_way = 'desc', $ajax = false, $use_cookie = true, Context $context = null, $isWS = false)

      

Once you have done that, you can pass the value for $ isWS from WebserviceSpecificManagementSearch. So replace it with line 87:

$results = Search::find($this->wsObject->urlFragments['language'], $this->wsObject->urlFragments['query'], 1,1, 'position', 'asc', true, false, null, true);

      

Hope this helps anyone with the same problem.

+3


source


I think you can try this way of looking for products:

http://store_url/api/products/?display=full&limit=2&filter[name]=[print]%

      

You can change display

and limit

.



He is from Prestashop Domain Web Service .

Hope this helps anyone.

0


source







All Articles