Jump to content

How to create a custom json output ( API Webservice Prestashop 1.6 )


Recommended Posts

Hi everyone,

I'm using prestashop 1.6.1.24

I want to customize Prestashop web service for my own usage but I don't know how

I made the Webservice key for product 

i want a json output like this :

a page with all product json

{
     "count": "150", // Total number of products
     "max_pages": "2", // Total number of pages considering 100 products per page
     "products": [
        {
            "title": "10 Pro",
            "subtitle": "10 Pro"
            "page_unique": "34", // product id
            "current_price": "5000000",
            "old_price": "5500000",
            "availability": "instock",
            "category_name": "mobile",
            "image_link": "https://domain.com/images/test.jpg",
            "page_url": "https://domain.com/product/34/",
            "short_desc": "A good phone",
            "spec": {
                "memory": "4GB",
                "camera": "12mp",
                "color": "black",
                ...
            },
        },
        "products": [
        {
            "title": "10 max",
            "subtitle": "10 max"
            "page_unique": "314", // product id
            "current_price": "5000000",
            "old_price": "5500000",
            "availability": "instock",
            "category_name": "mobile",
            "image_link": "https://domain.com/images/test2.jpg",
            "page_url": "https://domain.com/product/314/",
            "short_desc": "A good phone2",
            "spec": {
                "memory": "8GB",
                "camera": "20mp",
                "color": "white",
                ...
            },
        },
        ... 
...
...
...
}

 

Edited by lordad
add tag (see edit history)
Link to comment
Share on other sites

Hello, yes you can return response like this.

 

$this->response['response'] = array(
'status' => 'success',
'message' => 'Update',
'data' => $data
);
return $this->fetchJSONResponse();

protected function fetchJSONResponse()
{
    $response = array();
    if (!empty($this->response)) {
    $response = $this->response;
}
header('Content-Type: application/json');
return $response;
}

  • Like 1
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...