We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Adding multiple custom metafields to the Cart

Adding multiple custom metafields to the Cart

builtbyvern
Shopify Partner
7 0 4

I'm trying add a few metafields to the Cart in Hydrogen using the code below. When I view the cart and log out the contents, only dealer_id shows up in the metafields array. If I try to only show store_name and ignore setting dealer_id, I actually end up with no metafields in the Cart object. I can also confirm that store_name is not empty.

fetcher.submit(
{
[CartForm.INPUT_NAME]: JSON.stringify({
action: CartForm.ACTIONS.MetafieldsSet,
inputs: {
metafields: [
{
key: 'custom.dealer_id',
type: 'string',
value: store_vendor_id,
},
{
key: 'custom.store_name',
type: 'string',
value: store_name,
},

],
},
}),
},
{method: 'POST', action: '/cart'},
);
fragment CartApiQuery on Cart {
metafields(identifiers:
[
{namespace: "custom", key: "dealer_id"},
{namespace: "custom", key: "store_name"}
]) {
key
value
}
...

 

Replies 0 (0)