← back to Shopify Sample Shipping

diagnose-sample-profile.mjs

33 lines

import {query} from './query.mjs';
// Full read-only config of the retained empty sample profile to find the zero-rates cause.
const id='gid://shopify/DeliveryProfile/96764067891';
const q=`query($id:ID!){deliveryProfile(id:$id){name default coversAllItems
  profileLocationGroups{
    locationGroup{id locations(first:20){nodes{name}}}
    locationGroupZones(first:20){nodes{
      zone{name countries{code{countryCode restOfWorld} provinces{code}}}
      methodDefinitions(first:20){nodes{name active
        rateProvider{__typename ... on DeliveryRateDefinition{price{amount currencyCode}}}
        methodConditions{operator conditionCriteria{__typename ... on Weight{value unit} ... on MoneyV2{amount currencyCode}}}
      }}
    }}
  }}}`;
const d=await query(q,{id});
const p=d.deliveryProfile;
console.log('PROFILE:',p.name,'default=',p.default,'coversAllItems=',p.coversAllItems);
for(const g of p.profileLocationGroups){
  const locs=(g.locationGroup.locations.nodes||[]).map(x=>x.name);
  console.log(`\nlocationGroup locations=[${locs.join(', ')}]`);
  for(const z of g.locationGroupZones.nodes){
    const zn=z.zone; const c=zn.countries||[];
    const cc=c.map(x=>x.code?.restOfWorld?'RestOfWorld':x.code?.countryCode).join(',');
    const provCount=c.reduce((a,x)=>a+((x.provinces||[]).length),0);
    console.log(`  ZONE ${zn.name} countries=[${cc}] provinces=${provCount}`);
    for(const m of z.methodDefinitions.nodes){
      const rp=m.rateProvider; const price=rp&&rp.price?`${rp.price.amount} ${rp.price.currencyCode}`:rp?.__typename;
      const conds=(m.methodConditions||[]).map(mc=>{const cr=mc.conditionCriteria; const v=cr?.value!==undefined?`${cr.value}${cr.unit||''}`:(cr?.amount!==undefined?`${cr.amount}${cr.currencyCode||''}`:'?'); return `${mc.operator} ${v}`;}).join(' & ')||'(none)';
      console.log(`    method "${m.name}" active=${m.active} price=${price} conditions=${conds}`);
    }
  }
}