0
votes

I was experimenting on Shopify since I started learning Shopify recently. I' a MEAN stack developer. One thinking came to my mind that how do we update the shipping charges dynamically?

Here is my plan,

There will be a Google Maps and the usine will pick the location. I've added few fields to the cart.liquid by reffering to THIS page. I've created a small Embedded App to initiate the maps. The app uses NodeJS, Koa, NextJS, and React and I'm planning to create an Endpoint with Koa where I can calculate the shipping charges based on the Geometric distance from User location to Store location.

The calculation will be something like below.

let latA = /* Store Lat */
let lngA = /* Store Lng */

let latB = /* User Lat */
let lngB = /* User Lng */

/* I'll caculate the distance using Google maps API. Lets say, distance is 10KM */

let shippingCharge = 10 * 50;

I can get this value and set it as Cart Attribute. But I want to collect the amount from the user, so, Is there any way to send this to checkout page as shipping charge?

I can't use Shopify shipping methods since my shipping charge will be created dynamically.

1
Is your store Plus? If you have a Plus store you can write custom Shopify Scripts via their app and modify the shipping price from there (this is available only for plus stores and you use Ruby to write them). If you are not a plus member then... you don't have a lot of options except using an external checkout process via an App or custom coding something.drip
I'm not a Plus user. Is there any reference to create custom checkout? I just want same checkout with this feature in it.rakcode
I haven't dip my toes there so I can't provide a lot of guidance on the matter. But if you need to create a custom checkout flow it may be a huge undertaking, since I don't think that you can rely on the checkout api for this (except the order creation) you may need to handle the payment processing yourself and the shipping, but once again I haven't had the pleasure of coding a custom checkout flow for shopify as of this moment so I'm not a valid source.drip

1 Answers

2
votes

Any store can add the Custom Carrier Services to it. You get an endpoint in your own custom App to return shipping costs to customers in checkout. The payload of data from Shopify to work with includes the origin, destination and some details on the items being shipped. It lacks real depth of course, but if you are clever, you can leverage product properties to customize a bit.

So you get to figure out how much to charge between A and B, for the items.