Skip to content

Commit

Permalink
Merge branch 'develop' into feat/cart-module-data-models
Browse files Browse the repository at this point in the history
  • Loading branch information
olivermrbl committed Jan 4, 2024
2 parents b658e46 + 7f62ab1 commit ee02ba2
Show file tree
Hide file tree
Showing 103 changed files with 2,983 additions and 515 deletions.
6 changes: 6 additions & 0 deletions .changeset/breezy-horses-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/types": patch
"@medusajs/utils": patch
---

feat(types,utils): added promotion create with rules
8 changes: 8 additions & 0 deletions .changeset/fuzzy-ears-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@medusajs/pricing": patch
"@medusajs/types": patch
"@medusajs/utils": patch
---

feat(pricing, types): add soft deletion for money-amounts
feat(utils): cascade soft delete across 1:1 relationships
2 changes: 1 addition & 1 deletion .changeset/hot-dingos-pay.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
"@medusajs/medusa-react": patch
"medusa-react": patch
"@medusajs/types": patch
"@medusajs/modules-sdk": patch
---
Expand Down
9 changes: 9 additions & 0 deletions .changeset/perfect-pugs-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"medusa-test-utils": patch
"@medusajs/link-modules": patch
"@medusajs/pricing": patch
"@medusajs/product": patch
"@medusajs/utils": patch
---

fix(medusa-test-utils, utils, link-modules, pricing, product): upgrade mikro-orm version
5 changes: 5 additions & 0 deletions .changeset/rude-boats-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): Update cart sales channel should not remove all line items
6 changes: 6 additions & 0 deletions .changeset/smart-zoos-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/medusa": patch
"medusa-payment-stripe": patch
---

fix(medusa, medusa-payment-stripe): fix stripe error handling
8 changes: 8 additions & 0 deletions .changeset/swift-carpets-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@medusajs/link-modules": patch
"@medusajs/core-flows": patch
"@medusajs/medusa": patch
"@medusajs/utils": patch
---

feat: sales channel <> order link
1 change: 1 addition & 0 deletions .github/workflows/test-cli-with-database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
uses: ./.github/actions/setup-server
with:
cache-extension: "cli-test"
node-version: "16.14"

