All things Shopify and commerce
im struggling with development shopify app, so basically i try to learn how to create shipping app and then i've make the shipping rates by code and it works but the problem is my shipping rates by code is not showing as a shipping method on the checkout page any idea guys? here's the code
async function createCarrierService(session) {
const host = process.env.HOST || 'localhost'; // Pastikan `HOST` terdefinisi, jika tidak, gunakan fallback
const callbackUrl = `https://${host}/carrier/shipping_rate`;
const carrierServiceData = {
carrier_service: {
name: "Vins Shipping",
callback_url: callbackUrl,
service_discovery: true,
},
};
try {
const response = await axios.post(
`https://${session.shop}/admin/api/2024-07/carrier_services.json`,
carrierServiceData,
{
headers: {
'X-Shopify-Access-Token': session.accessToken,
'Content-Type': 'application/json',
},
}
);
console.log('Carrier service created:', response.data);
return response.data;
} catch (error) {
console.error('Error creating carrier service:', error.response ? error.response.data : error.message);
throw error; // Re-throw the error so it can be handled by the caller
}
}
app.post("/carrier/shipping_rate", express.json(), async (req, res) => {
console.log("Received shipping rate request:", req.body);
// Mengambil informasi tujuan pengiriman
const { destination } = req.body;
// Logika penetapan rate pengiriman berdasarkan negara tujuan
let rate = 0; // Default ke pengiriman gratis
if (destination.country === "ID") {
rate = 10000; // Rp 10.000 untuk pengiriman domestik (Indonesia)
} else {
rate = 50000; // Rp 50.000 untuk pengiriman internasional
}
const response = {
rates: [
{
service_name: "Vins Standard Shipping",
service_code: "VINS_STANDARD",
total_price: rate.toString(),
description: "5-7 business days",
currency: "IDR",
},
{
service_name: "Vins Express Shipping",
service_code: "VINS_EXPRESS",
total_price: rate.toString(), // Gunakan rate yang sama, tapi bisa disesuaikan jika ada perbedaan
description: "2-3 business days",
currency: "IDR",
}
]
};
console.log("Sending response:", response);
res.json(response);
});
The year-end shopping spree is around the corner! Is your online store ready for the ...
By JasonH Nov 10, 2024We recently spoke with Zopi developers @Zopi about how dropshipping businesses can enha...
By JasonH Oct 23, 2024A big shout out to all of the merchants who participated in our AMA with 2H Media: Holi...
By Jacqui Oct 21, 2024