From 79906bab12052db3cf532f54e37902199ff0cfe2 Mon Sep 17 00:00:00 2001 From: Adnan Saadeddine Date: Tue, 12 Nov 2024 14:46:59 +0200 Subject: [PATCH] TQLG-244: fix issue with payment method (#87) * TQLG-244: fix issue with payment method * TQLG-244: fix issue with payment method --- components/Account/Order/AccountOrderItem.vue | 3 +- composables/useOrderDetails.ts | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 composables/useOrderDetails.ts diff --git a/components/Account/Order/AccountOrderItem.vue b/components/Account/Order/AccountOrderItem.vue index e973e1a..0ad9c92 100644 --- a/components/Account/Order/AccountOrderItem.vue +++ b/components/Account/Order/AccountOrderItem.vue @@ -5,12 +5,11 @@ const props = defineProps<{ orderId: string; }>(); -const { order, loadOrderDetails, shippingMethod, paymentMethod, status, shippingAddress, billingAddress } = +const { order, loadOrderDetails, shippingMethod, paymentMethod, paymentState, status, shippingAddress, billingAddress } = useOrderDetails(props.orderId, { stateMachineState: {}, }); -const { state: paymentState } = useOrderPayment(order); const shippingStatus = computed(() => { const stateName = order.value?.deliveries?.[0]?.stateMachineState?.translated?.name; diff --git a/composables/useOrderDetails.ts b/composables/useOrderDetails.ts new file mode 100644 index 0000000..b4b0386 --- /dev/null +++ b/composables/useOrderDetails.ts @@ -0,0 +1,32 @@ +import { useOrderDetails as useBaseOrderDetails } from '@shopware-pwa/composables-next'; +import type { UseOrderDetailsReturn } from '@shopware-pwa/composables-next'; +import type { Schemas } from '@shopware/api-client/api-types'; +import type { ComputedRef } from 'vue'; + +export type UseCustomOrderDetailsReturn = UseOrderDetailsReturn & { + paymentState: ComputedRef; +} + +export function useOrderDetails( + orderId: string, + associations?: Schemas["Criteria"]["associations"], +): UseCustomOrderDetailsReturn { + const baseUserDetails = useBaseOrderDetails(orderId, associations); + const paymentMethod = computed(() => { + const transactions = baseUserDetails.order.value?.transactions; + + return transactions?.[transactions.length - 1]?.paymentMethod; + }); + + const paymentState = computed(() => { + const transactions = baseUserDetails.order.value?.transactions; + + return transactions?.[transactions.length - 1]?.stateMachineState; + }); + + return { + ...baseUserDetails, + paymentMethod, + paymentState, + }; +} \ No newline at end of file