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:Creating the Product Grid Component
Createsrc/components/ProductGrid.astro
:
Creating the Products Page
Createsrc/pages/products.astro
:
Creating the Product Detail Component
Createsrc/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 createsrc/components/VariableProduct.astro
:
Creating the Product Detail Page
Createsrc/pages/product/[slug].astro
:
Adding Interactive Cart Functionality
To add items to cart with interactivity, create enhanced versions with AlpineJS.Interactive Product Grid
Createsrc/components/ProductGridInteractive.astro
:
Interactive Product Detail
Createsrc/components/ProductDetailInteractive.astro
:
Creating the Cart API Endpoint
Createsrc/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 insrc/lib/cocart.js
:
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
- ProductGrid.astro - Static product grid (SEO-friendly, server-rendered)
- ProductGridInteractive.astro - Interactive product grid with add to cart
Simple Product Detail Components
- ProductDetail.astro - Static product detail view
- ProductDetailInteractive.astro - Interactive product detail with add to cart
Variable Product Components
- 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)
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