WE have a custom ERP application, and basis some event in that we need to add or update the metafield associated to a specific product. We have tried three different code snippets, but the metafileds don’t seem to get added, nor are we getting any error. The code sample is below, and we are testing it by using fixed values .. which will then be replaced by variable values
Code 1
We have tried the foll three code snippets but unable to do so .. can someone guide us how to do this
metafield = Metafield({‘value_type’: ‘value’, ‘namespace’: ‘inventory’, ‘value’: 25, ‘key’: ‘warehouse’, ‘resource’: ‘products’, ‘resource_id’: 7519320604927})
print(“metafields value :”,metafield)
metafield.save()
Code 2
product1 = Product.find(7519320604927)
shopify_request =Metafield({
‘key’: ‘KEY’,
‘value’: ‘VALUE’,
‘value_type’: ‘string’,
‘namespace’: ‘NAMESPACE’,
})
product1.add_metafield(shopify_request)
product1.save()
Code 3
product = Product.find(632910392)
metafield = Metafield({‘value_type’: ‘integer’, ‘namespace’: ‘inventory’, ‘value’: 25, ‘key’: ‘warehouse’})
product.add_metafield(metafield)