Skip to main content
This tutorial was written by Claude Code (an AI) and has not yet been reviewed. Follow along with caution. If the tutorial was helpful or a specific part was not clear/correct, please provide feedback at the bottom of the page. Thank you.

Introduction

OxbowUI is an open-source component library featuring ready-to-use components built with Tailwind CSS and AlpineJS. In this tutorial, you’ll learn how to use OxbowUI’s ecommerce components with CoCart API to build dynamic product pages in Astro.

What You’ll Build

  • A responsive product grid for listing products
  • A detailed product page with image and description
  • Dynamic product data from CoCart/WooCommerce
  • Add to cart functionality with AlpineJS
  • Proper image handling and pricing display

Prerequisites

  • An Astro project set up with CoCart
  • CoCart installed and activated on your WordPress site
  • Basic knowledge of Astro, Tailwind CSS, and AlpineJS
  • Tailwind CSS and AlpineJS installed in your project
If you haven’t set up your Astro project yet, follow the Astro Setup Guide first.

Understanding OxbowUI Components

We’ll be working with three OxbowUI ecommerce components. You can interact with the demos below to see how they work:

1. Product Grid Component

A responsive grid layout for displaying multiple products: The component structure:

2. Product Detail Component

A detailed product view with image, price, and description: The component structure:
We’ll adapt these structures to work with CoCart product data.

Creating the Product Grid Component

Create src/components/ProductGrid.astro:

Creating the Products Page

Create src/pages/products.astro:

Creating the Product Detail Component

Create src/components/ProductDetail.astro:

Creating a Variable Product Component

For products with variations (colors, sizes), we’ll use an advanced component with interactive features:

3. Variable Product Component (Interactive Demo)

Try selecting a color and size, then click “Add to Cart”: Now let’s create src/components/VariableProduct.astro:

Creating the Product Detail Page

Create src/pages/product/[slug].astro:

Adding Interactive Cart Functionality

To add items to cart with interactivity, create enhanced versions with AlpineJS.

Interactive Product Grid

Create src/components/ProductGridInteractive.astro:

Interactive Product Detail

Create src/components/ProductDetailInteractive.astro:

Creating the Cart API Endpoint

Create src/pages/api/cart/add.js:
Make sure AlpineJS is installed and configured in your project. See the Astro Setup Guide for instructions.

Working with Variable Products

To add variable products to cart, you need to find the correct variation ID based on selected attributes. Update your CoCart API client in src/lib/cocart.js:
Then create an interactive variable product component that uses these functions to add the correct variation to cart.

Understanding the CoCart Response

The CoCart Products API returns data in this structure:

Customization Options

Filtering Products

Add category or search filtering:

Different Grid Layouts

Modify the grid classes in ProductGrid.astro:

Price Variations

Handle sale prices:

Component Usage Summary

You now have six components to use in your Astro project:

Product Listing Components

  1. ProductGrid.astro - Static product grid (SEO-friendly, server-rendered)
  2. ProductGridInteractive.astro - Interactive product grid with add to cart

Simple Product Detail Components

  1. ProductDetail.astro - Static product detail view
  2. ProductDetailInteractive.astro - Interactive product detail with add to cart

Variable Product Components

  1. VariableProduct.astro - Advanced component with:
    • Image gallery with thumbnails
    • Color selector
    • Size selector
    • Accordion sections (Details, Shipping, Returns)
    • Multiple action buttons (Add to Cart, Buy Now)
The page automatically detects if a product is variable and uses the appropriate component. Use the static versions for better SEO and performance, or the interactive versions when you need client-side cart functionality.

Next Steps

  • Explore more OxbowUI ecommerce components
  • Add product image gallery (multiple images)
  • Implement product variations (size, color selection)
  • Add product filtering and search
  • Build cart page using OxbowUI cart components
  • Create checkout flow with CoCart Checkout API
  • Add product quick view functionality

Resources