Shop & E-Commerce Module

1. Deep Dive: Luxe E-Commerce & Transaction Engine

The Shop Module transforms Zero CMS into a robust, high-performance transactional storefront. Engineered on strict multi-tenant isolation, the module manages a fully relational catalog, variant-level stock parameters, and orders processing pipelines with **100% zero package dependencies**.

System Capabilities

  • Relational Categories & Catalog: Groups products into multi-tenant categories with clean SEO slug generation.
  • Product Variants & Stock Mapping: Maps unique SKUs, pricing overrides, and isolated stock parameters directly per variant option (e.g. Size, Color).
  • Session-Cart Checkout: Persists the order and its order items, then decrements each purchased variant's stock via ProductVariant::save(). Note this is a known concurrency gap rather than a solved one: there is currently no row-level locking (FOR UPDATE) or transaction wrapping the stock read-and-decrement, so two simultaneous checkouts against the same low-stock variant can still oversell it.
  • Relational Orders Tracking: Records detailed customer meta-headers and tracks relational order item lists inside historical ledger tables.

2. High-Contrast Administrative Previews & Mockups

Below are visual structures and back-office mockups representing the Shop module's administrative workspace and public catalog displays:

Backend Product & Variant Inventory Manager

https://d6laptop.zero.shop/admin/shop/products/edit?id=019ec7cd
[EDIT PRODUCT] - Luxe Cashmere Wool Scarf
Category: Winter Wear  |  Base Price: $120.00  |  Status: Published
Variant Pricing & Inventory Matrices:
OptionSKUPrice OverrideStock Quantity
Midnight BlackW-001-BLK$120.0015 (In Stock)
Charcoal GreyW-001-GRY$120.000 (Out of Stock)

Backend Orders Ledger & Relational Items Viewer

https://d6laptop.zero.shop/admin/shop/orders/view?id=019ec7cd
ORDER DETAILS: #019ec7cd-57c5-738b-8f0b-9235f5d2d930
Customer Name: John Connor (john@leader.resistance)
Shipping Address: Sector 4 Bunker, Old Los Angeles Ruins
Order Total: $240.00  |  Status: Payment Settled
Relational Purchased Items:
Product TitleVariant SKUQuantityUnit Price
Luxe Cashmere Wool ScarfW-001-BLK2$120.00

Product ActiveRecord Model (Product.php)

Product ActiveRecord Model (Product.php) php
namespace Zero\Modules\Shop\Models;

class Product implements Model
{
    use IsModel;
    protected static string $tableName = 'shop_products';
    protected static array $fillable = ['site_id', 'category_id', 'title', 'slug', 'sku', 'description', 'price', 'compare_at_price', 'main_image', 'status'];

    public $id;
    public $title;
    public $slug;
    public $price;
    public $compare_at_price;
}

Product Variant Model (ProductVariant.php)

Product Variant Model (ProductVariant.php) php
namespace Zero\Modules\Shop\Models;

class ProductVariant implements Model
{
    use IsModel;
    protected static $tableName = 'shop_product_variants';
    protected static $fillable = ['site_id', 'product_id', 'title', 'sku', 'price', 'stock'];

    public $id;
    public $product_id;
    public $title;
    public $sku;
    public $price;
    public $stock;
}

Orders & Order Items Models (Order.php & OrderItem.php)

Orders & Order Items Models (Order.php & OrderItem.php) php
namespace Zero\Modules\Shop\Models;

class Order implements Model
{
    use IsModel;
    protected static $tableName = 'shop_orders';
    protected static $fillable = ['site_id', 'customer_name', 'customer_email', 'total_price', 'status', 'shipping_address'];
}

class OrderItem implements Model
{
    use IsModel;
    protected static $tableName = 'shop_order_items';
    protected static $fillable = ['site_id', 'order_id', 'product_id', 'variant_id', 'title', 'quantity', 'price'];
}

Session-Cart Checkout Workflow (CheckoutController.php)

Session-Cart Checkout Workflow (CheckoutController.php) php
namespace Zero\Modules\Shop\Controllers;

class CheckoutController implements Controller
{
    public function handle($param)
    {
        $cart = $_SESSION['cart'] ?? [];
        // ... validate name/email/address, then:

        $order = new Order([
            'id' => $orderId,
            'site_id' => App::getCurrentSiteId(),
            'customer_name' => $name,
            'customer_email' => $email,
            'total_price' => $subtotal,
            'status' => 'paid', // Marked paid immediately -- demo checkout simulation, no payment gateway
            'shipping_address' => $address,
        ]);
        $order->save();

        foreach ($cart as $item) {
            (new OrderItem([/* ... */]))->save();

            // Inventory deduction -- NOT locked or transaction-wrapped. Two concurrent
            // checkouts against the same low-stock variant can both read the stale stock
            // value before either writes, oversells the variant, and neither call raises
            // an error -- a known gap, not a solved race condition.
            if (!empty($item['variant_id'])) {
                $variant = ProductVariant::find($item['variant_id']);
                if ($variant) {
                    $variant->stock = max(0, $variant->stock - $item['quantity']);
                    $variant->save();
                }
            }
        }

        $_SESSION['cart'] = [];
    }
}