Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core-flows, types): calculated shipping in RMA flows #11533

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fc6c44b
wip: calculated SO pricing in RMA flows
fPolic Feb 15, 2025
a5426b4
fix: types
fPolic Feb 15, 2025
8be1431
chore: small refactor
fPolic Feb 16, 2025
c2efe76
feat: caluclated shipping in return flow
fPolic Feb 19, 2025
26333d1
Merge branch 'develop' into feat/calculated-so-rma
fPolic Feb 20, 2025
b23fc7e
fix: module integrations
fPolic Feb 20, 2025
9a4f53c
fix: array containing
fPolic Feb 20, 2025
546f601
feat: refresh shipping on update item quantity
fPolic Feb 20, 2025
93ed9b5
rm: log
fPolic Feb 21, 2025
76069c9
rm: log2
fPolic Feb 21, 2025
4f7f5e9
feat: update interface, remove flag
fPolic Feb 21, 2025
74c2800
fix: revert change on OE for now
fPolic Feb 21, 2025
3af01b7
Merge branch 'develop' into feat/calculated-so-rma
fPolic Feb 21, 2025
efd6f27
fix: import
fPolic Feb 21, 2025
d39e360
feat: refactor flwos, cleanup cacluation cotext data model, wip excha…
fPolic Feb 24, 2025
782cd2e
feat: refreshing inbound/outbound shipping on items change
fPolic Feb 24, 2025
728cd9a
feat: refresh exchange shipping on return item add, test
fPolic Feb 24, 2025
d0c06f7
feat: refresh shipping on exchange/return item remove
fPolic Feb 24, 2025
417d246
Merge branch 'develop' into feat/calculated-so-rma
fPolic Feb 25, 2025
1c8efe1
fix: check optional
fPolic Feb 25, 2025
2a447c0
feat: test recalculation on quantity update
fPolic Feb 25, 2025
65bf283
feat: calculated shipping on claims
fPolic Feb 25, 2025
399284c
Merge branch 'develop' into feat/calculated-so-rma
fPolic Feb 26, 2025
91b4db7
Merge branch 'develop' into feat/calculated-so-rma
fPolic Feb 26, 2025
a3b2a27
fix: comment
fPolic Feb 26, 2025
f56ff9d
Merge branch 'develop' into feat/calculated-so-rma
fPolic Feb 26, 2025
cf0415b
Merge branch 'develop' into feat/calculated-so-rma
fPolic Feb 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ medusaIntegrationTestRunner({
)

expect(response.status).toEqual(200)
expect(response.data.fulfillment_providers).toEqual([
{ id: "manual_test-provider", is_enabled: true },
])
expect(response.data.fulfillment_providers).toEqual(
expect.arrayContaining([
{ id: "manual_test-provider", is_enabled: true },
{
id: "manual-calculated_test-provider-calculated",
is_enabled: true,
},
])
)
})
})
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ import {
} from "@medusajs/utils"

const providerId = "manual_test-provider"
const providerIdCalculated = "manual-calculated_test-provider-calculated"

export async function prepareDataFixtures({ container }) {
const fulfillmentService = container.resolve(Modules.FULFILLMENT)
const salesChannelService = container.resolve(Modules.SALES_CHANNEL)
const stockLocationModule: IStockLocationService = container.resolve(
Modules.STOCK_LOCATION
)
const pricingModule = container.resolve(Modules.PRICING)
const productModule = container.resolve(Modules.PRODUCT)
const inventoryModule = container.resolve(Modules.INVENTORY)
const customerService = container.resolve(Modules.CUSTOMER)

const customer = await customerService.createCustomers({
email: "[email protected]",
})

const shippingProfile = await fulfillmentService.createShippingProfiles({
name: "test",
Expand Down Expand Up @@ -71,6 +79,18 @@ export async function prepareDataFixtures({ container }) {
},
})

const priceSets = await pricingModule.createPriceSets([
{
prices: [
{
amount: 10,
region_id: region.id,
currency_code: "usd",
},
],
},
])

const [product] = await productModule.createProducts([
{
title: "Test product",
Expand All @@ -91,7 +111,7 @@ export async function prepareDataFixtures({ container }) {
{
inventory_item_id: inventoryItem.id,
location_id: location.id,
stocked_quantity: 2,
stocked_quantity: 10,
reserved_quantity: 0,
},
])
Expand Down Expand Up @@ -123,6 +143,14 @@ export async function prepareDataFixtures({ container }) {
inventory_item_id: inventoryItem.id,
},
},
{
[Modules.PRODUCT]: {
variant_id: product.variants[0].id,
},
[Modules.PRICING]: {
price_set_id: priceSets[0].id,
},
},
])

