fix(invoice): drop fulfillmentOrders query (scope-denied), keep shippingLine pickup heuristic

Querying Order.fulfillmentOrders.deliveryMethod requires the
read_merchant_managed_fulfillment_orders scope (not read_orders, despite
what shopify.dev claims) and was failing with 'Access denied for
fulfillmentOrders field' against real stores.

Adding that scope would force every install to re-grant permissions, so
instead we rely on shippingLine alone:

- Shopify Local Pickup app: shippingLine.code = 'Pickup' (caught by the
  regex) and shippingLine.title is the chosen location name itself   (e.g. 'Lager Graz') \u2014 perfect as pickupLocationName.
- Custom-rate pickup ('Abholung im Lager'): regex matches title/code,
  title is used as the location hint.

Removes RawDeliveryMethod, the deliveryMethods field on RawOrderForInvoice,
and the fulfillmentOrders edges from RawAdminResponse.
This commit is contained in:
Gerhard Scheikl
2026-05-15 15:04:16 +02:00
parent d742e75419
commit f16ef4e103
5 changed files with 209 additions and 78 deletions
+17 -16
View File
@@ -487,11 +487,18 @@ function mapTracking(order: RawOrderForInvoice): TrackingInfo[] {
}
/**
* Detects whether the order is a "local pickup" order. Primary signal is
* Shopify's `DeliveryMethodType` on the fulfillment order (`PICK_UP`),
* which is what the Shopify Local Pickup app sets. Falls back to a string
* heuristic on `shippingLine.source/code/title` for merchants who model
* pickup as a custom shipping rate named "Abholung"/"Pickup".
* Detects whether the order is a "local pickup" order. Pickup is detected
* heuristically from `shippingLine.{source,code,title,carrierIdentifier}`:
*
* - The Shopify Local Pickup app sets `shippingLine.code = "Pickup"` and
* uses the chosen pickup-location name as the shipping-line title — so
* the title doubles as the location name.
* - Merchants who model pickup as a custom shipping rate typically include
* "Abholung"/"Pickup" in the title or code.
*
* (We deliberately do NOT query `Order.fulfillmentOrders.deliveryMethod`
* here: that field requires the `read_merchant_managed_fulfillment_orders`
* scope, which would force every install to re-grant permissions.)
*
* Returns the pickup descriptor (with location name when known) or `null`
* when the order is a normal shipping order. Callers should not render the
@@ -500,23 +507,17 @@ function mapTracking(order: RawOrderForInvoice): TrackingInfo[] {
function detectPickup(
order: RawOrderForInvoice,
): { locationName: string | null } | null {
// Primary: DeliveryMethodType from fulfillment orders.
for (const dm of order.deliveryMethods ?? []) {
if (dm.methodType === "PICK_UP") {
return { locationName: dm.locationName };
}
}
// Fallback: legacy string heuristic on shippingLine.
const sl = order.shippingLine;
if (!sl) return null;
const haystack = [sl.source, sl.code, sl.title, sl.carrierIdentifier]
.filter(Boolean)
.join(" ")
.toLowerCase();
if (/pick[\s-]?up|abholung|abhol\b/.test(haystack)) {
return { locationName: sl.title?.trim() || null };
}
return null;
if (!/pick[\s-]?up|abholung|abhol\b/.test(haystack)) return null;
// For Shopify Local Pickup, `title` is the location name itself
// (e.g. "Lager Graz"). For custom-rate pickup ("Abholung im Lager"),
// it's a generic description — still better than nothing as a hint.
return { locationName: sl.title?.trim() || null };
}
/**