Skip to content

Commit

Permalink
fix(composables): correct delivery address source (#1847)
Browse files Browse the repository at this point in the history
* fix(composables): correct delivery address source

* chore: test and lint
  • Loading branch information
mkucmus authored Mar 14, 2022
1 parent 1128c69 commit 280af6e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 21 deletions.
17 changes: 15 additions & 2 deletions packages/commons/interfaces/models/checkout/cart/Cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,28 @@ export interface CartErrors {
}

/**
* @beta
* @public
*/
export interface CartDelivery extends Delivery {
shippingCosts: {
unitPrice: number;
quantity: number;
listPrice: number | null;
apiAlias: string;
totalPrice: number;
};
}

/**
* @public
*/
export interface Cart {
name: string;
token: string;
price: CartPrice;
lineItems: LineItem[];
errors: CartErrors;
deliveries: Delivery[];
deliveries: CartDelivery[];
transactions: Transaction[];
modified: boolean;
customerComment: null | string;
Expand Down
36 changes: 27 additions & 9 deletions packages/commons/interfaces/models/checkout/delivery/Delivery.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
import { OrderDeliveryPosition } from "../order/OrderDeliveryPosition";
import { ShippingMethod } from "../shipping/ShippingMethod";
import { CalculatedPrice } from "../cart/price/CalculatedPrice";
import { ShippingLocation } from "./ShippingLocation";
import { DeliveryDate } from "./DeliveryDate";
import { StateMachineState } from "../../system/state-machine/StateMachineState";
import { ShippingAddress } from "@shopware-pwa/commons";

/**
* @public
*/
export interface Delivery {
apiAlias: string;
createdAt: string;
customFields: unknown | null;
extensions: unknown;
id: string;
orderId: string;
orderVersionId: string;
positions: unknown | null;
shippingCosts: {
unitPrice: number;
quantity: number;
listPrice: number | null;
apiAlias: string;
};
shippingDateEarliest: string;
shippingDateLatest: string;
shippingMethod: ShippingMethod;
shippingMethodId: string;
shippingOrderAddress: ShippingAddress;
shippingOrderAddressId: string;
shippingOrderAddressVersionId: string;
stateId: string;
stateMachineState: StateMachineState;
positions: OrderDeliveryPosition[];
location: ShippingLocation;
deliveryDate: DeliveryDate;
shippingMethod: ShippingMethod;
shippingCosts: CalculatedPrice;
trackingCodes: unknown[];
translated: unknown[];
updatedAt: string | null;
versionId: string;
_uniqueIdentifier: string;
}
1 change: 0 additions & 1 deletion packages/commons/interfaces/models/checkout/order/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ interface Price {
interface ShippingCost {
unitPrice: number;
quantity: number;
totalPrice: number;
calculatedTaxes: CalculatedTax[];
taxRules: TaxRule[];
referencePrice: number | null;
Expand Down
10 changes: 3 additions & 7 deletions packages/composables/__tests__/useOrderDetails.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ describe("Composables - useOrderDetails", () => {
],
deliveries: [
{
location: {
address: {
id: "delivery-address-id",
},
shippingOrderAddress: {
id: "delivery-address-id"
},
shippingMethod: {
name: "Express",
Expand All @@ -117,9 +115,7 @@ describe("Composables - useOrderDetails", () => {
id: "shipping-address-id",
},
],
shippingCosts: {
totalPrice: 10.0,
},
shippingTotal: 10.0,
price: {
positionPrice: 90.0,
totalPrice: 100.0,
Expand Down
4 changes: 2 additions & 2 deletions packages/composables/src/logic/useOrderDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ export function useOrderDetails(params: { order: Ref<Order> | Order }): {
)
);
const shippingAddress = computed(
() => _sharedOrder.value?.deliveries?.[0]?.location?.address
() => _sharedOrder.value?.deliveries?.[0]?.shippingOrderAddress
);

const shippingCosts = computed(
() => _sharedOrder.value?.shippingCosts?.totalPrice
() => _sharedOrder.value?.shippingTotal
);
const subtotal = computed(() => _sharedOrder.value?.price?.positionPrice);
const total = computed(() => _sharedOrder.value?.price?.totalPrice);
Expand Down

0 comments on commit 280af6e

Please sign in to comment.