Skip to content

Commit

Permalink
feat: #49 (docs) useShippingProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Baroshem committed Aug 22, 2021
1 parent c019eb1 commit 5f52511
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = {
['/composables/use-cart', 'useCart'],
['/composables/use-billing', 'useBilling'],
['/composables/use-shipping', 'useShipping'],
['/composables/use-shipping-provider', 'useShippingProvider'],
]
},
]
Expand Down
81 changes: 81 additions & 0 deletions docs/composables/use-shipping-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# `useShippingProvider`

## Features

`useShippingProvider` composable can be used for:

* Loading shipping methods for the current cart.

## API

* `load` - function for fetching shipping method. When invoked, it requests data from the API and populates the `response` key inside the `state` property. This method accepts a single optional `params` object. The `params` has the following option:

* `customQuery?: CustomQuery`

```ts
type CustomQuery = {
getBasicProfile: string
}
```
* `save` - not used in this integration.
::: warning
This integration does not use the `save` method. Instead a direct call from the theme to the API Client is being made and the response is saved as a new Cart object to update prices, details, etc. It works as follows:
```ts
import { useCart, useShippingProvider } from '@vue-storefront/vendure';

export default {
setup () {
const { setCart } = useCart();

const setShippingMethod = (shippingMethod) => {
const newOrder = await $vendure.api.setShippingMethod({ shippingMethodId: shippingMethod.id })
setCart(newOrder.data.setOrderShippingMethod);
}
}
}
```

:::

* `state: ShippingMethodQuote[]` - a main data object that contains shipping methods

<https://www.vendure.io/docs/graphql-api/shop/object-types/#shippingmethodquote>

* `loading: boolean` - a reactive object containing information about loading state of your `load` or `save` method.

* `error: UseShippingProviderErrors` - a reactive object containing the error message, if `load` or `save` failed for any reason.

```ts
interface UseShippingProviderErrors {
load?: Error;
save?: Error;
}
```

## Getters

We do not provide getters for checkout and its parts.

## Example

```js
import { useShippingProvider } from '@vue-storefront/vendure';
import { onSSR } from '@vue-storefront/core';

export default {
setup () {
const { load, state } = useShippingProvider();

onSSR(async () => {
await load();
});

return {
state
};
}
}
```

0 comments on commit 5f52511

Please sign in to comment.