Shopify app extension part not showing on test store

173 views Asked by At

I am trying to create an app in shopify, which will call my API to fetch shipping rates based on product and location, and on checkout my multiple rates will be shown and user will chose one option and make an order.

I used this documentation: https://shopify.dev/docs/apps/getting-started/create

and followed step by step guide,

while creating app it asked me to add extension which I added and I choose "Fulfillment constraints - Function" extension as it seemed related to what I was developing.

Till here all went fine, after running app locally it installed on my store by URL authentication.

it is showing default pages as well on store admin

But when I go to checkout I can not see my custom shipping method below is the code which I added in my "App Folder/extensions/Extension Name/src/run.js"

// @ts-check

/**
 * @typedef {import("../generated/api").RunInput} RunInput
 * @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
 */

/**
 * @type {FunctionRunResult}
 */
const NO_CHANGES = {
  operations: [],
};

/**
 * @param {RunInput} input
 * @returns {FunctionRunResult}
 */
export function run(input) {
  const configuration = JSON.parse(
    input?.fulfillmentConstraintRule?.metafield?.value ?? "{}"
  );
  console.log('Configuration:', configuration);

  // Custom shipping method logic
  const customShippingMethod = {
    name: 'Custom Shipping', // Name of the shipping method
    price: 5.99, // Price for the shipping method
    minOrderValue: 25.0, // Minimum order value for this method
  };

  if (input.order?.subtotal >= customShippingMethod.minOrderValue) {
    return {
      operations: [
        {
          action: 'ship',
          fulfillments: [
            {
              fulfillmentMethod: {
                id: 'custom_shipping',
                name: customShippingMethod.name,
              },
            },
          ],
        },
      ],
    };
  }

  return NO_CHANGES;
};

can anyone help me what wrong I am doing here? I am new to shopify apps, if someone can provide some directions to search that would be great help.

Regards, Kamran

I am trying to search a sample app which can have similar feature or at least basic framework which I can use. But could find something maybe because its lastest CLI?

0

There are 0 answers