useUserOrderHistory()

The useUserOrderHistory() composable method allows for fetching and storing the user's Order History.

orderHistory

Main data object populated by the load() method.

Type

const orderHistory: ComputedProperty<OrderHistoryList>

References: OrderHistoryList

loading

Indicates whether any of the composable methods is in progress.

Type

const loading: ComputedProperty<UseUserOrderHistoryLoading>;

References: UseUserOrderHistoryLoading

error

Contains errors thrown by any of the composable methods.

Type

const error: ComputedRef<UseUserOrderHistoryError>;

References: UseUserOrderHistoryError

load()

Fetches the user's order history and populates the orderHistory property. Under the hood, it sends a request to the getUserOrderHistory API endpoint.

Remember to log in first!

This method will not work when used during an anonymous session.

Type

interface LoadUserOrderHistoryProps extends BaseProps {
  currentPage?: number;
  pageSize?: number;
  sort?: string;
  statuses?: string;
}

async function load: (props?: LoadUserOrderHistoryProps) => Promise<void>

References: LoadUserOrderHistoryProps, BaseProps

Example

In the following example, we are fetching the first page of a paginated user's order history. We are also filtering the results by statuses, sort them byOrderNumber and specify the subset of fields to be returned in the response.

import { onMounted } from '@nuxtjs/composition-api';
import { useUserOrderHistory } from '@vsf-enterprise/sapcc';

export default {
  setup() {
    const { orderHistory, load: loadOrderHistory } = useUserOrderHistory();

    onMounted(async () => {
      await loadOrderHistory({
        currentPage: 0,
        pageSize: 3,
        statuses: 'READY,COMPLETED,SUSPENDED',
        sort: 'byOrderNumber',
        fields: 'orders(code,placed,status,statusDisplay,total(FULL))'
      });
    });

    return { orderHistory };
  }
};