• Resolved dpadureanu

    (@dpadureanu)


    We are trying to add a variant to a variable product using v3 API.
    First we add attributes to the system: Culoare – Rosu, Gri, Negru; Marime – 32, 34, 36.
    This is ok we see effect in the backend.

    Then we add variable product with the following JSON, containing all attribues combinations available.
    {
    “regular_price”:”10″,
    “sku”:”2″,
    “attributes”:[
    {
    “visible”:”true”,
    “options”:[
    “Rosu”,
    “Negru”,
    “Gri”
    ],
    “variation”:”true”,
    “id”:2
    },
    {
    “visible”:”true”,
    “options”:[
    “32”,
    “34”
    ],
    “variation”:”true”,
    “id”:3
    }
    ],
    “status”:”draft”,
    “description”:””,
    “sale_price”:”10″,
    “IDSMARTCASH”:2,
    “manage_stock”:”true”,
    “type”:”variable”,
    “tax_class”:”tva-b-9″,
    “name”:”Pitza”
    }
    The result is successful (we receive id for product 2092 and we see the product in the backend).
    Then we call POST method https://staging28.market.smartcash.store/wp-json/wc/v3/products/2092/variations
    with the following JSON
    {
    “regular_price”:”10″,
    “sku”:”7″,
    “attributes”:[
    {
    “id”:2,
    “option”:”Gri”,
    “name”:”Culoare”
    },
    {
    “id”:3,
    “option”:”32″,
    “name”:”Marime”
    }
    ],
    “status”:”draft”,
    “description”:””,
    “sale_price”:”10″,
    “IDSMARTCASH”:7,
    “manage_stock”:”true”,
    “tax_class”:”tva-b-9″
    }
    The result have no errors and the variant is added with the id = 2121.

    However we cannot see the variant in the list of variations in the backend.
    We noticed that for manually added variations the variable product hold in the array “variations” all the id’s of the “childs”
    ex:
    “variations”: [ 2001, 2002, 2003 ], But on our case, when adding variations through API (v3) this array is always empty.

    What are we missing?
    Everything seems to be ok but WooCommerce does not update the “variations” node and consequently the backend.`

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Hi there ??

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers.

    Thread Starter dpadureanu

    (@dpadureanu)

    Hi, We are trying to add a variant to a variable product using v3 API. First we add attributes to the system: Culoare – Rosu, Gri, Negru; Marime – 32, 34, 36. This is ok we see effect in the backend.
    Then we add variable product with the following JSON, containing all attributes combinations available.

    {
    “sku”:”2″,
    “name”:”Pitza”,
    “description”:””,
    “regular_price”:”10″,
    “sale_price”:”10″,
    “manage_stock”:”true”,
    “type”:”variable”,
    “tax_class”:”tva-b-9″,
    “status”:”draft”,
    “IDSMARTCASH”:2,
    “attributes”:[
    {
    “id”:2,
    “visible”:”true”,
    “variation”:”true”,
    “options”:[“Rosu”,”Negru”,”Gri”]
    },
    {
    “id”:3,
    “visible”:”true”,
    “variation”:”true”,
    “options”:[“32″,”34”]
    }
    ],
    }

    The result is successful (we receive id for product 2092 and we see the product in the backend as variation product).
    Then we call POST method https://staging28.market.smartcash.store/wp-json/wc/v3/products/2092/variations with the following JSON:

    {
    “sku”:”7″,
    “description”:””,
    “regular_price”:”10″,
    “sale_price”:”10″,
    “manage_stock”:”true”,
    “tax_class”:”tva-b-9″,
    “status”:”draft”,
    “IDSMARTCASH”:7,
    “attributes”:[
    {
    “id”:2,
    “name”:”Culoare”,
    “option”:”Gri”
    },
    {
    “id”:3,
    “name”:”Marime”,
    “option”:”32″
    }
    ],
    }

    The result have no errors and the variant is added with the id = 2121. However we cannot see the variant in the list of variations in the backend.
    What are we missing?

    We noticed that for manually added variations the variable product hold in the array “variations” all the id’s of the “childs” ex: “variations”: [ 2001, 2002, 2003 ], But on our case, when adding variations through API (v3) this array is always empty.
    Everything seems to be ok but WooCommerce does not update the “variations” node and consequently the backend.

    Thread Starter dpadureanu

    (@dpadureanu)

    For anyone else having same problem, we found the solution by ourselves:
    The variations JSON should NOT include atribute “status”.

    When provided, woocommerce does not handle internally the error properly and even if it adds the variation it does not link it with the variable product.
    It should be reported to them to fix it in the future.

    Anyway it is a mistake to put “status” to a variation since it take this flag from the master product automatically.

    Plugin Support Gabriel – a11n

    (@gabrielfuentes)

    Hi @dpadureanu ??

    That’s wonderful! Thank you very much for sharing the solution with the WooCommerce community. ??

    Great! I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

    Cheers!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘WooCommerce product variations added through API not showing in backend’ is closed to new replies.