Presenting a Storefront

The Buy SDK provides access to shop data that a mobile app can use to present a native mobile storefront. This includes details about the shop itself, the product catalog, and customer accounts. Customer support is described in Customers.

Getting the Shop

Get information associated with a shop. This information includes the mailing address, web address and currency of the shop. The shop does not change often, and can be cached for each session.

buyClient.getShop(new Callback<Shop>() {
    @Override
    public void success(Shop shop) {
    // Add code to cache shop here
    }

    @Override
    public void failure(BuyClientError error) {
      // Handle errors here
    }
});

Getting Collections

Collections and products are provided in paginated lists. The page size is configurable using the productPageSize property of BuyClient. Pages are numbered starting at 1. If your shop has no collections, or the last page of collections has already been fetched this may be an empty list.

To get a partial list of collections, provide the desired page number:

buyClient.getCollections(1, new Callback<List<Collection>>() {
    @Override
    public void success(List<Collection> collections) {
    // Add code to display here
    }

    @Override
    public void failure(BuyClientError error) {
      // Handle errors here
    }
});

Getting Products

There are multiple ways to get products from a shop. You can get all products by page, retrieve the products in a collection, get a product by a handle, or get individual products by id.

Get a page of products from a shop. If your shop has no products, or the last page of products has already been fetched this may be an empty list.

buyClient.getProducts(1, new Callback<List<Product>>() {
    @Override
    public void success(List<Product> products) {
    // Add code to display here
    }

    @Override
    public void failure(BuyClientError error) {
      // Handle errors here
    }
});

Get a page of products from a collection. If your collection has no products, or the last page of products has already been fetched the products may be an empty list.

buyClient.getProducts(1, collectionId, null, null, new Callback<List<Product>>() {
    @Override
    public void success(List<Product> products) {
    // Add code to display here
    }

    @Override
    public void failure(BuyClientError error) {
      // Handle errors here
    }
});

Get products by identifier. This may return an empty list if none of the identifiers are found.

List<Long> ids = Arrays.asList(1331L, 123122L, 1241L);
buyClient.getProducts(ids, new Callback<List<Product>>() {
    @Override
    public void success(List<Product> products) {
    // Add code to display here
    }

    @Override
    public void failure(BuyClientError error) {
      // Handle errors here
    }
});

Get product by handle. This will return null if a product with that handle cannot be found.

buyClient.getProductByHandle("my-awesome-product", new Callback<Product>() {
    @Override
    public void success(Product product) {
    // Add code to display here
    }

    @Override
    public void failure(BuyClientError error) {
      // Handle errors here
    }
});

Get collection by handle. This will return null if a collection with that handle cannot be found.

buyClient.getCollectionByHandle("my-awesome-collection", new Callback<Collection>() {
    @Override
    public void success(Collection collection) {
    // Add code to display here
    }

    @Override
    public void failure(BuyClientError error) {
      // Handle errors here
    }
});