tastyigniter/ti-ext-cart
TastyIgniter Cart extension adds a flexible shopping cart and checkout for restaurants: delivery/pickup orders, tips/taxes via cart conditions, menu scheduling, inventory and order management, payment gateways (PayPal/Stripe/COD), notifications and emails.
Installation:
composer require tastyigniter/ti-ext-cart
php artisan vendor:publish --provider="TastyIgniter\Cart\CartServiceProvider"
php artisan migrate
Configuration:
.env with required settings (e.g., CART_SESSION_KEY, payment gateway keys).config/cart.php (e.g., default currency, tax rules, session handling).First Use Case:
use TastyIgniter\Cart\Facades\Cart;
$menuId = 1;
$quantity = 2;
$options = ['size' => 'large']; // Optional menu options
Cart::add($menuId, $quantity, $options);
@include('cart::partials.cart-summary')
Quick Checkout:
Route::get('/checkout', [CheckoutController::class, 'show'])->name('checkout.show');
Order model or controller methods provided by the package.Cart Management:
Cart::add($menuId, $quantity, $options, $locationId);
locationId for multi-location businesses (e.g., restaurants with multiple branches).Cart::update($menuId, $newQuantity);
Cart::clear();
CartCondition model or config:
Cart::applyCondition('discount_10_percent', $customerId);
Order Processing:
$order = Cart::checkout([
'customer_id' => auth()->id(),
'delivery_method' => 'pickup',
'payment_method' => 'stripe',
'notes' => 'Rush order',
]);
StatusWorkflow model to define custom status transitions (e.g., pending → accepted → shipped):
$workflow = StatusWorkflow::where('name', 'default')->first();
$order->updateStatus('accepted', $workflow);
Inventory Management:
if (!Cart::validateStock($menuId, $quantity)) {
return back()->withError('Item out of stock!');
}
Payment Integration:
$payment = $order->processPayment($gateway, $amount);
Real-Time Notifications:
OrderNotification model:
event(new OrderCreated($order));
resources/views/vendor/cart/emails/.Multi-Location Support:
location_id parameter in cart methods to manage separate inventories per branch:
Cart::setLocation($locationId);
Custom Menu Options:
MenuOption model to add validation or business logic:
public function validateOption($value, $menuOption)
{
if ($menuOption->type === 'select' && !in_array($value, $menuOption->values)) {
throw new \InvalidArgumentException('Invalid option selected.');
}
return true;
}
Dynamic Pricing:
CartCondition::create([
'name' => 'lunch_discount',
'type' => 'percentage',
'value' => 10,
'applies_to' => 'menus',
'conditions' => json_encode(['time' => '12:00-14:00']),
]);
Checkout Customization:
@extends('cart::checkout')
@section('extra_fields')
<div>{{ Form::text('custom_field', null, ['placeholder' => 'Special instructions']) }}</div>
@endsection
API Access:
Route::middleware('auth:api')->group(function () {
Route::get('/cart', [CartController::class, 'getCart']);
Route::post('/cart/add', [CartController::class, 'addToCart']);
});
Testing:
$this->actingAs($user)
->post('/cart/add', ['menu_id' => 1, 'quantity' => 2])
->assertRedirect('/cart');
Session Key Conflicts:
CART_SESSION_KEY values in config:
'session_key' => 'cart_' . env('APP_LOCATION_ID', 'default'),
Stock Validation Bypass:
out_of_stock_override feature can accidentally enable sales for unavailable items. Monitor the inventory_override_duration setting in the admin panel.Payment Gateway Fallbacks:
$defaultGateway = \TastyIgniter\PayRegister\Facades\PaymentGateway::getDefault();
Menu Option Validation:
validateOption() method or override the MenuOption model:
public function validateOption($value, $menuOption)
{
if ($menuOption->type === 'number' && !is_numeric($value)) {
throw new \InvalidArgumentException('Invalid quantity.');
}
return parent::validateOption($value, $menuOption);
}
Order Status Workflows:
Performance with Large Orders:
orders table indexes on status_id, created_at):
Schema::table('orders', function (Blueprint $table) {
$table->index('status_id');
$table->index('created_at');
});
Blade Template Conflicts:
@extends('cart::layouts.app')). Override templates in resources/views/vendor/cart/.Cart Contents:
dd(\TastyIgniter\Cart\Facades\Cart::getContent());
Order Events:
Order::created(function ($order) {
\Log::info('New order created:', ['order_id' => $order->id]);
});
Session Issues:
session()->forget(\TastyIgniter\Cart\Facades\Cart::getSessionKey());
Inventory Logs:
\TastyIgniter\Inventory\Facades\Inventory::enableLogging();
Payment Gateway Errors:
payment_gateways table for misconfigured gateways or missing API keys.CartCondition model to add logic (e.g., user-specific discounts):
namespace App\Extensions;
use TastyIgniter\Cart\Models\CartCondition;
class LoyaltyDiscount extends CartCondition
{
public function apply($cart)
{
if (auth()->user()->isLoyaltyMember()) {
$cart->applyDiscount('loyalty_15_percent', 15);
}
}
}
How can I help you explore Laravel packages today?