shipping support
This commit is contained in:
parent
6cf92c1db7
commit
0059f03e87
4 changed files with 14 additions and 3 deletions
|
|
@ -497,6 +497,7 @@ module.exports = (pool, query, authMiddleware) => {
|
||||||
|
|
||||||
// If no address provided, return only flat rate shipping
|
// If no address provided, return only flat rate shipping
|
||||||
if (!shippingAddress) {
|
if (!shippingAddress) {
|
||||||
|
console.log("No Address provide flat rate");
|
||||||
const rates = await shippingService.getFlatRateShipping(subtotal);
|
const rates = await shippingService.getFlatRateShipping(subtotal);
|
||||||
|
|
||||||
return res.json({
|
return res.json({
|
||||||
|
|
@ -509,6 +510,7 @@ module.exports = (pool, query, authMiddleware) => {
|
||||||
const parsedAddress = typeof shippingAddress === 'string'
|
const parsedAddress = typeof shippingAddress === 'string'
|
||||||
? shippingService.parseAddressString(shippingAddress)
|
? shippingService.parseAddressString(shippingAddress)
|
||||||
: shippingAddress;
|
: shippingAddress;
|
||||||
|
console.log("parsedAddress provided ", parsedAddress);
|
||||||
|
|
||||||
const rates = await shippingService.getShippingRates(
|
const rates = await shippingService.getShippingRates(
|
||||||
null, // Use default from config
|
null, // Use default from config
|
||||||
|
|
@ -518,6 +520,7 @@ module.exports = (pool, query, authMiddleware) => {
|
||||||
order_total: subtotal
|
order_total: subtotal
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
console.log("rates provided ", JSON.stringify(rates, null ,4));
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
|
|
|
||||||
|
|
@ -241,7 +241,7 @@ module.exports = (pool, query, authMiddleware) => {
|
||||||
try {
|
try {
|
||||||
// Get all settings from database
|
// Get all settings from database
|
||||||
const allSettings = await SystemSettings.getAllSettings(pool, query);
|
const allSettings = await SystemSettings.getAllSettings(pool, query);
|
||||||
|
config.updateFromDatabase(allSettings)
|
||||||
// Build environment variables string
|
// Build environment variables string
|
||||||
let envContent = '';
|
let envContent = '';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ const shippingService = {
|
||||||
async getShippingRates(addressFrom, addressTo, parcelDetails) {
|
async getShippingRates(addressFrom, addressTo, parcelDetails) {
|
||||||
// If EasyPost is not enabled, return flat rate shipping
|
// If EasyPost is not enabled, return flat rate shipping
|
||||||
if (!config.shipping.easypostEnabled || !config.shipping.easypostApiKey) {
|
if (!config.shipping.easypostEnabled || !config.shipping.easypostApiKey) {
|
||||||
|
console.log("EASY POST NOT CONFIGURED ", !config.shipping.easypostEnabled, !config.shipping.easypostApiKey)
|
||||||
return this.getFlatRateShipping(parcelDetails.order_total);
|
return this.getFlatRateShipping(parcelDetails.order_total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,7 +26,13 @@ const shippingService = {
|
||||||
|
|
||||||
// Format parcel for EasyPost
|
// Format parcel for EasyPost
|
||||||
const parcel = this.formatParcel(parcelDetails);
|
const parcel = this.formatParcel(parcelDetails);
|
||||||
|
console.log("EasyPost shipment request", JSON.stringify({
|
||||||
|
shipment: {
|
||||||
|
from_address: fromAddress,
|
||||||
|
to_address: toAddress,
|
||||||
|
parcel: parcel
|
||||||
|
}
|
||||||
|
}, null , 4))
|
||||||
// Create shipment via EasyPost API
|
// Create shipment via EasyPost API
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
'https://api.easypost.com/v2/shipments',
|
'https://api.easypost.com/v2/shipments',
|
||||||
|
|
@ -46,6 +53,7 @@ const shippingService = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
// console.log("EasyPost shipment response", response)
|
||||||
|
|
||||||
// Process and filter rates
|
// Process and filter rates
|
||||||
return this.processShippingRates(response.data.rates, parcelDetails.order_total);
|
return this.processShippingRates(response.data.rates, parcelDetails.order_total);
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ const CheckoutPage = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Call API to get shipping rates
|
// Call API to get shipping rates
|
||||||
const response = await apiClient.post('/api/cart/shipping-rates', {
|
const response = await apiClient.post('/cart/shipping-rates', {
|
||||||
userId: user,
|
userId: user,
|
||||||
shippingAddress
|
shippingAddress
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue