Generate pickup points
Customers can choose to have their order sent to a pickup point instead of to their address.
In this guide, you'll learn how to generate custom pickup point options using Shopify Functions. You'll create a starter function with some logic to support pickup points for a specific location. You'll also learn how to retrieve the pickup point that the customer selected, using the GraphQL Admin API.
What you'll learn
Anchor link to section titled "What you'll learn"In this tutorial, you’ll learn how to do the following tasks:
- Generate starter code for Shopify Functions
- Use GraphQL to define the input of your function
- Test the delivery option generator and review function logs
- Retrieve the selected pickup point for an order, using the GraphQL Admin API
- Deploy your function to the Shopify platform.
Requirements
Anchor link to section titled "Requirements"- You've created a Partner account.
- You've created a development store.
You've created an app that uses Shopify CLI 3.49.5 or higher. If you previously installed Shopify CLI, then make sure that you're using the latest version.
You've installed Node.js 16 or higher.
You've installed your app on the development store.
Rust-specific requirements
Anchor link to section titled "Rust-specific requirements"The following requirements are specific to Rust-based development with Shopify Functions.
You've installed Rust.
On Windows, Rust requires the Microsoft C++ Build Tools. Make sure to select the Desktop development with C++ workload when installing the tools.
You've installed cargo-wasi:
Step 1: Create the pickup point delivery option generator function
Anchor link to section titled "Step 1: Create the pickup point delivery option generator function"Use Shopify CLI to generate a pickup point delivery option generator starter function. Shopify CLI generates the function, specifies the function's inputs using an input query, and implements the function logic. Learn more about the function that's generated.
Navigate to your app directory:
Create a new pickup point delivery option generator extension with the following command:
Choose the language to use. For this tutorial, you should select either Rust or JavaScript.
For handling large data payloads, consider using Rust, as it may help avoid exceeding Shopify's instruction limit, potentially preventing an InstructionCountLimitExceededError.
Navigate to
extensions/pickup-points-generator
:
Step 2: Preview the function on a development store
Anchor link to section titled "Step 2: Preview the function on a development store"To test your function, you need to make it available to your development store.
If you're developing a function in a language other than JavaScript or TypeScript, ensure you have configured
build.watch
in your function extension configuration.Navigate back to your app root:
Use the Shopify CLI
dev
command to start app preview:You can keep the preview running as you work on your function. When you make changes to a watched file, Shopify CLI rebuilds your function and updates the function extension's drafts, so you can immediately test your changes.
Follow the CLI prompts to preview your app, and install it on your development store.
Step 3: Set up shipping to pickup points
Anchor link to section titled "Step 3: Set up shipping to pickup points"For pickup points to be available at checkout, your store needs to have at least one location with pickup points enabled.
- In the Shopify admin, go to Settings > Shipping and delivery.
- Under Shipping to pickup points, select a location.
- Enable the option to ship to pickup points from the location.
- Click Edit rate.
- Under Apply rate to pickup points provided by, select your extension.
- Click Done.
- Click Save.
Step 4: Test the pickup point delivery option generator
Anchor link to section titled "Step 4: Test the pickup point delivery option generator"You can test your pickup point delivery option generator to ensure that it's working as expected.
In your development store, add a product to your cart and proceed to checkout.
The product must be available from the configured location.
In checkout, select Ship to pickup point.
Type an address in Canada, and click Search. If you're in Canada, then you can use your location.
To view available pickup points, select either Map or List.
Select a location.
Click Continue to payment.
The Payment page displays the address that you selected.
Step 5 (Optional): Debug the function
Anchor link to section titled "Step 5 (Optional): Debug the function"To debug your function, or view its output, you can review its logs.
- Log in to your Partner Dashboard.
- Navigate to Apps and select your app.
- Click Extensions > pickup-points-generator.
- Click on any function run to view its input, output, and any logs written to
STDERR
.
Step 6: Retrieve the pickup point from an order
Anchor link to section titled "Step 6: Retrieve the pickup point from an order"You can retrieve a pickup point from an order with the GraphQL Admin API.
To query the pickup point, you need to request access to protected customer data in the Partner Dashboard. Your app also needs to meet specific requirements to ensure customer privacy and security.
Set access scopes
Anchor link to section titled "Set access scopes"Add the read_orders
and read_merchant_managed_fulfillment_orders
access scopes to your app.
Stop your app if it's running.
In
shopify.app.toml
, updatescopes
to include the required access scopes. The following is an example:Deploy your changes with the following command:
When prompted, release the new version.
Restart your server for the changes to take effect:
Retrieve the pickup point
Anchor link to section titled "Retrieve the pickup point"Request the pickup point from the GraphQL Admin API's DeliveryMethod
object. You'll request data from the deliveryOptionGeneratorPickupPoint
field.
Complete the order that you started.
In Shopify CLI, where your server is running, press
g
to open GraphiQL in your browser.In GraphiQL, run the following query, with the ID of the order that you created.
This example returns the IDs of the pickup point and the function that generated the pickup point option.
Step 7 (Optional): Edit the selected pickup point
Anchor link to section titled "Step 7 (Optional): Edit the selected pickup point"You can edit the selected pickup point option, either on the order or on the fulfillment page for a pickup order that's completed using pickup points functions.
In the Shopify admin, go to Orders page.
Next to Pickup point address, click the pencil icon.
In the modal that displays, edit the pickup point address.
After you've edited the address, click Search.
Installed pickup points functions will run and a list of pickup points will be returned.
Select a new pickup point delivery option.
Click Done.
To edit the selected pickup point option on the fulfillment page, fulfill the order and repeat the steps above.
- Review the UX guidelines for pickup points, to seamlessly integrate your app into the checkout experience.
- Learn more about how Shopify Functions work and the benefits of using Shopify Functions.
- Learn how to use variables in your input query.
- Review the developer tools and resources to build for pickup points, including the Pickup Point Delivery Option Generator API reference.