- name: Install Medusa cli
run: npm i -g @medusajs/medusa-cli
Expand Down
52 changes: 48 additions & 4 deletions integration-tests/api/__tests__/store/cart/ff-sales-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ describe("[MEDUSA_FF_SALES_CHANNELS] /store/carts", () => {

describe("POST /store/carts/:id", () => {
let product
let product2
let product3

const salesChannelId = "sales-channel"
const defaultSalesChannelId = "default-sales-channel"

beforeEach(async () => {
await simpleRegionFactory(dbConnection, {
Expand All @@ -55,20 +60,24 @@ describe("[MEDUSA_FF_SALES_CHANNELS] /store/carts", () => {
product = await simpleProductFactory(dbConnection, {
sales_channels: [
{
id: "sales-channel",
id: salesChannelId,
name: "Sales channel",
description: "Sales channel",
is_disabled: false,
},
{
id: "default-sales-channel",
id: defaultSalesChannelId,
name: "Main sales channel",
description: "Main sales channel",
is_default: true,
is_disabled: false,
},
],
})

product2 = await simpleProductFactory(dbConnection)

product3 = await simpleProductFactory(dbConnection)
})

afterEach(async () => {
Expand All @@ -91,7 +100,7 @@ describe("[MEDUSA_FF_SALES_CHANNELS] /store/carts", () => {
quantity: 1,
},
],
sales_channel_id: "sales-channel",
sales_channel_id: salesChannelId,
})

const cart = createCartRes.data.cart
Expand All @@ -110,7 +119,7 @@ describe("[MEDUSA_FF_SALES_CHANNELS] /store/carts", () => {
expect(createdOrder.status).toEqual(200)
expect(createdOrder.data.data).toEqual(
expect.objectContaining({
sales_channel_id: "sales-channel",
sales_channel_id: salesChannelId,
})
)
})
Expand Down Expand Up @@ -152,5 +161,40 @@ describe("[MEDUSA_FF_SALES_CHANNELS] /store/carts", () => {
})
)
})

it("should remove the line items that does not belong to the new sales channel", async () => {
const api = useApi()

let createCartRes = await api.post("/store/carts", {
region_id: "test-region",
items: [
{
variant_id: product.variants[0].id,
quantity: 1,
},
{
variant_id: product2.variants[0].id,
quantity: 1,
},
{
variant_id: product3.variants[0].id,
quantity: 1,
},
],
sales_channel_id: defaultSalesChannelId,
})

let items = createCartRes.data.cart.items
expect(items).toHaveLength(3)

const cartId = createCartRes.data.cart.id
createCartRes = await api.post(`/store/carts/${cartId}`, {
sales_channel_id: salesChannelId,
})

items = createCartRes.data.cart.items
expect(items).toHaveLength(1)
expect(items.map((i) => i.variant.id)).toEqual([product.variants[0].id])
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ Object {
],
"locale": null,
"order": Object {
"afterLoad": [Function],
"beforeInsert": [Function],
"beforeUpdate": [Function],
"billing_address_id": null,
"canceled_at": null,
"cart_id": null,
Expand Down Expand Up @@ -753,7 +755,9 @@ Object {

exports[`medusa-plugin-sendgrid order canceled data 1`] = `
Object {
"afterLoad": [Function],
"beforeInsert": [Function],
"beforeUpdate": [Function],
"billing_address": null,
"billing_address_id": null,
"canceled_at": Any<Date>,
Expand Down Expand Up @@ -982,7 +986,9 @@ Object {

exports[`medusa-plugin-sendgrid order placed data 1`] = `
Object {
"afterLoad": [Function],
"beforeInsert": [Function],
"beforeUpdate": [Function],
"billing_address": null,
"billing_address_id": null,
"canceled_at": null,
Expand Down Expand Up @@ -1236,7 +1242,9 @@ Object {
},
"locale": null,
"order": Object {
"afterLoad": [Function],
"beforeInsert": [Function],
"beforeUpdate": [Function],
"billing_address": null,
"billing_address_id": null,
"canceled_at": null,
Expand Down Expand Up @@ -1612,7 +1620,9 @@ Object {
],
"locale": null,
"order": Object {
"afterLoad": [Function],
"beforeInsert": [Function],
"beforeUpdate": [Function],
"billing_address_id": null,
"canceled_at": null,
"cart_id": null,
Expand Down Expand Up @@ -2078,7 +2088,9 @@ Object {
],
"locale": null,
"order": Object {
"afterLoad": [Function],
"beforeInsert": [Function],
"beforeUpdate": [Function],
"billing_address_id": null,
"canceled_at": null,
"cart_id": null,
Expand Down Expand Up @@ -2533,4 +2545,4 @@ Object {
"tracking_links": Array [],
"tracking_number": "",
}
`;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ const {
startBootstrapApp,
} = require("../../../environment-helpers/bootstrap-app")
const { initDb, useDb } = require("../../../environment-helpers/use-db")
const {
useApi,
useExpressServer,
} = require("../../../environment-helpers/use-api")
const { useApi } = require("../../../environment-helpers/use-api")

const adminSeeder = require("../../../helpers/admin-seeder")

Expand Down
8 changes: 4 additions & 4 deletions packages/authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
},
"devDependencies": {
"@mikro-orm/cli": "5.7.12",
"@mikro-orm/cli": "5.9.7",
"cross-env": "^5.2.1",
"jest": "^29.6.3",
"medusa-test-utils": "^1.1.40",
Expand All @@ -53,9 +53,9 @@
"@medusajs/modules-sdk": "^1.12.5",
"@medusajs/types": "^1.11.9",
"@medusajs/utils": "^1.11.2",
"@mikro-orm/core": "5.7.12",
"@mikro-orm/migrations": "5.7.12",
"@mikro-orm/postgresql": "5.7.12",
"@mikro-orm/core": "5.9.7",
"@mikro-orm/migrations": "5.9.7",
"@mikro-orm/postgresql": "5.9.7",
"awilix": "^8.0.0",
"dotenv": "^16.1.4",
"knex": "2.4.2"
Expand Down
8 changes: 4 additions & 4 deletions packages/cart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
},
"devDependencies": {
"@mikro-orm/cli": "5.7.12",
"@mikro-orm/cli": "5.9.7",
"cross-env": "^5.2.1",
"jest": "^29.6.3",
"medusa-test-utils": "^1.1.40",
Expand All @@ -53,9 +53,9 @@
"@medusajs/modules-sdk": "^1.12.5",
"@medusajs/types": "^1.11.9",
"@medusajs/utils": "^1.11.2",
"@mikro-orm/core": "5.7.12",
"@mikro-orm/migrations": "5.7.12",
"@mikro-orm/postgresql": "5.7.12",
"@mikro-orm/core": "5.9.7",
"@mikro-orm/migrations": "5.9.7",
"@mikro-orm/postgresql": "5.9.7",
"awilix": "^8.0.0",
"dotenv": "^16.1.4",
"knex": "2.4.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ export async function detachSalesChannelFromProducts({

if (featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)) {
const remoteLink = container.resolve("remoteLink")
const promises: Promise<unknown>[] = []

for (const [
salesChannelId,
productIds,
] of salesChannelIdProductIdsMap.entries()) {
productIds.forEach((id) =>
promises.push(
await promiseAll(
productIds.map((id) =>
remoteLink.dismiss({
[Modules.PRODUCT]: {
product_id: id,
Expand All @@ -57,8 +56,6 @@ export async function detachSalesChannelFromProducts({
)
)
}

return
} else {
await promiseAll(
Array.from(salesChannelIdProductIdsMap.entries()).map(
Expand Down
4 changes: 2 additions & 2 deletions packages/link-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"@medusajs/modules-sdk": "^1.12.5",
"@medusajs/types": "^1.11.9",
"@medusajs/utils": "^1.11.2",
"@mikro-orm/core": "5.7.12",
"@mikro-orm/postgresql": "5.7.12",
"@mikro-orm/core": "5.9.7",
"@mikro-orm/postgresql": "5.9.7",
"awilix": "^8.0.0"
}
}
1 change: 1 addition & 0 deletions packages/link-modules/src/definitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./product-variant-price-set"
export * from "./product-shipping-profile"
export * from "./product-sales-channel"
export * from "./cart-sales-channel"
export * from "./order-sales-channel"
66 changes: 66 additions & 0 deletions packages/link-modules/src/definitions/order-sales-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { ModuleJoinerConfig } from "@medusajs/types"

import { LINKS } from "../links"

export const OrderSalesChannel: ModuleJoinerConfig = {
serviceName: LINKS.OrderSalesChannel,
isLink: true,
databaseConfig: {
tableName: "order_sales_channel",
idPrefix: "ordersc",
},
alias: [
{
name: "order_sales_channel",
},
{
name: "order_sales_channels",
},
],
primaryKeys: ["id", "order_id", "sales_channel_id"],
relationships: [
{
serviceName: "orderService",
isInternalService: true,
primaryKey: "id",
foreignKey: "order_id",
alias: "order",
},
{
serviceName: "salesChannelService",
isInternalService: true,
primaryKey: "id",
foreignKey: "sales_channel_id",
alias: "sales_channel",
},
],
extends: [
{
serviceName: "orderService",
fieldAlias: {
sales_channel: "sales_channel_link.sales_channel",
},
relationship: {
serviceName: LINKS.OrderSalesChannel,
isInternalService: true,
primaryKey: "order_id",
foreignKey: "id",
alias: "sales_channel_link",
},
},
{
serviceName: "salesChannelService",
fieldAlias: {
orders: "order_link.order",
},
relationship: {
serviceName: LINKS.OrderSalesChannel,
isInternalService: true,
primaryKey: "sales_channel_id",
foreignKey: "id",
alias: "order_link",
isList: true,
},
},
],
}
Loading

0 comments on commit ee02ba2

Please sign in to comment.