Skip to content

Commit

Permalink
feat(composables): separate composable to manage cart item (#1834)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkucmus authored Mar 14, 2022
1 parent 4d977c7 commit 1128c69
Show file tree
Hide file tree
Showing 25 changed files with 854 additions and 27 deletions.
39 changes: 39 additions & 0 deletions api/composables.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ import { EffectScope } from 'vue-demi';
import { EntityError } from '@shopware-pwa/commons/interfaces';
import { Includes } from '@shopware-pwa/commons/interfaces';
import { LineItem } from '@shopware-pwa/commons/interfaces';
import { LineItemType } from '@shopware-pwa/commons/interfaces';
import { ListingFilter } from '@shopware-pwa/helpers';
import { ListingResult } from '@shopware-pwa/commons/interfaces';
import { Order } from '@shopware-pwa/commons/interfaces';
import { PaymentMethod } from '@shopware-pwa/commons/interfaces';
import { Product } from '@shopware-pwa/commons/interfaces';
import { PropertyGroup } from '@shopware-pwa/commons/interfaces';
import { PropertyGroupOption } from '@shopware-pwa/commons';
import { Ref } from 'vue-demi';
import { Salutation } from '@shopware-pwa/commons/interfaces';
import { SessionContext } from '@shopware-pwa/commons/interfaces';
Expand Down Expand Up @@ -198,6 +200,8 @@ export interface IUseCart {
// (undocumented)
appliedPromotionCodes: ComputedRef<LineItem[]>;
// (undocumented)
broadcastUpcomingErrors(cart: Cart): void;
// (undocumented)
cart: ComputedRef<Cart | null>;
// (undocumented)
cartErrors: ComputedRef<EntityError[]>;
Expand Down Expand Up @@ -228,6 +232,36 @@ export interface IUseCart {
totalPrice: ComputedRef<number>;
}

// @beta
export interface IUseCartItem {
// (undocumented)
changeItemQuantity: (quantity: number) => Promise<void>;
// (undocumented)
getProductItemSeoUrlData(): Promise<Partial<Product>>;
// (undocumented)
isProduct: ComputedRef<boolean>;
// (undocumented)
isPromotion: ComputedRef<boolean>;
// (undocumented)
itemImageThumbnailUrl: ComputedRef<string>;
// (undocumented)
itemOptions: ComputedRef<PropertyGroupOption[]>;
// (undocumented)
itemQuantity: ComputedRef<number | undefined>;
// (undocumented)
itemRegularPrice: ComputedRef<number | undefined>;
// (undocumented)
itemSpecialPrice: ComputedRef<number | undefined>;
// (undocumented)
itemStock: ComputedRef<number | undefined>;
// (undocumented)
itemType: ComputedRef<LineItemType | undefined>;
// (undocumented)
lineItem: ComputedRef<LineItem | undefined | null>;
// (undocumented)
removeItem: () => Promise<void>;
}

// @beta
export interface IUseCheckout {
// (undocumented)
Expand Down Expand Up @@ -674,6 +708,11 @@ export function useBreadcrumbs(params?: {
// @beta
export function useCart(): IUseCart;

// @beta
export function useCartItem({ cartItem }: {
cartItem: LineItem;
}): IUseCartItem;

// @beta
export function useCheckout(): IUseCheckout;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCart](./composables.iusecart.md) &gt; [broadcastUpcomingErrors](./composables.iusecart.broadcastupcomingerrors.md)

## IUseCart.broadcastUpcomingErrors() method

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
broadcastUpcomingErrors(cart: Cart): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| cart | Cart | |

<b>Returns:</b>

void

1 change: 1 addition & 0 deletions docs/landing/resources/api/composables.iusecart.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ export interface IUseCart

| Method | Description |
| --- | --- |
| [broadcastUpcomingErrors(cart)](./composables.iusecart.broadcastupcomingerrors.md) | <b><i>(BETA)</i></b> |
| [getProductItemsSeoUrlsData()](./composables.iusecart.getproductitemsseourlsdata.md) | <b><i>(BETA)</i></b> |

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md) &gt; [changeItemQuantity](./composables.iusecartitem.changeitemquantity.md)

## IUseCartItem.changeItemQuantity property

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
changeItemQuantity: (quantity: number) => Promise<void>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md) &gt; [getProductItemSeoUrlData](./composables.iusecartitem.getproductitemseourldata.md)

## IUseCartItem.getProductItemSeoUrlData() method

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
getProductItemSeoUrlData(): Promise<Partial<Product>>;
```
<b>Returns:</b>

Promise&lt;Partial&lt;Product&gt;&gt;

14 changes: 14 additions & 0 deletions docs/landing/resources/api/composables.iusecartitem.isproduct.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md) &gt; [isProduct](./composables.iusecartitem.isproduct.md)

## IUseCartItem.isProduct property

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
isProduct: ComputedRef<boolean>;
```
14 changes: 14 additions & 0 deletions docs/landing/resources/api/composables.iusecartitem.ispromotion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md) &gt; [isPromotion](./composables.iusecartitem.ispromotion.md)

## IUseCartItem.isPromotion property

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
isPromotion: ComputedRef<boolean>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md) &gt; [itemImageThumbnailUrl](./composables.iusecartitem.itemimagethumbnailurl.md)

