Go to file
Fabian @ Blax Software c711afb570 R reserve to claim 2025-12-04 11:06:09 +01:00
.github/workflows D laravel 9, A php 8.5 2025-12-03 14:52:32 +01:00
config A tests, I product action 2025-11-29 20:09:19 +01:00
database R reserve to claim 2025-12-04 11:06:09 +01:00
docs A stripe & BFI cart 2025-11-28 10:24:07 +01:00
routes init 2025-11-21 11:49:41 +01:00
src R reserve to claim 2025-12-04 11:06:09 +01:00
tests R reserve to claim 2025-12-04 11:06:09 +01:00
workbench BF laravel 9 2025-12-03 14:49:44 +01:00
.dockerignore init 2025-11-21 11:49:41 +01:00
.env.example I tests & structure 2025-11-29 12:05:02 +01:00
.envrc init 2025-11-21 11:49:41 +01:00
.gitattributes init 2025-11-21 11:49:41 +01:00
.gitignore A testbench, BF tests 2025-12-03 14:18:38 +01:00
README.md AI readme, tests 2025-12-03 14:12:22 +01:00
composer.json U composer cashier 2025-12-03 14:45:43 +01:00
phpunit.xml I tests & structure 2025-11-29 12:05:02 +01:00
pint.json init 2025-11-21 11:49:41 +01:00
shell.nix init 2025-11-21 11:49:41 +01:00
test.sh init 2025-11-21 11:49:41 +01:00
testbench.yaml init 2025-11-21 11:49:41 +01:00

README.md

Laravel Shop Package

Tests Latest Version License PHP Version

A comprehensive headless e-commerce package for Laravel with stock management, Stripe integration, and product actions.

Features

  • 🛍️ Product Management - Simple, variable, grouped, and external products
  • 💰 Multi-Currency Support - Handle multiple currencies with ease
  • 📦 Advanced Stock Management - Stock reservations, low stock alerts, and backorders
  • 💳 Stripe Integration - Built-in Stripe product and price synchronization
  • 🎯 Product Actions - Execute custom actions on product events (purchases, refunds)
  • 🔗 Product Relations - Related products, upsells, and cross-sells
  • 🌍 Translation Ready - Built-in meta translation support
  • 📊 Stock Logging - Complete audit trail of stock changes
  • 🎨 Headless Architecture - Perfect for API-first applications
  • Caching Support - Built-in cache management for better performance
  • 🛒 Shopping Capabilities - Built-in trait for any purchaser model

Installation

composer require blax-software/laravel-shop

Publish the configuration:

php artisan vendor:publish --provider="Blax\Shop\ShopServiceProvider"

Run migrations:

php artisan migrate

Quick Start

Setup Your User Model

Add the HasShoppingCapabilities trait to any model that should be able to purchase products (typically your User model):

use Blax\Shop\Traits\HasShoppingCapabilities;

class User extends Authenticatable
{
    use HasShoppingCapabilities;
    
    // ...existing code...
}

Creating Your First Product

use Blax\Shop\Models\Product;

$product = Product::create([
    'slug' => 'amazing-t-shirt',
    'sku' => 'TSH-001',
    'type' => 'simple',
    'manage_stock' => true,
    'status' => 'published',
]);

$product->prices()->create([
    'currency' => 'USD',
    'unit_amount' => 1999, // $19.99
    'sale_unit_amount' => 1499, // $14.99
    'is_default' => true,
]);

$product->stocks()->create([
    'quantity' => 100,
]);

// Add translated name
$product->setLocalized('name', 'Amazing T-Shirt', 'en');
$product->setLocalized('description', 'A comfortable cotton t-shirt', 'en');

Purchasing a Product

use Blax\Shop\Models\Product;

$product = Product::find($productId);
$user = auth()->user();

// Simple purchase
$purchase = $user->purchase($product, quantity: 1);

// Purchase with options
$purchase = $user->purchase($product, quantity: 2, options: [
    'price_id' => $priceId,
    'charge_id' => $paymentIntent->id,
]);

// Add to cart
$cartItem = $user->addToCart($product, quantity: 1);

// Checkout cart
$completedPurchases = $user->checkoutCart();

// Check if user has purchased
if ($user->hasPurchased($product)) {
    // Grant access
}

Documentation

Configuration

The config/shop.php file contains all configuration options:

return [
    'tables' => [
        'products' => 'products',
        'product_categories' => 'product_categories',
        // ...
    ],
    
    'stripe' => [
        'enabled' => env('SHOP_STRIPE_ENABLED', false),
        'sync_prices' => env('SHOP_STRIPE_SYNC_PRICES', true),
    ],
    
    'stock' => [
        'allow_backorders' => env('SHOP_ALLOW_BACKORDERS', false),
        'log_changes' => env('SHOP_LOG_STOCK_CHANGES', true),
    ],
    
    'cache' => [
        'enabled' => env('SHOP_CACHE_ENABLED', true),
        'prefix' => 'shop:',
    ],
];

Commands

Add Example Products

Create example products for testing and demonstration purposes:

# Create 2 products of each type (default)
php artisan shop:add-example-products

# Create 5 products of each type
php artisan shop:add-example-products --count=5

# Clean existing example products first
php artisan shop:add-example-products --clean

This command creates:

  • All 4 product types (simple, variable, grouped, external)
  • Product categories
  • Product attributes (material, size, color, etc.)
  • Multiple pricing options (multi-currency, subscriptions)
  • Example product actions (email notifications, stats updates)
  • Variations for variable products
  • Child products for grouped products
  • Realistic data using Faker

Reinstall Shop Tables

# With confirmation
php artisan shop:reinstall

# Force without confirmation
php artisan shop:reinstall --force

⚠️ Warning: This will delete all shop data!

License

MIT License

Support

For issues and questions, please use the GitHub issue tracker.