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);
});
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024