## IUseCartItem.itemImageThumbnailUrl property

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
itemImageThumbnailUrl: ComputedRef<string>;
```
14 changes: 14 additions & 0 deletions docs/landing/resources/api/composables.iusecartitem.itemoptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md) &gt; [itemOptions](./composables.iusecartitem.itemoptions.md)

## IUseCartItem.itemOptions property

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
itemOptions: ComputedRef<PropertyGroupOption[]>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md) &gt; [itemQuantity](./composables.iusecartitem.itemquantity.md)

## IUseCartItem.itemQuantity property

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
itemQuantity: ComputedRef<number | undefined>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md) &gt; [itemRegularPrice](./composables.iusecartitem.itemregularprice.md)

## IUseCartItem.itemRegularPrice property

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
itemRegularPrice: ComputedRef<number | undefined>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md) &gt; [itemSpecialPrice](./composables.iusecartitem.itemspecialprice.md)

## IUseCartItem.itemSpecialPrice property

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
itemSpecialPrice: ComputedRef<number | undefined>;
```
14 changes: 14 additions & 0 deletions docs/landing/resources/api/composables.iusecartitem.itemstock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md) &gt; [itemStock](./composables.iusecartitem.itemstock.md)

## IUseCartItem.itemStock property

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
itemStock: ComputedRef<number | undefined>;
```
14 changes: 14 additions & 0 deletions docs/landing/resources/api/composables.iusecartitem.itemtype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md) &gt; [itemType](./composables.iusecartitem.itemtype.md)

## IUseCartItem.itemType property

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
itemType: ComputedRef<LineItemType | undefined>;
```
14 changes: 14 additions & 0 deletions docs/landing/resources/api/composables.iusecartitem.lineitem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md) &gt; [lineItem](./composables.iusecartitem.lineitem.md)

## IUseCartItem.lineItem property

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
lineItem: ComputedRef<LineItem | undefined | null>;
```
40 changes: 40 additions & 0 deletions docs/landing/resources/api/composables.iusecartitem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md)

## IUseCartItem interface

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
interface for [useCartItem()](./composables.usecartitem.md) composable

<b>Signature:</b>

```typescript
export interface IUseCartItem
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [changeItemQuantity](./composables.iusecartitem.changeitemquantity.md) | (quantity: number) =&gt; Promise&lt;void&gt; | <b><i>(BETA)</i></b> |
| [isProduct](./composables.iusecartitem.isproduct.md) | ComputedRef&lt;boolean&gt; | <b><i>(BETA)</i></b> |
| [isPromotion](./composables.iusecartitem.ispromotion.md) | ComputedRef&lt;boolean&gt; | <b><i>(BETA)</i></b> |
| [itemImageThumbnailUrl](./composables.iusecartitem.itemimagethumbnailurl.md) | ComputedRef&lt;string&gt; | <b><i>(BETA)</i></b> |
| [itemOptions](./composables.iusecartitem.itemoptions.md) | ComputedRef&lt;PropertyGroupOption\[\]&gt; | <b><i>(BETA)</i></b> |
| [itemQuantity](./composables.iusecartitem.itemquantity.md) | ComputedRef&lt;number \| undefined&gt; | <b><i>(BETA)</i></b> |
| [itemRegularPrice](./composables.iusecartitem.itemregularprice.md) | ComputedRef&lt;number \| undefined&gt; | <b><i>(BETA)</i></b> |
| [itemSpecialPrice](./composables.iusecartitem.itemspecialprice.md) | ComputedRef&lt;number \| undefined&gt; | <b><i>(BETA)</i></b> |
| [itemStock](./composables.iusecartitem.itemstock.md) | ComputedRef&lt;number \| undefined&gt; | <b><i>(BETA)</i></b> |
| [itemType](./composables.iusecartitem.itemtype.md) | ComputedRef&lt;LineItemType \| undefined&gt; | <b><i>(BETA)</i></b> |
| [lineItem](./composables.iusecartitem.lineitem.md) | ComputedRef&lt;LineItem \| undefined \| null&gt; | <b><i>(BETA)</i></b> |
| [removeItem](./composables.iusecartitem.removeitem.md) | () =&gt; Promise&lt;void&gt; | <b><i>(BETA)</i></b> |

