jasonknight / woocommerce-json-api

A simple, Abstract JSON API for Wordpress' Awesome Plugin: WooCommerce
58 stars 21 forks source link

Product attribute 'attributes' is represented as array, map or string #54

Closed guisrx closed 10 years ago

guisrx commented 10 years ago

The 'get_products' method returns the object product with its attribute 'attributes' represented as array, map or string depending of the product type representation on Woocommerce. Can't parse it correctly this way.

jasonknight commented 10 years ago

Can you be a bit more specific with what you got, and what you expect.

guisrx commented 10 years ago

Sorry. When I executed a 'get_products' request I got this JSON bellow. Note the lines: "attributes":[], "attributes":{ and "attributes":"". The object Product has 3 different types for the "attributes" field. When I try to parse it in Java with Gson I got an error because it can't identify correctly the type.

{
    "action":"woocommerce_json_api",
    "arguments":{
        "include":{
            "categories":false,
            "featured_image":false,
            "images":false,
            "reviews":false,
            "tags":false,
            "variations":false},
        "order":"asc",
        "order_by":"ID",
        "token":"1234",
        "per_page":20,
        "page":1},
    "proc":"get_products",
    "status":true,
    "errors":[],
    "warnings":[],
    "notifications":[],
    "payload":[
        {
            "id":"16",
            "name":"Product1",
            "slug":"product1",
            "type":"product",
            "description":"Product1 anything ...",
            "short_description":"product description ....",
            "parent_id":"0",
            "publishing":"publish",
            "sku":"",
            "downloadable":"no",
            "visibility":"visible",
            "virtual":"no",
            "manage_stock":"yes",
            "sold_individually":"no",
            "featured":"no",
            "allow_backorders":"no",
            "quantity":"50",
            "height":"",
            "weight":"1",
            "length":"",
            "price":"20",
            "regular_price":"15",
            "sale_price":"20",
            "sale_from":"",
            "sale_to":"",
            "status":"instock",
            "attributes":[],
            "tax_class":"",
            "tax_status":"none",
            "product_type":"simple"},
        {
            "id":"22",
            "name":"Product 3",
            "slug":"product-3",
            "type":"product",
            "description":"product 3 description ....",
            "short_description":"description .....",
            "parent_id":"0",
            "publishing":"publish",
            "sku":"",
            "downloadable":"no",
            "visibility":"visible",
            "virtual":"no",
            "manage_stock":"yes",
            "sold_individually":"no",
            "featured":"no",
            "allow_backorders":"no",
            "quantity":"65",
            "height":"",
            "weight":"",
            "length":"",
            "price":"",
            "regular_price":"",
            "sale_price":"",
            "sale_from":"",
            "sale_to":"",
            "status":"instock",
            "attributes":{
                "size":{
                    "name":"Size",
                    "value":"small | medium | large",
                    "position":"0",
                    "is_visible":1,
                    "is_variation":1,
                    "is_taxonomy":0},
                "color":{
                    "name":"Color",
                    "value":"green | red | orange | yellow | black",
                    "position":"1",
                    "is_visible":1,
                    "is_variation":1,
                    "is_taxonomy":0}},
            "tax_class":"",
            "tax_status":"none",
            "product_type":"variable"},                                                                                                     
        {
            "id":"24",
            "name":"Variation #24 of Product 3",
            "slug":"product-22-variation-2",
            "type":"product_variation",
            "description":"",
            "short_description":"",
            "parent_id":"22",
            "publishing":"publish",
            "sku":"",
            "downloadable":"no",
            "visibility":"visible",
            "virtual":"no",
            "manage_stock":"no",
            "sold_individually":"no",
            "featured":"no",
            "allow_backorders":"no",
            "quantity":"",
            "height":"",
            "weight":"",
            "length":"",
            "price":"",
            "regular_price":"",
            "sale_price":"",
            "sale_from":"",
            "sale_to":"",
            "status":"instock",
            "attributes":"",
            "tax_class":"",
            "tax_status":"none",
            "product_type":"unknown",
            "featured_image":[]}],
    "statistics":{
        "products":"3",
        "products_in_trash":"0",
        "variations":"1",
        "orders":"0",
        "user_id":1},
    "payload_length":4
}

Thanks. Selau.

jasonknight commented 10 years ago

K, see if that does it, not it will force it to always be a hash.

jasonknight commented 10 years ago

Also, would you be interested in sending me some notes about using Java to connect to the API? Also I am interested in your feed back, or ways it can be made easier. It'd be nice to add some documentation on using Java to connect to WooCom through the API.

guisrx commented 10 years ago

Yeah. It's working! Thanks!

I'm developing an native Android application to a store that uses Woocommerce. I will use Woocommerce as a back-end through woocommerce-json-api, so I will need full access to its functionalities. I will write a tutorial about using Java through the API.

Do you have some idea of when the cart functionality will be available on the woocommerce-json-api? Maybe I can contribute with some help implementing it.