Support » Plugin: Pods - Custom Content Types and Fields » Extend WooCommerce Product with relationship field

  • Resolved Carlos Longarela

    (@carloslongarela)


    Hi, I extended WooCommerce product with a new field cl_product_documents that is a relationship field with multiple options (a product can have several documents).

    If I add documents and check the product with the API I see it in meta_data

    {
    "meta_data": [
    		{
    			"key": "_pods_cl_product_documents",
    			"value": [
    				79,
    				75
    			]
    		},
    		{
    			"key": "cl_product_documents",
    			"value": "79"
    		},
    		{
    			"key": "cl_product_documents",
    			"value": "75"
    		}
    	]
    }

    But if I update documents with the API, nothing happen, I see in the API the new meta_data, but in admin, documents are the same. In database I see that wp_podsrel isn’t changed.

    Can you guide me about the correct method to update this field with the API REST from an external service, data sent was:

    {
    "meta_data": [
    		{
    			"key": "_pods_cl_product_documents",
    			"value": [
    				79,
    				75,
    				58
    			]
    		},
    		{
    			"key": "cl_product_documents",
    			"value": "79"
    		},
    		{
    			"key": "cl_product_documents",
    			"value": "75"
    		},
    		{
    			"key": "cl_product_documents",
    			"value": "58"
    		}
    	]
    }

    But the API result is:

    "meta_data": [
    		{
    			"id": 1813,
    			"key": "_pods_cl_product_documents",
    			"value": [
    				79,
    				75,
    				58
    			]
    		},
    		{
    			"id": 1816,
    			"key": "cl_product_documents",
    			"value": "58"
    		}
    	],

    Thanks in advance.

    Kindly regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    Don’t update _pods_cl_product_documents directly. That’s what Pods uses to maintain the order of items as set. Try saving just the cl_product_documents key with an array of IDs.

    Thread Starter Carlos Longarela

    (@carloslongarela)

    Thanks for your quick response Scott.

    If I send this JSON to the API:

    {
    "meta_data": [
    		{
    			"key": "cl_product_documents",
    			"value": [
    				54,
    				58
    			]
    		}
    ]
    }

    In json response I see that cl_product_documents is updated, but not _pods_cl_product_documents and table wp_podsrel is not updated and admin fields not updated.

    If I send this JSON to the API (with other document Ids):

    {
    "cl_product_documents": [
    	76,
    	79
    	]
    }

    Nothing changed in the product; the response is the previous response.

    My question is. Can I modify a relationship pod field (product extended with this field) by REST API without extending it or creating a new endpoint? Because I can’t find the response. I can modify other CPTs pods, simple fields… but with this, nothing works.

    Thanks in advance, Carlos Longarela.

    Thread Starter Carlos Longarela

    (@carloslongarela)

    UPDATE:

    If I create a new product by REST API and at creation, I send this JSON:

    {
    "meta_data": [
    		{
    			"key": "cl_product_documents",
    			"value": [
    				76,
    				79
    			]
    		}
    ]
    }

    Works fine, insert metadata, fields order in _pods_cl_product_documents data in wp_podsrel table and all works fine in backend and frontend.

    But the problem is that I can’t modify that data to works fine, I make tests by POST and PUT, but nothing works modifying the product.

    Thread Starter Carlos Longarela

    (@carloslongarela)

    Hi @sc0ttkclark any idea about the problem with the update? all working fine in new product creation with API REST, but not working in a product modification with API REST.

    Best regards, Carlos Longarela.

    Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.