feat(core-flows, dashboard, medusa, types): optional shipping profile (#11434)

* feat: create product flow changes

* feat: allow unsetting SP on product update

* feat: update prepare line item helper

* test: add testcase

* wip: fix tests

* fix: update module tests

* fix: cart module test
This commit is contained in:
Frane Polić
2025-02-17 19:08:59 +01:00
committed by GitHub
parent 3b7856e8f5
commit ee848bf0f4
19 changed files with 191 additions and 112 deletions

View File

@@ -1123,6 +1123,102 @@ medusaIntegrationTestRunner({
)
})
it("should successfully complete cart without shipping for digital products", async () => {
/**
* Product has a shipping profile so cart item should not require shipping
*/
const product = (
await api.post(
`/admin/products`,
{
title: "Product without inventory management",
description: "test",
options: [
{
title: "Size",
values: ["S", "M", "L", "XL"],
},
],
variants: [
{
title: "S / Black",
sku: "special-shirt",
options: {
Size: "S",
},
manage_inventory: false,
prices: [
{
amount: 1500,
currency_code: "usd",
},
],
},
],
},
adminHeaders
)
).data.product
let cart = (
await api.post(
`/store/carts`,
{
currency_code: "usd",
sales_channel_id: salesChannel.id,
region_id: region.id,
shipping_address: shippingAddressData,
},
storeHeadersWithCustomer
)
).data.cart
cart = (
await api.post(
`/store/carts/${cart.id}/line-items`,
{
variant_id: product.variants[0].id,
quantity: 1,
},
storeHeaders
)
).data.cart
const paymentCollection = (
await api.post(
`/store/payment-collections`,
{ cart_id: cart.id },
storeHeaders
)
).data.payment_collection
await api.post(
`/store/payment-collections/${paymentCollection.id}/payment-sessions`,
{ provider_id: "pp_system_default" },
storeHeaders
)
expect(cart.items[0].requires_shipping).toEqual(false)
const response = await api.post(
`/store/carts/${cart.id}/complete`,
{},
storeHeaders
)
expect(response.status).toEqual(200)
expect(response.data.order).toEqual(
expect.objectContaining({
shipping_methods: [],
items: expect.arrayContaining([
expect.objectContaining({
requires_shipping: false,
}),
]),
})
)
})
describe("with sale price lists", () => {
let priceList

View File

@@ -114,7 +114,7 @@ export async function createOrderSeeder({
"/admin/products",
{
title: `Test fixture ${shippingProfile.id}`,
shipping_profile_id: shippingProfile.id,
shipping_profile_id: withoutShipping ? undefined : shippingProfile.id,
options: [
{ title: "size", values: ["large", "small"] },
{ title: "color", values: ["green"] },

View File

@@ -668,7 +668,6 @@ medusaIntegrationTestRunner({
"/admin/products",
{
title: `Test fixture 2`,
shipping_profile_id: shippingProfile.id,
options: [
{ title: "size", values: ["large", "small"] },
{ title: "color", values: ["green"] },

View File

@@ -990,7 +990,7 @@ medusaIntegrationTestRunner({
is_tax_inclusive: true,
is_custom_price: false,
quantity: 1,
requires_shipping: true,
requires_shipping: false, // product doesn't have a shipping profile nor inventory items that require shipping
subtitle: "Test product",
title: "Test variant",
unit_price: 3000,
@@ -1006,7 +1006,7 @@ medusaIntegrationTestRunner({
metadata: {
foo: "bar",
},
requires_shipping: true,
requires_shipping: true, // overriden when adding to cart
subtitle: "Test subtitle",
thumbnail: "some-url",
title: "Test item",
@@ -1040,7 +1040,7 @@ medusaIntegrationTestRunner({
is_tax_inclusive: false,
is_custom_price: false,
quantity: 1,
requires_shipping: true,
requires_shipping: false,
subtitle: "Test product",
title: "Test variant",
unit_price: 2000,

View File

@@ -1218,7 +1218,6 @@ medusaIntegrationTestRunner({
"/admin/products",
{
title: "Test fixture",
shipping_profile_id: shippingProfile.id,
options: [
{ title: "size", values: ["large", "small"] },
{ title: "color", values: ["green"] },