Lakshmanan PHP Posted January 7, 2016 Share Posted January 7, 2016 We are developing an android app using prestashop webservice. Currently we are able to obtain JSON response of categories successfully. We need to get subcategories and the products from a given category id. We found that this can be achieved through multiple requests api/categories/?output_format=JSON&filter[active]=1&display=[id,name]&filter[level_depth]=2 to get all categories /api/categories/?output_format=JSON&filter[active]=1&display=[id,name]&filter[id_parent]=47 to find subcategories in a category page /api/products/?output_format=JSON&filter[id_category_default]=47 to get all products of the given category in category page Is this the only way or any other right way to get all subcategories and the products from a given category id? Version 1.6 Link to comment Share on other sites More sharing options...
Lakshmanan PHP Posted January 18, 2016 Author Share Posted January 18, 2016 Still waiting for your support Hope someone will save us Thanks again Link to comment Share on other sites More sharing options...
rajesh_kumar Posted January 21, 2016 Share Posted January 21, 2016 hai Lakshmanan PHP, I am too developing android application using prestashop webservice. I am stopped in registering a new customer and add to cart..how did you do.. Plz say the webservice url to register and add to cart.... Link to comment Share on other sites More sharing options...
rajesh_kumar Posted February 1, 2016 Share Posted February 1, 2016 Hello reply......... Link to comment Share on other sites More sharing options...
umakantsuman Posted May 27, 2016 Share Posted May 27, 2016 Hi Lakshmanan PHP, Please can ypu tell me , which web service call to checkout in prestashop 1.6 . Actually I want to create web service for all event like show product list, show product detail, user login , checkout etc.... Link to comment Share on other sites More sharing options...
rvkvino Posted January 21, 2020 Share Posted January 21, 2020 On 1/18/2016 at 12:26 PM, Lakshmanan PHP said: Still waiting for your support Hope someone will save us Thanks again Did you get any solution, now I'm in same situation need to know the solution for this, If you were find the solutions means please share Link to comment Share on other sites More sharing options...
Victor Casajuana Mas Posted September 17, 2020 Share Posted September 17, 2020 output_format=JSON https://devdocs.prestashop.com/1.7/webservice/getting-started/ Link to comment Share on other sites More sharing options...
rvkvino Posted September 23, 2020 Share Posted September 23, 2020 (edited) I have tried below but not working , $opt = array( 'resource' =>'categories', 'filter[id]' => "[$data->id_category]", 'output_format' => 'JSON', 'display' => 'full' ); Edited September 23, 2020 by rvkvino (see edit history) Link to comment Share on other sites More sharing options...
Victor Casajuana Mas Posted September 23, 2020 Share Posted September 23, 2020 I send the output_format in url: https://[email protected]/api/?output_format=JSON Link to comment Share on other sites More sharing options...
rvkvino Posted September 23, 2020 Share Posted September 23, 2020 This is working on while run directly in browser, I'm trying in PHP code so that it's not returning anything from my above code Link to comment Share on other sites More sharing options...
Tahsin Hasan Posted March 23, 2021 Share Posted March 23, 2021 `/prestashop/api/categories?language=1&output_format=JSON&display=full` gives below ```json active: "1" associations: {products: Array(1)} date_add: "2021-03-17 10:21:48" date_upd: "2021-03-17 10:21:48" description: null id: 4 id_parent: "3" id_shop_default: "1" is_root_category: "0" level_depth: "3" link_rewrite: null meta_description: null meta_keywords: null meta_title: null name: null nb_products_recursive: "1" position: "0" ``` here name is null. how to fix it? Link to comment Share on other sites More sharing options...
Nouhail AL FIDI Posted January 8, 2022 Share Posted January 8, 2022 (edited) Hello, I hope it's not too late to answer the question, but I figured out a way to get product details of a given category by overriding the Category class. Below you can find the steps that I have followed : Create a new prestashop module, I called mine : pn_productcategoryws Inside module's directory "pn_productcategoryws" create the php module file and call it : pn_productcategory_ws.php Then add the costructor to the class called : "Pn_ProductCategoryWs" public function __construct() { $this->name = 'ml_productcategoryws'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'Author'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Webservice Products By Category'); $this->description = $this->l('Display products details by category'); $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); } Then, inside the "pn_productcategoryws" create 2 subdirectories : "/override/classes" inside the classes directory create the file Category.php You should have by now this structure pn_productcategoryws __pn_productcategoryws.php __override ____classes _______Cateogory.php Inside your Category.php file you can modify the fields that you want to display by updating the protected class member $this->webserviceParameter as long as you update the function getProductsWs() that gets the data directly from the table you can, you just need to add LEFT JOINS each time you need an info from another table. I call the setWebServicesParameters function in the constructor to update the protected member. If you try to modify it directly, it doesn't work as prestashop cannot generate the overriden class by using this method. Don't forget to reinitialize your module once you finished modifying your files. The example below could help you get the data you want to display <?php class Category extends CategoryCore { /** * Category override constructor */ public function __construct($idCategory = null, $idLang = null, $idShop = null) { $this->clearCache(true); $this->setWebServicesParameters(); parent::__construct($idCategory, $idLang, $idShop); } /** * Function to add fields to product associations when getting categories. * @return void */ public function setWebServicesParameters() { $this->webserviceParameters = [ 'objectsNodeName' => 'categories', 'hidden_fields' => ['nleft', 'nright', 'groupBox'], 'fields' => [ 'id_parent' => ['xlink_resource' => 'categories'], 'level_depth' => ['setter' => false], 'nb_products_recursive' => ['getter' => 'getWsNbProductsRecursive', 'setter' => false], ], 'associations' => [ 'products' => array( 'resource' => 'product', 'getter' => 'getProductsWs', 'fields' => array( 'id_product' => array('required' => true), 'name' => array('required' => true), 'price' => array('required' => true), 'quantity' => array('required' => true), 'date_add' => array('required' => true), 'id_image' => array('required' => true), 'on_sale' => array('required' => true), 'reduction' => array('required' => true), 'link_rewrite' => array('required' => true), ), ), ], ]; } /** * Overriding getProductsWs to add product fields to the result. * @throws PrestaShopDatabaseException */ public function getProductsWs() { return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT p.id_product, p.price, pl.name, sa.quantity, p.date_add, i.id_image, p.on_sale, sp.reduction, pl.link_rewrite FROM `' . _DB_PREFIX_ . 'category_product` cp LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (cp.`id_product` = pl.`id_product`) LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON (cp.`id_product` = p.`id_product`) LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product`) LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa ON (sa.`id_product` = p.`id_product`) LEFT JOIN `' . _DB_PREFIX_ . 'specific_price` sp ON (sp.`id_product` = p.`id_product`) WHERE cp.`id_category` = ' . (int)$this->id . ' AND pl.id_lang = 1 AND i.cover = 1 GROUP BY p.`id_product` ORDER BY p.`date_add` DESC LIMIT 12'); } } Edited January 8, 2022 by Nouhail AL FIDI (see edit history) 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