Zocheyado Posted May 20, 2015 Share Posted May 20, 2015 So I am using Prestashop search in the API, which requires two inputs, query and language. I am inputting https://www.mysite.com/api/search/?query=handbag&language=1 and it works and returns a list of product and category ID's. Problem is that it only ever sends back 10 or less results. If I do something obscure I get 1-2 results but if I do something more generic that there should be hundreds of results for I only ever get 10. I also tried doing an &offset, &skip and &limit request like most API services use but to no avail.How can I get more then 10 results back at once and or how can I skip the first 10 so that if I want 20 I can call it twice once with an offset. 1 Link to comment Share on other sites More sharing options...
abyss996 Posted July 21, 2015 Share Posted July 21, 2015 So I am using Prestashop search in the API, which requires two inputs, query and language. I am inputting https://www.mysite.com/api/search/?query=handbag&language=1 and it works and returns a list of product and category ID's. Problem is that it only ever sends back 10 or less results. If I do something obscure I get 1-2 results but if I do something more generic that there should be hundreds of results for I only ever get 10. I also tried doing an &offset, &skip and &limit request like most API services use but to no avail. How can I get more then 10 results back at once and or how can I skip the first 10 so that if I want 20 I can call it twice once with an offset. This was asked in May and still no replies. I want to know the answer to this as well. Prestashop's documentation on its web service it really poor Link to comment Share on other sites More sharing options...
abyss996 Posted July 22, 2015 Share Posted July 22, 2015 I asked the same question at StackOverflow.com I didn't get any replies there either. Instead, I posted my own answer. Here it is: After much wall smashing, I've found a work around. So, the problem is in this file located at /classes/webservice, WebserviceSpecificManagementSearch.php Around line 87, you'll find $results = Search::find($this->wsObject->urlFragments['language'], $this->wsObject->urlFragments['query'], 1,1, 'position', 'desc', true, false); This the last but second argument tells the Search function that it's an ajax search. MAKING IT FALSE WILL NOT WORK. Instead, you need to go to /classes/Search.php and find the function "find". Starting at around line 278, you'll 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 pINNER 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 limited by 10. So you need a way to tell the function that it's being called by the WebService. So what I did was this. It's pretty simple. Instead of ORDER BY position DESC LIMIT 10' use: ORDER BY position DESC LIMIT '.(($isWS)? '10000': '10') The variable $isWS is type Boolean. So you'll have to change the find function's 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've done this, you can now pass in the value for $isWS from WebserviceSpecificManagementSearch. So change it to this at 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. I REQUEST THE PRESTASHOP DEVELOPERS TO FIX THIS 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now