@fabrix/spool-cart
Version:
Spool - eCommerce Spool for Fabrix
45 lines (44 loc) • 1.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("@fabrix/fabrix/dist/common");
class ShippingService extends common_1.FabrixService {
publish(type, event, options = {}) {
if (this.app.services.EventsService) {
options.include = options.include || [{
model: this.app.models.EventItem.instance,
as: 'objects'
}];
return this.app.services.EventsService.publish(type, event, options);
}
this.app.log.debug('spool-events is not installed, please install it to use publish');
return Promise.resolve();
}
calculate(obj, lineItems, shippingAddress, resolver, options) {
options = options || {};
let resObj;
return resolver.resolve(obj, { transaction: options.transaction || null })
.then(_obj => {
if (!_obj) {
throw new Error('Could not resolve for shipping');
}
resObj = _obj;
return this.app.services.ProxyCartService.resolveItemsFromTo(resObj, lineItems.filter(i => i.requires_shipping), shippingAddress);
})
.then(resolvedItemsFromTo => {
if (!resolvedItemsFromTo) {
return resObj;
}
return this.getShipping(resObj, lineItems, resolvedItemsFromTo, options);
})
.then(shippingResult => {
return shippingResult;
});
}
getShipping(obj, lineItems, resolvedItemsFromTo, options) {
options = options || {};
return Promise.resolve({
line_items: []
});
}
}
exports.ShippingService = ShippingService;