2026-05-14 08:44:31 +00:00
[](https://github.com/blax-software)
2026-05-15 08:27:59 +00:00
# Laravel Shop
2025-11-21 10:49:41 +00:00
2025-12-03 13:12:22 +00:00
[](https://github.com/blax-software/laravel-shop/actions/workflows/tests.yml)
2026-06-02 09:40:15 +00:00
[](#testing)
2026-06-03 08:37:09 +00:00
[](#testing)
2025-12-03 13:12:22 +00:00
[](https://packagist.org/packages/blax-software/laravel-shop)
[](https://packagist.org/packages/blax-software/laravel-shop)
[](https://packagist.org/packages/blax-software/laravel-shop)
2025-11-21 10:59:25 +00:00
A comprehensive headless e-commerce package for Laravel with stock management, Stripe integration, and product actions.
2025-11-21 10:49:41 +00:00
## Features
2025-12-30 08:29:43 +00:00
- 🛍️ **Product Management** - Simple, variable, grouped, external, booking, and pool products
2025-11-21 10:49:41 +00:00
- 💰 **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
2025-12-09 09:59:46 +00:00
- 🎭 **Facade Support** - Clean, expressive API through Shop and Cart facades
- 👤 **Guest Cart Support** - Session-based carts for unauthenticated users
2025-11-21 10:49:41 +00:00
## Installation
```bash
composer require blax-software/laravel-shop
2026-05-15 08:27:59 +00:00
php artisan migrate
2025-11-21 10:49:41 +00:00
```
2026-05-15 08:27:59 +00:00
That's it — the package's migrations are auto-loaded from `vendor/` so a fresh `migrate` is all you need.
Optionally publish the config:
2025-11-21 10:49:41 +00:00
```bash
2026-05-15 08:27:59 +00:00
php artisan vendor:publish --tag="shop-config"
2025-11-21 10:49:41 +00:00
```
2026-05-15 08:27:59 +00:00
If you'd rather own the migrations in your own `database/migrations/` directory (e.g. to customise schemas, switch ID types, etc.):
2025-11-21 10:49:41 +00:00
```bash
2026-05-15 08:27:59 +00:00
php artisan vendor:publish --tag="shop-migrations"
2025-11-21 10:49:41 +00:00
```
2026-05-15 08:27:59 +00:00
To stop the package from also auto-loading them, set `'run_migrations' => false` in `config/shop.php` .
2025-12-30 08:29:43 +00:00
## Configuration
The main configuration file is located at `config/shop.php` . Here you can configure:
- Database table names
- Caching settings
- Stripe integration keys and settings
- Currency settings
2025-11-21 10:49:41 +00:00
## Quick Start
### Setup Your User Model
Add the `HasShoppingCapabilities` trait to any model that should be able to purchase products (typically your User model):
```php
use Blax\Shop\Traits\HasShoppingCapabilities;
2025-12-30 08:29:43 +00:00
use Illuminate\Foundation\Auth\User as Authenticatable;
2025-11-21 10:49:41 +00:00
class User extends Authenticatable
{
use HasShoppingCapabilities;
// ...existing code...
}
```
### Creating Your First Product
2025-12-30 08:29:43 +00:00
Use the provided Enums to ensure type safety and consistency.
2025-11-21 10:49:41 +00:00
```php
use Blax\Shop\Models\Product;
2025-12-30 08:29:43 +00:00
use Blax\Shop\Enums\ProductType;
use Blax\Shop\Enums\ProductStatus;
use Blax\Shop\Enums\StockType;
2025-11-21 10:49:41 +00:00
$product = Product::create([
'slug' => 'amazing-t-shirt',
'sku' => 'TSH-001',
2025-12-30 08:29:43 +00:00
'type' => ProductType::SIMPLE,
2025-11-21 10:49:41 +00:00
'manage_stock' => true,
2025-12-30 08:29:43 +00:00
'status' => ProductStatus::PUBLISHED,
'name' => 'Amazing T-Shirt', // Uses meta translation
'description' => 'A comfortable cotton t-shirt',
2025-11-21 10:49:41 +00:00
]);
2025-12-30 08:29:43 +00:00
// Add Price
2025-11-29 19:09:19 +00:00
$product->prices()->create([
'currency' => 'USD',
'unit_amount' => 1999, // $19.99
'sale_unit_amount' => 1499, // $14.99
'is_default' => true,
]);
2025-12-30 08:29:43 +00:00
// Manage Stock
2025-12-09 09:59:46 +00:00
$product->adjustStock(StockType::INCREASE, 100); // Add 100 items to stock
2025-12-30 08:29:43 +00:00
$product->adjustStock(StockType::DECREASE, 10); // Remove 10 items from stock
// Reserve Stock (e.g., for a booking)
2025-12-09 09:59:46 +00:00
$product->adjustStock(
StockType::CLAIMED,
2025-12-30 08:29:43 +00:00
1,
2025-12-09 09:59:46 +00:00
from: now(),
until: now()->addDay(),
2025-12-30 08:29:43 +00:00
note: 'Reserved for Order #123 '
);
2025-11-21 10:49:41 +00:00
```
2025-12-30 08:29:43 +00:00
### Working with Cart
2025-12-09 09:59:46 +00:00
```php
use Blax\Shop\Facades\Cart;
2025-12-30 08:29:43 +00:00
// Add item to cart
Cart::addToCart($product, 1);
2025-12-09 09:59:46 +00:00
2025-12-30 08:29:43 +00:00
// Add item with date range (for bookings)
Cart::addToCart($product, 1, [], now(), now()->addDay());
2025-12-09 09:59:46 +00:00
2025-12-30 08:29:43 +00:00
// Checkout
$cart = Cart::getCart();
$cart->checkout(); // Creates purchases, claims stock, etc.
2025-12-09 09:59:46 +00:00
```
2025-12-30 08:29:43 +00:00
## Advanced Usage
2025-12-09 09:59:46 +00:00
2025-12-30 08:29:43 +00:00
### Pool Products
2025-12-09 09:59:46 +00:00
2025-12-30 08:29:43 +00:00
Pool products are collections of single items (e.g., "Parking Spaces" containing "Spot A1", "Spot A2").
2025-11-21 10:49:41 +00:00
```php
use Blax\Shop\Models\Product;
2025-12-30 08:29:43 +00:00
use Blax\Shop\Enums\ProductType;
2025-11-21 10:49:41 +00:00
2025-12-30 08:29:43 +00:00
// Create the Pool Parent
$pool = Product::create([
'type' => ProductType::POOL,
'name' => 'Parking Spaces',
'manage_stock' => true, // Pool manages availability
2025-11-21 10:49:41 +00:00
]);
2025-12-30 08:29:43 +00:00
// Create Single Items
$spot1 = Product::create([
'type' => ProductType::BOOKING,
'name' => 'Spot A1',
]);
2025-12-09 09:59:46 +00:00
2025-12-30 08:29:43 +00:00
$spot2 = Product::create([
'type' => ProductType::BOOKING,
'name' => 'Spot A2',
]);
2025-12-09 09:59:46 +00:00
2025-12-30 08:29:43 +00:00
// Attach Singles to Pool
$pool->attachSingleItems([$spot1->id, $spot2->id]);
2025-12-09 09:59:46 +00:00
```
2025-12-30 08:29:43 +00:00
### Booking Products
2025-11-21 10:49:41 +00:00
2025-12-30 08:29:43 +00:00
Booking products are time-based and require `from` and `until` dates when adding to cart.
2025-11-21 10:49:41 +00:00
```php
2025-12-30 08:29:43 +00:00
use Blax\Shop\Models\Product;
use Blax\Shop\Enums\ProductType;
2025-11-21 14:52:06 +00:00
2025-12-30 08:29:43 +00:00
$room = Product::create([
'type' => ProductType::BOOKING,
'name' => 'Conference Room',
'manage_stock' => true,
]);
2025-11-21 14:52:06 +00:00
2025-12-30 08:29:43 +00:00
// Check availability
$isAvailable = $room->availableOnDate(now(), now()->addHour());
2025-11-21 14:52:06 +00:00
```
feat(i18n,stripe): de/pl translations + order address snapshots from Checkout Session
- lang/de and lang/pl for cart.php and auth.php (informal register), every
key of lang/en translated; README documents the `shop::` namespace and
the lang/vendor/shop/<locale>/ override path.
- StripeWebhookController::handleCheckoutSessionCompleted now persists the
session's customer_details as Order.billing_address and shipping_details
as Order.shipping_address (falls back to billing when Stripe sent no
shipping block). Snapshot shape: name, email, phone, line1, line2,
postal_code, city, state, country, uid (first tax id). Only empty columns
are filled; a session without either block leaves the order untouched.
Optional host-added customer_email/customer_name columns are filled when
present and empty. Accepts Stripe objects, stdClass and arrays.
- Controller formatted with pint (composer lint).
Tests: tests/Unit/Stripe/StripeWebhookAddressTest.php (5),
tests/Feature/ShopServiceProvider/TranslationsTest.php (4). Full suite
green (1477, 7 skipped).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-21 11:39:40 +00:00
## Translations
The package ships its user-facing messages under the `shop` translation
namespace (`lang/{en,de,pl}/cart.php` and `auth.php` , registered by
`ShopServiceProvider` via `loadTranslationsFrom(..., 'shop')` ). Use them with
`__('shop::cart.added')` ; the active `app()->getLocale()` picks the language
(`en`, `de` , `pl` shipped; other locales fall back to `en` ).
To override or extend a message, drop a file at
`lang/vendor/shop/<locale>/<file>.php` in your application, e.g.
`lang/vendor/shop/de/cart.php` returning only the keys you want to change.
Laravel merges vendor overrides on top of the package defaults, so untouched
keys keep their shipped text.
2025-12-30 08:29:43 +00:00
## Testing
2025-11-21 14:52:06 +00:00
2026-05-16 10:17:38 +00:00
We test this package for many edge cases across every surface — products,
stock, pricing strategies, cart/checkout, loan lifecycle, pool aggregation,
booking, Stripe sync and the event surface — so host applications can lean
on the behaviour with confidence.
```
2026-06-03 08:37:09 +00:00
Tests: 1409, Assertions: 3774
2026-05-16 10:17:38 +00:00
```
CI runs the full suite on every push (see the badge above). To run it
locally:
2025-11-21 10:49:41 +00:00
```bash
2025-12-30 08:29:43 +00:00
./vendor/bin/phpunit
2025-11-21 10:49:41 +00:00
```
2026-05-16 10:17:38 +00:00
The tests use an in-memory SQLite database and Orchestra Testbench, so they
run in roughly a minute with no external services required.
2025-11-21 10:49:41 +00:00
2025-12-30 08:29:43 +00:00
## Documentation
2025-11-21 10:49:41 +00:00
2025-12-30 08:29:43 +00:00
For more detailed documentation, please refer to the `docs/` directory in the repository.
2026-05-14 08:44:31 +00:00
2026-11-04 10:35:23 +00:00
## Maintainer
Maintained by [Blax Software ](https://www.blax.at/laravel ), a software practice in Austria. Bugs and pull requests go to this repository; for project work, write to office@blax.at.
2026-05-14 08:44:31 +00:00
## License
MIT. See [LICENSE ](LICENSE ).
## Star History
< a href = "https://www.star-history.com/?repos=blax-software%2Flaravel-shop&type=date&legend=top-left" >
< picture >
< source media = "(prefers-color-scheme: dark)" srcset = "https://api.star-history.com/chart?repos=blax-software/laravel-shop&type=date&theme=dark&legend=top-left" / >
< source media = "(prefers-color-scheme: light)" srcset = "https://api.star-history.com/chart?repos=blax-software/laravel-shop&type=date&legend=top-left" / >
< img alt = "Star History Chart" src = "https://api.star-history.com/chart?repos=blax-software/laravel-shop&type=date&legend=top-left" / >
< / picture >
< / a >