Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating multiple metafields with different key showing Error

I want to Create multiple Meta fields with different key but it displaying me following error:

'metafield' => 'expected Array to be a Hash',

This is my code:

    $prodcut_variant = array(

    'metafield'=>array(
       array('namespace'=>'orbital_response',
             'key'=>'Os Purchases',
             'value'=>'0',
             'value_type'=>integer,),
       array('namespace'=>'orbital_response',
             'key'=>'Stock Status',
             'value'=>'C',
             'value_type'=>integer,)

));

$request_update = $shopify('POST /admin/products/{#ID}/metafields.json',array(),$prodcut_variant);
like image 213
Tarun modi Avatar asked May 03 '17 08:05

Tarun modi


People also ask

How do I add Metafields to a product on Shopify?

From your Shopify admin, go to Settings > Metafields. Select the part of your store that you want to add a metafield to. For example, Products. Click Add definition.

What is namespace in Metafields?

Together, the namespace and key create a unique identifier for your metafield. They're separated by a . , and can only contain letters, numbers, underscores ( _ ), and hyphens ( - ). You can use a namespace to group similar metafields together, but each namespace and key combination must be unique.

What is Metafield?

Metafields enable you to customize the functionality and appearance of your Shopify store by letting you save specialized information that isn't usually captured in the Shopify admin. You can use Metafields for internal tracking, or to display specialized information on your online store in a variety of ways.


1 Answers

If you are adding metafields with a new record you can pass an array of metafields. Otherwise you have to create them one at a time at the url '/admin/variant/#id/metafields.json

Your value 'C' is not an integer. I suspect the quoted '0' won't go through either. It is likely these that are throwing the first error. Do you mean 0 or 0xC?

like image 96
bknights Avatar answered Oct 04 '22 12:10

bknights