-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(composables): useDefaultOrderAssociations for accessing associat…
…ions (#1194)
- Loading branch information
Showing
5 changed files
with
96 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@shopware-pwa/composables-next": minor | ||
--- | ||
|
||
New `useDefaultOrderAssociations` composable to be used or overriden separately in user project. This composable just returns default associations object. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/composables/src/useDefaultOrderAssociations.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { useSetup } from "./_test"; | ||
import { useDefaultOrderAssociations } from "./useDefaultOrderAssociations"; | ||
|
||
describe("useDefaultOrderAssociations", () => { | ||
it("returns default associations object", async () => { | ||
const { vm } = useSetup(() => useDefaultOrderAssociations()); | ||
|
||
expect(vm).toMatchInlineSnapshot(` | ||
{ | ||
"associations": { | ||
"addresses": {}, | ||
"deliveries": { | ||
"associations": { | ||
"shippingMethod": {}, | ||
"shippingOrderAddress": {}, | ||
"stateMachineState": {}, | ||
}, | ||
}, | ||
"lineItems": { | ||
"associations": { | ||
"cover": {}, | ||
"downloads": { | ||
"associations": { | ||
"media": {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"stateMachineState": {}, | ||
"transactions": { | ||
"associations": { | ||
"paymentMethod": {}, | ||
"stateMachineState": {}, | ||
}, | ||
}, | ||
}, | ||
"checkPromotion": true, | ||
} | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { Schemas } from "#shopware"; | ||
|
||
export type UseDefaultOrderAssociationsReturn = Schemas["Criteria"] & { | ||
checkPromotion?: boolean; | ||
}; | ||
|
||
/** | ||
* Returns default order associations. You can override this composable in your project. | ||
* @public | ||
*/ | ||
export function useDefaultOrderAssociations(): UseDefaultOrderAssociationsReturn { | ||
const orderAssociations: Schemas["Criteria"] & { checkPromotion?: boolean } = | ||
{ | ||
associations: { | ||
stateMachineState: {}, | ||
lineItems: { | ||
associations: { | ||
cover: {}, | ||
downloads: { | ||
associations: { | ||
media: {}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
addresses: {}, | ||
deliveries: { | ||
associations: { | ||
shippingMethod: {}, | ||
shippingOrderAddress: {}, | ||
stateMachineState: {}, | ||
}, | ||
}, | ||
transactions: { | ||
associations: { | ||
paymentMethod: {}, | ||
stateMachineState: {}, | ||
}, | ||
}, | ||
}, | ||
checkPromotion: true, | ||
}; | ||
|
||
return orderAssociations; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters