shopper/core
Shopper Core is the foundation package for the Shopper e-commerce platform in Laravel. It provides shared core services, utilities, and framework integrations used by Shopper modules to build and run a modular, extensible store backend.
Installation:
composer require shopperlabs/core
Ensure your composer.json specifies Laravel version constraints (e.g., ^10.0).
Publish Assets:
php artisan vendor:publish --provider="Shopper\Core\ShopperServiceProvider"
This generates config (config/shopper.php) and migrations.
Run Migrations:
php artisan migrate
Creates tables for products, carts, orders, etc.
Basic Setup:
config/shopper.php (e.g., default currency, tax settings).AppServiceProvider:
$this->app->bind(
\Shopper\Core\Contracts\OrderRepository::class,
\Shopper\Core\Repositories\EloquentOrderRepository::class
);
First Use Case: Create a product via Tinker or a controller:
use Shopper\Core\Models\Product;
$product = Product::create([
'name' => 'Test Product',
'price' => 9.99,
'sku' => 'SKU123',
]);
vendor/shopperlabs/core/src/Shopper/Core/README.md for basic usage (likely minimal).src/Shopper/Core/Models/ for Product, Cart, Order, etc., to understand relationships.ShopperServiceProvider for bootstrapped services and bindings.database/migrations/ for schema expectations (e.g., shopper_products table structure).Shopper\Core\Models\Product):
// Create
$product = Product::create([...]);
// Query
$products = Product::with('category')->where('price', '>', 10)->get();
Product model to add custom inventory logic:
class Product extends \Shopper\Core\Models\Product
{
public function updateInventory(int $quantityChange)
{
$this->stock -= $quantityChange;
$this->save();
}
}
Cart facade or service:
use Shopper\Core\Facades\Cart;
Cart::add($productId, $quantity = 1, $options = []);
$this->app->bind(
\Shopper\Core\Contracts\CartRepository::class,
\App\Repositories\SessionCartRepository::class
);
Order service to create orders from carts:
use Shopper\Core\Services\OrderService;
$order = app(OrderService::class)->createFromCart($cartId, $user);
event(new \Shopper\Core\Events\OrderCreated($order));
config/shopper.php:
'payments' => [
'gateways' => [
'stripe' => [
'enabled' => true,
'key' => env('STRIPE_KEY'),
],
],
],
Use the Payment facade:
use Shopper\Core\Facades\Payment;
$paymentIntent = Payment::createIntent($order, 'stripe');
$this->app->singleton(\Shopper\Core\Contracts\TaxCalculator::class, function ($app) {
return new \App\Services\CustomTaxCalculator();
});
OrderPaid) in your EventServiceProvider:
protected $listen = [
\Shopper\Core\Events\OrderPaid::class => [
\App\Listeners\SendOrderConfirmation::class,
],
];
Route::middleware(['auth', 'can:manage-orders'])->group(function () {
Route::resource('orders', \App\Http\Controllers\OrderController::class);
});
use Shopper\Core\Models\Product;
class Product extends Product
{
use \App\Traits\ProductAnalytics;
}
// config/view.php
'composers' => [
'shopper::products.index' => \App\View\Composers\ProductComposer::class,
];
namespace App\Http\Resources;
use Shopper\Core\Models\Order;
use Illuminate\Http\Resources\Json\JsonResource;
class OrderResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'items' => OrderItemResource::collection($this->items),
'status' => $this->status,
];
}
}
type Order {
id: ID!
items: [OrderItem!]!
status: String!
}
Undocumented Assumptions:
utf8mb4) or table engines (e.g., InnoDB). Verify in migrations.Naming Conflicts:
Product or Order may conflict with existing models.shopper_products) or namespace models:
class Product extends \Shopper\Core\Models\Product {}
Transaction Handling:
DB::transaction(function () {
$order = app(OrderService::class)->createFromCart($cartId, $user);
});
Caching Quirks:
Cache::remember) could cause stale data.event(new \Shopper\Core\Events\ProductUpdated($product));
Payment Gateway Lock-in:
$this->app->bind(
\Shopper\Core\Contracts\PaymentGateway::class,
\App\Services\CustomPaymentGateway::class
);
Log Configuration:
Enable debug logging in config/shopper.php:
'debug' => env('APP_DEBUG', false),
Check logs at storage/logs/laravel.log for package-specific entries.
Query Logging: Use Laravel Debugbar to inspect queries:
if (app()->environment('local')) {
$bar = app(\Barryvdh\Debugbar\Debugbar::class);
}
Event Debugging:
Listen for all events in AppServiceProvider:
public function boot()
{
if (app()->environment('local')) {
\Shopper\Core\Events\Event::listen(function ($event) {
\Log::info("Event fired: {$event::class}", $event->toArray());
});
}
}
Service Container Inspection: Dump bindings to verify overrides:
dd(app()->bindings());
Environment Variables:
The package may not use Laravel’s .env conventions (e.g., SHOPPER_* prefixes).
config/shopper.php:
'currency' => env('CURRENCY', 'USD'),
Default Values: Some settings may lack defaults, causing runtime errors.
How can I help you explore Laravel packages today?