Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
feat: guest order with steps (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
patzick authored Apr 14, 2020
1 parent 5e2172b commit 1c77b1f
Show file tree
Hide file tree
Showing 37 changed files with 1,591 additions and 1,369 deletions.
2 changes: 2 additions & 0 deletions api/composables.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export interface UseCheckout {
guestOrderParams: Ref<Readonly<Partial<GuestOrderParams | null>>>;
// (undocumented)
isGuestOrder: Readonly<Ref<boolean>>;
// (undocumented)
updateGuestOrderParams: (params: Partial<GuestOrderParams>) => void;
}

// @alpha (undocumented)
Expand Down
19 changes: 3 additions & 16 deletions packages/composables/__tests__/useCheckout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,10 @@ describe("Composables - useCheckout", () => {
});

describe("guestOrderParams", () => {
afterEach(() => {
// return to default state
const { guestOrderParams } = useCheckout();
guestOrderParams.value = {};
});
it("should return an empty object when prams are not set", () => {
const { guestOrderParams } = useCheckout();
expect(guestOrderParams.value).toEqual({});
});
it("should return guest order params if are set", () => {
const { guestOrderParams } = useCheckout();
expect(guestOrderParams.value).toEqual({});
guestOrderParams.value = {
firstName: "John",
};
expect(guestOrderParams.value).toEqual({ firstName: "John" });
});
});
});

Expand Down Expand Up @@ -270,10 +257,10 @@ describe("Composables - useCheckout", () => {
mockedApiClient.createGuestOrder.mockResolvedValueOnce({
id: "newOrderId",
} as any);
const { createOrder, guestOrderParams } = useCheckout();
guestOrderParams.value = {
const { createOrder, updateGuestOrderParams } = useCheckout();
updateGuestOrderParams({
firstName: "John",
};
});
await createOrder();
expect(mockedApiClient.createGuestOrder).toHaveBeenCalledWith({
firstName: "John",
Expand Down
13 changes: 8 additions & 5 deletions packages/composables/src/logic/useCheckout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vue from "vue";
import { Ref, computed } from "@vue/composition-api";
import { Ref, computed, reactive } from "@vue/composition-api";
import { useUser, useCart } from "@shopware-pwa/composables";
import { ShippingMethod } from "@shopware-pwa/commons/interfaces/models/checkout/shipping/ShippingMethod";
import { PaymentMethod } from "@shopware-pwa/commons/interfaces/models/checkout/payment/PaymentMethod";
Expand All @@ -25,6 +25,7 @@ export interface UseCheckout {
forceReload: boolean;
}) => Promise<Readonly<Ref<readonly PaymentMethod[]>>>;
createOrder: () => Promise<Order>;
updateGuestOrderParams: (params: Partial<GuestOrderParams>) => void;
}

const orderData: {
Expand All @@ -49,6 +50,7 @@ export const useCheckout = (): UseCheckout => {
const paymentMethods: Readonly<Ref<readonly PaymentMethod[]>> = computed(
() => orderData.paymentMethods
);
const localOrderData = reactive(orderData);

const getShippingMethods = async (
{ forceReload } = { forceReload: false }
Expand Down Expand Up @@ -89,16 +91,17 @@ export const useCheckout = (): UseCheckout => {
};
const isGuestOrder = computed(() => !isLoggedIn.value);

const guestOrderParams = computed({
get: () => orderData.guestOrderParams,
set: (val) => (orderData.guestOrderParams = val),
});
const guestOrderParams = computed(() => localOrderData.guestOrderParams);
const updateGuestOrderParams = (params: Partial<GuestOrderParams>): void => {
orderData.guestOrderParams = { ...orderData.guestOrderParams, ...params };
};

return {
isGuestOrder,
getPaymentMethods,
getShippingMethods,
createOrder,
guestOrderParams,
updateGuestOrderParams,
};
};
197 changes: 0 additions & 197 deletions packages/default-theme/components/checkout/ReviewOrder.vue

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1c77b1f

Please sign in to comment.