Creates ShippingProfileService & ShippingOptionService (#30)
Adds ShippingProfiles: With Shipping Profiles store operators can group products together and select which shipping options can fulfill the products. The shipping profiles are region agnostic, but for products to be shippable to a given region the shipping profile must have a shipping option associated that ships to this region. Adds Shipping Options: Shipping Options represents a way that the customer can have their order shipped. The shipping option has a fulfillment provider associated to determine who fulfills orders with the given shipping method. If a fulfillment provider has multiple ways that they can ship a shipping option for each of the fulfillment provider's shipping options can be created.
This commit is contained in:
1 parent
aff1ec3390
commit
ea4185eddd
72 files changed
+3658
-370
No files matched your search
@@ -204,7 +204,7 @@ export const carts = {
|
||||
_id: IdMap.getId("eur-8-us-10"),
|
||||
},
|
||||
product: {
|
||||
_id: IdMap.getId("product"),
|
||||
_id: IdMap.getId("product1"),
|
||||
},
|
||||
quantity: 1,
|
||||
},
|
||||
@@ -214,7 +214,7 @@ export const carts = {
|
||||
_id: IdMap.getId("eur-10-us-12"),
|
||||
},
|
||||
product: {
|
||||
_id: IdMap.getId("product"),
|
||||
_id: IdMap.getId("product1"),
|
||||
},
|
||||
quantity: 1,
|
||||
},
|
||||
@@ -232,7 +232,7 @@ export const carts = {
|
||||
_id: IdMap.getId("eur-10-us-12"),
|
||||
},
|
||||
product: {
|
||||
_id: IdMap.getId("product"),
|
||||
_id: IdMap.getId("product2"),
|
||||
},
|
||||
quantity: 1,
|
||||
},
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { IdMap } from "medusa-test-utils"
|
||||
|
||||
export const options = {
|
||||
validOption: {
|
||||
_id: IdMap.getId("validId"),
|
||||
name: "Default Option",
|
||||
region_id: IdMap.getId("fr-region"),
|
||||
provider_id: "default_provider",
|
||||
data: {
|
||||
id: "bonjour",
|
||||
},
|
||||
requirements: [
|
||||
{
|
||||
_id: "requirement_id",
|
||||
type: "min_subtotal",
|
||||
value: 100,
|
||||
},
|
||||
],
|
||||
price: {
|
||||
type: "flat_rate",
|
||||
amount: 10,
|
||||
},
|
||||
},
|
||||
noCalc: {
|
||||
_id: IdMap.getId("noCalc"),
|
||||
name: "No Calc",
|
||||
region_id: IdMap.getId("fr-region"),
|
||||
provider_id: "default_provider",
|
||||
data: {
|
||||
id: "bobo",
|
||||
},
|
||||
requirements: [
|
||||
{
|
||||
_id: "requirement_id",
|
||||
type: "min_subtotal",
|
||||
value: 100,
|
||||
},
|
||||
],
|
||||
price: {
|
||||
type: "flat_rate",
|
||||
amount: 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export const ShippingOptionModelMock = {
|
||||
create: jest.fn().mockReturnValue(Promise.resolve()),
|
||||
updateOne: jest.fn().mockImplementation((query, update) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
deleteOne: jest.fn().mockReturnValue(Promise.resolve()),
|
||||
findOne: jest.fn().mockImplementation(query => {
|
||||
if (query._id === IdMap.getId("noCalc")) {
|
||||
return Promise.resolve(options.noCalc)
|
||||
}
|
||||
if (query._id === IdMap.getId("validId")) {
|
||||
return Promise.resolve(options.validOption)
|
||||
}
|
||||
return Promise.resolve(undefined)
|
||||
}),
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { IdMap } from "medusa-test-utils"
|
||||
|
||||
export const profiles = {
|
||||
validProfile: {
|
||||
_id: IdMap.getId("validId"),
|
||||
name: "Default Profile",
|
||||
products: [IdMap.getId("validId")],
|
||||
shipping_options: [IdMap.getId("validId")],
|
||||
},
|
||||
profile1: {
|
||||
_id: IdMap.getId("profile1"),
|
||||
name: "Profile One",
|
||||
products: [IdMap.getId("product1")],
|
||||
shipping_options: [IdMap.getId("shipping1")],
|
||||
},
|
||||
}
|
||||
|
||||
export const ShippingProfileModelMock = {
|
||||
create: jest.fn().mockReturnValue(Promise.resolve()),
|
||||
updateOne: jest.fn().mockImplementation((query, update) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
find: jest.fn().mockImplementation(query => {
|
||||
return Promise.resolve([])
|
||||
}),
|
||||
deleteOne: jest.fn().mockReturnValue(Promise.resolve()),
|
||||
findOne: jest.fn().mockImplementation(query => {
|
||||
if (query.shipping_options === IdMap.getId("validId")) {
|
||||
return Promise.resolve(profiles.validProfile)
|
||||
}
|
||||
if (query.products === IdMap.getId("validId")) {
|
||||
return Promise.resolve(profiles.validProfile)
|
||||
}
|
||||
if (query._id === IdMap.getId("validId")) {
|
||||
return Promise.resolve(profiles.validProfile)
|
||||
}
|
||||
if (query._id === IdMap.getId("profile1")) {
|
||||
return Promise.resolve(profiles.profile1)
|
||||
}
|
||||
return Promise.resolve(undefined)
|
||||
}),
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
/*******************************************************************************
|
||||
*
|
||||
******************************************************************************/
|
||||
import mongoose from "mongoose"
|
||||
|
||||
export default new mongoose.Schema({
|
||||
provider_id: { type: String, required: true },
|
||||
data: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
items: { type: [mongoose.Schema.Types.Mixed], default: [] },
|
||||
})
|
||||
@@ -0,0 +1,6 @@
|
||||
import mongoose from "mongoose"
|
||||
|
||||
export default new mongoose.Schema({
|
||||
type: { type: String, required: true },
|
||||
amount: { type: Number },
|
||||
})
|
||||
@@ -0,0 +1,6 @@
|
||||
import mongoose from "mongoose"
|
||||
|
||||
export default new mongoose.Schema({
|
||||
type: { type: String, required: true },
|
||||
value: { type: Number, required: true },
|
||||
})
|
||||
@@ -0,0 +1,20 @@
|
||||
import mongoose from "mongoose"
|
||||
import { BaseModel } from "medusa-interfaces"
|
||||
|
||||
import ShippingOptionPrice from "./schemas/shipping-option-price"
|
||||
import ShippingOptionRequirement from "./schemas/shipping-option-requirement"
|
||||
|
||||
class ShippingOptionModel extends BaseModel {
|
||||
static modelName = "ShippingOption"
|
||||
static schema = {
|
||||
name: { type: String, required: true },
|
||||
region_id: { type: String, required: true },
|
||||
provider_id: { type: String, required: true },
|
||||
data: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
price: { type: ShippingOptionPrice, required: true },
|
||||
requirements: { type: [ShippingOptionRequirement], default: [] },
|
||||
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
}
|
||||
}
|
||||
|
||||
export default ShippingOptionModel
|
||||
@@ -0,0 +1,13 @@
|
||||
import mongoose from "mongoose"
|
||||
import { BaseModel } from "medusa-interfaces"
|
||||
|
||||
class ShippingProfileModel extends BaseModel {
|
||||
static modelName = "ShippingProfile"
|
||||
static schema = {
|
||||
name: { type: String, required: true },
|
||||
products: { type: [String], default: [] },
|
||||
shipping_options: { type: [String], default: [] },
|
||||
}
|
||||
}
|
||||
|
||||
export default ShippingProfileModel
|
||||
Reference in new issue
Block a user