## Methods

| Method | Description |
| --- | --- |
| [getProductItemSeoUrlData()](./composables.iusecartitem.getproductitemseourldata.md) | <b><i>(BETA)</i></b> |

14 changes: 14 additions & 0 deletions docs/landing/resources/api/composables.iusecartitem.removeitem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [IUseCartItem](./composables.iusecartitem.md) &gt; [removeItem](./composables.iusecartitem.removeitem.md)

## IUseCartItem.removeItem property

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
<b>Signature:</b>

```typescript
removeItem: () => Promise<void>;
```
2 changes: 2 additions & 0 deletions docs/landing/resources/api/composables.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Vue's composables to be used in Shopware frontend application.
| [useAddToCart(params)](./composables.useaddtocart.md) | <b><i>(BETA)</i></b> Add product to cart. Options - [IUseAddToCart](./composables.iuseaddtocart.md) |
| [useBreadcrumbs(params)](./composables.usebreadcrumbs.md) | <b><i>(BETA)</i></b> Composable for displaying and setting breadcrumbs for page. |
| [useCart()](./composables.usecart.md) | <b><i>(BETA)</i></b> Composable for cart management. Options - [IUseCart](./composables.iusecart.md) |
| [useCartItem({ cartItem })](./composables.usecartitem.md) | <b><i>(BETA)</i></b> Composable for cart item management. Options - [IUseCartItem](./composables.iusecartitem.md) |
| [useCheckout()](./composables.usecheckout.md) | <b><i>(BETA)</i></b> Composable for Checkout management. Options - [IUseCheckout](./composables.iusecheckout.md) |
| [useCms(params)](./composables.usecms.md) | <b><i>(BETA)</i></b> |
| [useCountries()](./composables.usecountries.md) | <b><i>(BETA)</i></b> |
Expand Down Expand Up @@ -49,6 +50,7 @@ Vue's composables to be used in Shopware frontend application.
| [IInterceptorCallbackFunction](./composables.iinterceptorcallbackfunction.md) | interface for the callback function of interceptors |
| [IUseAddToCart](./composables.iuseaddtocart.md) | <b><i>(BETA)</i></b> interface for [useAddToCart()](./composables.useaddtocart.md) composable |
| [IUseCart](./composables.iusecart.md) | <b><i>(BETA)</i></b> interface for [useCart()](./composables.usecart.md) composable |
| [IUseCartItem](./composables.iusecartitem.md) | <b><i>(BETA)</i></b> interface for [useCartItem()](./composables.usecartitem.md) composable |
| [IUseCheckout](./composables.iusecheckout.md) | <b><i>(BETA)</i></b> interface for [useCheckout()](./composables.usecheckout.md) composable |
| [IUseCountries](./composables.iusecountries.md) | <b><i>(BETA)</i></b> |
| [IUseCountry](./composables.iusecountry.md) | <b><i>(BETA)</i></b> |
Expand Down
29 changes: 29 additions & 0 deletions docs/landing/resources/api/composables.usecartitem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@shopware-pwa/composables](./composables.md) &gt; [useCartItem](./composables.usecartitem.md)

## useCartItem() function

> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
>
Composable for cart item management. Options - [IUseCartItem](./composables.iusecartitem.md)

<b>Signature:</b>

```typescript
export declare function useCartItem({ cartItem }: {
cartItem: LineItem;
}): IUseCartItem;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| { cartItem } | { cartItem: LineItem; } | |

<b>Returns:</b>

[IUseCartItem](./composables.iusecartitem.md)

Loading

1 comment on commit 1128c69

@vercel
Copy link

@vercel vercel bot commented on 1128c69 Mar 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.