await remoteLink.create([
Expand All @@ -131,7 +159,16 @@ export async function prepareDataFixtures({ container }) {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: "manual_test-provider",
fulfillment_provider_id: providerId,
},
},

{
[Modules.STOCK_LOCATION]: {
stock_location_id: location.id,
},
[Modules.FULFILLMENT]: {
fulfillment_provider_id: providerIdCalculated,
},
},
])
Expand Down Expand Up @@ -160,14 +197,29 @@ export async function prepareDataFixtures({ container }) {
],
}

const shippingOptionCalculatedData: FulfillmentWorkflow.CreateShippingOptionsWorkflowInput =
{
name: "Calculated shipping option",
service_zone_id: serviceZone.id,
shipping_profile_id: shippingProfile.id,
provider_id: providerIdCalculated,
price_type: "calculated",
type: {
label: "Test type",
description: "Test description",
code: "test-code",
},
rules: [],
}

const { result } = await createShippingOptionsWorkflow(container).run({
input: [shippingOptionData],
input: [shippingOptionData, shippingOptionCalculatedData],
})

const remoteQueryObject = remoteQueryObjectFromString({
entryPoint: "shipping_option",
variables: {
id: result[0].id,
id: result.map((r) => r.id),
},
fields: [
"id",
Expand All @@ -189,13 +241,17 @@ export async function prepareDataFixtures({ container }) {

const remoteQuery = container.resolve(ContainerRegistrationKeys.REMOTE_QUERY)

const [createdShippingOption] = await remoteQuery(remoteQueryObject)
const shippingOptions = await remoteQuery(remoteQueryObject)
return {
shippingOption: createdShippingOption,
shippingOption: shippingOptions.find((s) => s.price_type === "flat"),
shippingOptionCalculated: shippingOptions.find(
(s) => s.price_type === "calculated"
),
region,
salesChannel,
location,
product,
customer,
inventoryItem,
}
}
Expand All @@ -205,18 +261,31 @@ export async function createOrderFixture({
product,
location,
inventoryItem,
region,
salesChannel,
customer,
overrides,
}: {
container: any
product: any
location: any
inventoryItem: any
salesChannel?: any
customer?: any
region?: any
overrides?: { quantity?: number }
}) {
const orderService: IOrderModuleService = container.resolve(Modules.ORDER)

let order = await orderService.createOrders({
region_id: "test_region_id",
email: "[email protected]",
region_id: region?.id || "test_region_id",
email: customer?.email || "[email protected]",
items: [
{
title: "Custom Item 2",
variant_sku: product.variants[0].sku,
variant_title: product.variants[0].title,
quantity: 1,
quantity: overrides?.quantity ?? 1,
unit_price: 50,
adjustments: [
{
Expand All @@ -235,7 +304,7 @@ export async function createOrderFixture({
currency_code: "usd",
},
],
sales_channel_id: "test",
sales_channel_id: salesChannel?.id || "test",
shipping_address: {
first_name: "Test",
last_name: "Test",
Expand Down Expand Up @@ -277,7 +346,7 @@ export async function createOrderFixture({
},
],
currency_code: "usd",
customer_id: "joe",
customer_id: customer?.id || "joe",
})

const inventoryModule = container.resolve(Modules.INVENTORY)
Expand Down
Loading
Loading