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

Commit

Permalink
feat(client): checkout service (#1452)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkucmus authored May 4, 2021
1 parent e4d14a5 commit 02a901a
Show file tree
Hide file tree
Showing 22 changed files with 45 additions and 583 deletions.
17 changes: 5 additions & 12 deletions api/composables.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { CustomerUpdatePasswordParam } from '@shopware-pwa/shopware-6-client';
import { CustomerUpdateProfileParam } from '@shopware-pwa/shopware-6-client';
import { EntityError } from '@shopware-pwa/commons/interfaces/models/common/EntityError';
import { EqualsFilter } from '@shopware-pwa/commons/interfaces/search/SearchFilter';
import { GuestOrderParams } from '@shopware-pwa/commons/interfaces/request/GuestOrderParams';
import { Includes } from '@shopware-pwa/commons/interfaces/search/SearchCriteria';
import { IUseListing as IUseListing_2 } from '@shopware-pwa/composables';
import { LineItem } from '@shopware-pwa/commons/interfaces/models/checkout/cart/line-item/LineItem';
Expand All @@ -42,8 +41,7 @@ import { RangeFilter } from '@shopware-pwa/commons/interfaces/search/SearchFilte
import { Ref } from '@vue/composition-api';
import { Salutation } from '@shopware-pwa/commons/interfaces/models/system/salutation/Salutation';
import { SessionContext } from '@shopware-pwa/commons/interfaces/response/SessionContext';
import { ShippingAddress } from '@shopware-pwa/commons/interfaces/request/GuestOrderParams';
import { ShippingAddress as ShippingAddress_2 } from '@shopware-pwa/commons/interfaces/models/checkout/customer/ShippingAddress';
import { ShippingAddress } from '@shopware-pwa/commons/interfaces/models/checkout/customer/ShippingAddress';
import { ShippingMethod } from '@shopware-pwa/commons/interfaces/models/checkout/shipping/ShippingMethod';
import { ShopwareApiInstance } from '@shopware-pwa/shopware-6-client';
import { ShopwareSearchParams } from '@shopware-pwa/commons/interfaces/search/SearchCriteria';
Expand Down Expand Up @@ -128,10 +126,10 @@ export interface CreateCheckoutStep {
}

// @alpha (undocumented)
export function createCheckoutStep({ stepNumber, stepFields, stepDataUpdated, }: {
export function createCheckoutStep({ stepNumber, stepFields, }: {
stepNumber: number;
stepFields: CheckoutStepFields;
stepDataUpdated: (updatedData: CheckoutStepFields, guestOrderParams: Ref<Readonly<Partial<GuestOrderParams>>>) => Partial<GuestOrderParams>;
stepDataUpdated: (updatedData: CheckoutStepFields) => Partial<any>;
}): (rootContext: ApplicationVueContext) => CreateCheckoutStep;

// @beta
Expand Down Expand Up @@ -268,9 +266,6 @@ export interface IUseCheckout {
forceReload: boolean;
}) => Promise<Readonly<Ref<readonly ShippingMethod[]>>>;
// (undocumented)
guestOrderParams: Ref<Readonly<Partial<GuestOrderParams>>>;
isGuestOrder: Readonly<Ref<boolean>>;
// (undocumented)
onOrderPlace: (fn: (params: {
order: Order;
}) => void) => void;
Expand All @@ -280,8 +275,6 @@ export interface IUseCheckout {
shippingAddress: Readonly<Ref<ShippingAddress | undefined>>;
// (undocumented)
shippingMethods: Readonly<Ref<readonly ShippingMethod[]>>;
// (undocumented)
updateGuestOrderParams: (params: Partial<GuestOrderParams>) => void;
}

// @beta
Expand Down Expand Up @@ -395,7 +388,7 @@ export interface IUseSessionContext {
// (undocumented)
activeBillingAddress: Readonly<Ref<BillingAddress | null>>;
// (undocumented)
activeShippingAddress: Readonly<Ref<ShippingAddress_2 | null>>;
activeShippingAddress: Readonly<Ref<ShippingAddress | null>>;
// (undocumented)
currency: Readonly<Ref<Currency | null>>;
// (undocumented)
Expand All @@ -419,7 +412,7 @@ export interface IUseSessionContext {
// (undocumented)
setActiveBillingAddress: (address: Partial<BillingAddress>) => Promise<void>;
// (undocumented)
setActiveShippingAddress: (address: Partial<ShippingAddress_2>) => Promise<void>;
setActiveShippingAddress: (address: Partial<ShippingAddress>) => Promise<void>;
// (undocumented)
setCurrency: (currency: Partial<Currency>) => Promise<void>;
// (undocumented)
Expand Down
10 changes: 0 additions & 10 deletions api/shopware-6-client.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { Customer } from '@shopware-pwa/commons/interfaces/models/checkout/custo
import { CustomerAddress } from '@shopware-pwa/commons/interfaces/models/checkout/customer/CustomerAddress';
import { CustomerRegistrationParams } from '@shopware-pwa/commons/interfaces/request/CustomerRegistrationParams';
import { EntityResult } from '@shopware-pwa/commons/interfaces/response/EntityResult';
import { GuestOrderParams } from '@shopware-pwa/commons/interfaces/request/GuestOrderParams';
import { Language } from '@shopware-pwa/commons/interfaces/models/framework/language/Language';
import { Order } from '@shopware-pwa/commons/interfaces/models/checkout/order/Order';
import { PageResolverProductResult } from '@shopware-pwa/commons/interfaces/models/content/cms/CmsPage';
Expand Down Expand Up @@ -91,9 +90,6 @@ export interface ContactFormData {
// @beta
export function createCustomerAddress(params: Partial<CustomerAddress>, contextInstance?: ShopwareApiInstance): Promise<string>;

// @beta
export function createGuestOrder(params: GuestOrderParams, contextInstance?: ShopwareApiInstance): Promise<Order>;

// @beta (undocumented)
export function createInstance(initialConfig?: ClientSettings): ShopwareApiInstance;

Expand Down Expand Up @@ -198,12 +194,6 @@ export const getCheckoutCartEndpoint: () => string;
// @beta (undocumented)
export const getCheckoutCartLineItemEndpoint: () => string;

// @beta (undocumented)
export const getCheckoutGuestOrderDetailsEndpoint: (orderId: string) => string;

// @beta (undocumented)
export const getCheckoutGuestOrderEndpoint: () => string;

// @beta (undocumented)
export const getCheckoutOrderEndpoint: () => string;

Expand Down
15 changes: 13 additions & 2 deletions docs/landing/operations/migrations/0.8.x_to_0.9.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Just add `<script lang="ts">` in your components to start using it there. All yo

### [@shopware-pwa/shopware-6-client](../../resources/api/shopware-6-client)
1. **_SearchResult_** interface has been replaced with **_EntityResult<ENTITY, ENTITY_TYPE>_** interface as a response in listed methods:

- `createGuestOrder`
- `getAvailableCountries`
- `getAvailableCurrencies`
- `getAvailableLanguages`
Expand All @@ -40,7 +40,18 @@ Just add `<script lang="ts">` in your components to start using it there. All yo

2. Removed methods (not supported in v6.4.x):
- `addCartItemQuantity`
- `createGuestOrder`
- `getCheckoutGuestOrderDetailsEndpoint`
- `getCheckoutGuestOrderEndpoint`
- `getContextCountryItemEndpoint`
- `getContextPaymentMethodDetailsEndpoint`
- `getContextSalutationItemEndpoint`
- `getContextShippingMethodDetailsEndpoint`
- `getContextShippingMethodDetailsEndpoint`
- `getOrderPaymentUrl`


### [@shopware-pwa/composables](../../resources/api/composables)
1. Changed behavior
- Guest customer's data is not kept in shared state within **`createCheckoutStep`** anymore.
2. Removed (not supported in v6.4.x):
- `createGuestOrder`, `isGuestOrder`, `updateGuestOrderParams` from **`useCheckout`**.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions docs/landing/resources/api/composables.iusecheckout.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ export interface IUseCheckout
| [createOrder](./composables.iusecheckout.createorder.md) | () =&gt; Promise&lt;Order&gt; | <b><i>(BETA)</i></b> |
| [getPaymentMethods](./composables.iusecheckout.getpaymentmethods.md) | (options?: { forceReload: boolean; }) =&gt; Promise&lt;Readonly&lt;Ref&lt;readonly PaymentMethod\[\]&gt;&gt;&gt; | <b><i>(BETA)</i></b> |
| [getShippingMethods](./composables.iusecheckout.getshippingmethods.md) | (options?: { forceReload: boolean; }) =&gt; Promise&lt;Readonly&lt;Ref&lt;readonly ShippingMethod\[\]&gt;&gt;&gt; | <b><i>(BETA)</i></b> |
| [guestOrderParams](./composables.iusecheckout.guestorderparams.md) | Ref&lt;Readonly&lt;Partial&lt;GuestOrderParams&gt;&gt;&gt; | <b><i>(BETA)</i></b> |
| [isGuestOrder](./composables.iusecheckout.isguestorder.md) | Readonly&lt;Ref&lt;boolean&gt;&gt; | <b><i>(BETA)</i></b> Flag isGuestOrder is true when user is not logged in |
| [onOrderPlace](./composables.iusecheckout.onorderplace.md) | (fn: (params: { order: Order; }) =&gt; void) =&gt; void | <b><i>(BETA)</i></b> |
| [paymentMethods](./composables.iusecheckout.paymentmethods.md) | Readonly&lt;Ref&lt;readonly PaymentMethod\[\]&gt;&gt; | <b><i>(BETA)</i></b> |
| [shippingAddress](./composables.iusecheckout.shippingaddress.md) | Readonly&lt;Ref&lt;ShippingAddress \| undefined&gt;&gt; | <b><i>(BETA)</i></b> |
| [shippingMethods](./composables.iusecheckout.shippingmethods.md) | Readonly&lt;Ref&lt;readonly ShippingMethod\[\]&gt;&gt; | <b><i>(BETA)</i></b> |
| [updateGuestOrderParams](./composables.iusecheckout.updateguestorderparams.md) | (params: Partial&lt;GuestOrderParams&gt;) =&gt; void | <b><i>(BETA)</i></b> |

This file was deleted.

28 changes: 0 additions & 28 deletions docs/landing/resources/api/shopware-6-client.createguestorder.md

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions docs/landing/resources/api/shopware-6-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
| [changeCartItemQuantity(itemId, newQuantity, contextInstance)](./shopware-6-client.changecartitemquantity.md) | <b><i>(BETA)</i></b> Changes the current quantity in specific cart line item to given quantity.<!-- -->Example: If current quantity is 3 and you pass 2 as quantity parameter, you will get a new cart's state with quantity 2. |
| [clearCart(contextInstance)](./shopware-6-client.clearcart.md) | <b><i>(BETA)</i></b> When no sw-context-token given then this method return an empty cart with the new sw-context-token.<!-- -->When sw-context-token given then this method simply returns the current state of the cart.<!-- -->As the purpose of this method is not clear we recommend to use <code>getCart</code> method because its behaviour seems to be the same. |
| [createCustomerAddress(params, contextInstance)](./shopware-6-client.createcustomeraddress.md) | <b><i>(BETA)</i></b> Create an address and respond the new address's id |
| [createGuestOrder(params, contextInstance)](./shopware-6-client.createguestorder.md) | <b><i>(BETA)</i></b> Creates an order for not logged in users Should be used when the user is logged out, but has items in the cart |
| [createInstance(initialConfig)](./shopware-6-client.createinstance.md) | <b><i>(BETA)</i></b> |
| [createOrder(contextInstance)](./shopware-6-client.createorder.md) | <b><i>(BETA)</i></b> Creates an order for logged in users |
| [deleteCustomerAddress(addressId, contextInstance)](./shopware-6-client.deletecustomeraddress.md) | <b><i>(BETA)</i></b> Delete's the customer's address by id |
Expand Down Expand Up @@ -96,8 +95,6 @@
| [getCategoryProductsListing](./shopware-6-client.getcategoryproductslisting.md) | <b><i>(BETA)</i></b> Get default amount of products and listing configuration for given category |
| [getCheckoutCartEndpoint](./shopware-6-client.getcheckoutcartendpoint.md) | <b><i>(BETA)</i></b> |
| [getCheckoutCartLineItemEndpoint](./shopware-6-client.getcheckoutcartlineitemendpoint.md) | <b><i>(BETA)</i></b> |
| [getCheckoutGuestOrderDetailsEndpoint](./shopware-6-client.getcheckoutguestorderdetailsendpoint.md) | <b><i>(BETA)</i></b> |
| [getCheckoutGuestOrderEndpoint](./shopware-6-client.getcheckoutguestorderendpoint.md) | <b><i>(BETA)</i></b> |
| [getCheckoutOrderEndpoint](./shopware-6-client.getcheckoutorderendpoint.md) | <b><i>(BETA)</i></b> |
| [getCheckoutOrderPayEndpoint](./shopware-6-client.getcheckoutorderpayendpoint.md) | <b><i>(BETA)</i></b> |
| [getCheckoutPromotionCodeEndpoint](./shopware-6-client.getcheckoutpromotioncodeendpoint.md) | <b><i>(BETA)</i></b> |
Expand Down
18 changes: 0 additions & 18 deletions packages/commons/interfaces/request/GuestOrderParams.ts

This file was deleted.

44 changes: 1 addition & 43 deletions packages/composables/__tests__/createCheckoutStep.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vue from "vue";
import VueCompositionApi, { computed, ref } from "@vue/composition-api";
import VueCompositionApi, { ref } from "@vue/composition-api";
Vue.use(VueCompositionApi);

import { VuelidateValidation } from "@shopware-pwa/composables";
Expand Down Expand Up @@ -65,32 +65,6 @@ describe("Composables - createCheckoutStep", () => {
expect(initialData.someField).toEqual("qwe");
});

it("should call stepDataUpdated on field update", async () => {
const initialData = {
someField: "qwe eee",
};
const guestOrderParamsValue = computed(() => ({}));
const stepDataUpdatedMock = jest.fn();
const stepComposable = createCheckoutStep({
stepNumber: 2,
stepFields: initialData,
stepDataUpdated: stepDataUpdatedMock,
});
const { someField } = stepComposable(rootContextMock);
someField.value = "qwerty";

await Vue.nextTick();

expect(stepDataUpdatedMock).toHaveBeenCalledWith(
{
isValid: false,
someField: "qwerty",
},
guestOrderParamsValue
);
expect(stepDataUpdatedMock).toHaveBeenCalledTimes(2);
});

it("should override field existing value with cached from cookie", async () => {
const initialData = {
someField: "qwe",
Expand All @@ -99,7 +73,6 @@ describe("Composables - createCheckoutStep", () => {
someField: "eeeh",
isValid: true,
});
const guestOrderParamsValue = computed(() => ({}));
const stepDataUpdatedMock = jest.fn();
const stepComposable = createCheckoutStep({
stepNumber: 2,
Expand All @@ -110,21 +83,6 @@ describe("Composables - createCheckoutStep", () => {
someField.value = "qwerty";
await Vue.nextTick();
expect(getCookie).toHaveBeenCalledWith("sw-checkout-2");
expect(stepDataUpdatedMock).toHaveBeenCalledWith(
{
isValid: false,
someField: "qwerty",
},
guestOrderParamsValue
);
expect(stepDataUpdatedMock).toHaveBeenCalledWith(
{
isValid: true,
someField: "eeeh",
},
guestOrderParamsValue
);
expect(stepDataUpdatedMock).toHaveBeenCalledTimes(2);
expect(someField.value).toEqual("eeeh");
});

Expand Down
Loading

0 comments on commit 02a901a

Please sign in to comment.