Accessing cart attributes from Pickup Point Delivery option generator function

Accessing cart attributes from Pickup Point Delivery option generator function

martin-lacko
Shopify Partner
2 0 3

Hello,

I generated new pickup point delivery generator function using typescript. The graphql schema suggest the cart attributes and other cart properties should be accessible in both run.graphql and fetch.graphql and therefore the data should be available at both of these stages. I've created proof of concept that sets the attribute at the checkout and updated following graphql for fetch and run functions.

 

Fetch:

 

query FetchInput {
  deliveryAddress {
    countryCode
    longitude
    latitude
  }
  cart {
    attribute(key: "expressDelivery") {
      key
      value
    }
    cost {
      totalAmount {
        amount
        currencyCode
      }
    }
    lines {
      quantity
      id
      cost {
        totalAmount {
          amount
          currencyCode
        }
      }
    }
  }
}

 

 

Run:

 

query RunInput {
  fetchResult {
    status
    body
  }
  cart {
    attribute(key: "expressDelivery") {
      key
      value
    }
    cost {
      totalAmount {
        amount
        currencyCode
      }
    }
    lines {
      quantity
      id
      cost {
        totalAmount {
          amount
          currencyCode
        }
      }
    }
  }
}

 


 The addition of cost and lines is there just to see if the issue is attribute specific or I am not getting any data at all about the cart.

After running this I am getting this logged in in the extension logs in the partners dashboard
Run input:

 

{
  "fetchResult": {
    "status": 200,
    "body": "// response of the fetch call"
  },
  "cart": {
    "attribute": null,
    "cost": {
      "totalAmount": {
        "amount": "0.0",
        "currencyCode": "CAD"
      }
    },
    "lines": []
  }
}

 

 Fetch input:

 

{
  "deliveryAddress": {
    "countryCode": "GB",
    "longitude": -1.1516966,
    "latitude": 53.9685834
  },
  "cart": {
    "attribute": null,
    "cost": {
      "totalAmount": {
        "amount": "0.0",
        "currencyCode": "CAD"
      }
    },
    "lines": []
  }
}

 


So my question is, is the pickup point generation function not supposed to be providing access to cart attributes and other cart properties (and therefore the graphql schema is broken as it suggest these properties should be accessible)? Or am I doing something wrong on my side? Maybe I need to add some access scope to be able to see cart data etc?

The goal of this feature is to be able to add specific pickup points only when an attribute is present in the cart.

Thank you!

Replies 6 (6)

algarcia
Shopify Partner
3 0 2

Hi Martin-Lacko,

I have the same issue, I need to show pickup points based on the products added to the cart,

have you find any solution to get the cart info on the Pickup Point Delivery option generator function?

I tried to import another query file and load the result on run.js but the result always is undefined?


@typedef
{import("../generated/api").GetCart} GetCart

query GetCart {
  cart {
    lines {
    quantity
      cost {
        totalAmount {
          amount
          currencyCode
        }
      }
      merchandise {
        ... on ProductVariant {
          product {
            id
          }
        }
      }
    }
    buyerIdentity {
      email
    }
  }
}

Thank you


 

martin-lacko
Shopify Partner
2 0 3

Unfortunately no luck. We ended up going different route which would not apply to your case. We were not trying to filter out pickup points but adjust the cost of pickup point delivery based on some cart attributes. We ended up going with additional product that can be toggled while on the checkout page instead of cart attribute. It's a shame because I do believe this approach should work, or at least I have not found anything in shopify documentation or elsewhere which would suggest this approach is not meant to function. Especially since we are getting a response, not an error. Just the response is completely undefined.

algarcia
Shopify Partner
3 0 2

Thank you Martin for the info, I hope that somebody of the shopify staff, maybe @Blair, can explain us how to acces to the cart info from a pickup point generator function of if it isn't possible.

VGM137
Shopify Partner
5 0 0

I'm also having the same issue, I already tried this:

query FetchInput {
  deliveryAddress{
    countryCode
    city
    provinceCode
    latitude
    longitude
  }
  cart{
    deliveryGroups{
      id
      cartLines{
        merchandise{
          ... on ProductVariant{
            sku
            weight
          }
        }
        quantity
      }
    }
    deliverableLines{
      merchandise{
        ... on ProductVariant{
          sku
          weight
        }
      }
      quantity
    }
    lines{
      merchandise{
        ... on ProductVariant{
          sku
          weight
        }
      }
      quantity
      attribute{
        key
      }
    }
  }
}

 but none of the arrays comes with the products in the cart.

 

these are the scopes I'm using: scopes = "read_checkouts,read_merchant_managed_fulfillment_orders,read_orders,read_products"

Maybe it´s a bug, hopefully they fix it soon.

EugeneDymo
Shopify Partner
1 0 1

Faced the same issue and it's a blocker for my application. Tried with the simplest FetchInput examples - only empty fields were returned from the Shopify side.

I would love to hear from the Shopify team or anyone who managed to overcome the problem or find an alternative way of receiving the cart's items on the "run" stage.

SkylarRohter
Shopify Partner
5 0 0

I have a similar issue and I'm unsure if it's caused by FetchInput.

I am trying to return errors to block checkout using network access, however my FetchInput is always null. I have configured my permissions to allow network-access.

 

Run Input:

query RunInput {
  fetchResult {
    status
    body
  }
}
run.ts
export function run(input: RunInput) {
  const fetchResult = input.fetchResult;

  if(!fetchResult){
    console.log("No fetchResult");
    return { errors: [] };
  }
  if(fetchResult.status !== 200){
    throw new Error("Server reponse unprocessable (status) ")
  }
  if(!fetchResult.body){
    throw new Error("Server response unprocessable (body)")
  }

  const data = JSON.parse(fetchResult.body);

  const errors = data.errors.map(error => ({
    localizedMessage: error.localized_message,
    target: error.target
  }))
  return { errors }
};
 
Shopify partner dashboard
SkylarRohter_0-1721668752082.png

 

 

This is currently blocking the development of my app, so I'm very curious if a solution has been found.