feat(core-flows): calculate SO price on cart ops (#10563)
**What** - calculate the shipping option price when creating a shipping method - calculate the shipping option price when refreshing cart - add testing for calculated SO flow - fix validation on calculated SO creation - add manual fulfillment provider for testing - add `from_location` to calculation context --- RESOLVES CMRC-778 RESOLVES CMRC-602 RESOLVES SUP-136
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { ModuleProvider, Modules } from "@medusajs/framework/utils"
|
||||
import { ManualFulfillmentService } from "./services/manual-fulfillment"
|
||||
|
||||
const services = [ManualFulfillmentService]
|
||||
|
||||
export default ModuleProvider(Modules.FULFILLMENT, {
|
||||
services,
|
||||
})
|
||||
@@ -0,0 +1,54 @@
|
||||
import { AbstractFulfillmentProviderService } from "@medusajs/framework/utils"
|
||||
|
||||
export class ManualFulfillmentService extends AbstractFulfillmentProviderService {
|
||||
static identifier = "manual-calculated"
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
async getFulfillmentOptions() {
|
||||
return [
|
||||
{
|
||||
id: "manual-fulfillment-calculated",
|
||||
},
|
||||
{
|
||||
id: "manual-fulfillment-return-calculated",
|
||||
is_return: true,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
async validateFulfillmentData(optionData, data, context) {
|
||||
return data
|
||||
}
|
||||
|
||||
async calculatePrice(optionData, data, context) {
|
||||
return {
|
||||
calculated_amount:
|
||||
context.items.reduce((acc, i) => acc + i.quantity, 0) * 1.5, // mock caluclation as 1.5 per item
|
||||
is_calculated_price_tax_inclusive: false,
|
||||
}
|
||||
}
|
||||
|
||||
async canCalculate() {
|
||||
return true
|
||||
}
|
||||
|
||||
async validateOption(data) {
|
||||
return true
|
||||
}
|
||||
|
||||
async createFulfillment() {
|
||||
// No data is being sent anywhere
|
||||
return {}
|
||||
}
|
||||
|
||||
async cancelFulfillment() {
|
||||
return {}
|
||||
}
|
||||
|
||||
async createReturnFulfillment() {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user