sylius/promotion package is a decoupled component, making it ideal for integration into modular PHP architectures (e.g., Laravel, Symfony, or custom MVC setups). It follows a component-based design, allowing selective adoption of promotion logic without tight coupling to Sylius’s full e-commerce stack.ExpressionLanguage, Workflow). Laravel’s service container and event system can host this component with minimal overhead.spatie/laravel-graphql).Promotion, PromotionRule, PromotionAction). TPMs must map these to Laravel’s existing cart/checkout flows.active, expired). Laravel’s stateful models or event-based transitions (e.g., model_observers) may need adaptation.symfony/cache) or pre-computing eligible promotions may be needed.laravel-cart) or a custom solution? The package expects a CartInterface; alignment is critical.checkout.order.placed) can bridge this.POST /coupons/{code}) or entered in the UI? Laravel’s form requests or API gateways can handle this.PromotionAction classes may be needed.ExpressionLanguage) integrate cleanly with Laravel’s service container via package auto-discovery or manual registration.PromotionResource::collection()).composer require sylius/promotion.config/app.php:
Sylius\Promotion\PromotionServiceProvider::class,
php artisan vendor:publish --provider="Sylius\Promotion\PromotionServiceProvider"
PromotionApplicatorInterface.class Order extends Model {
use HasPromotions;
}
PromotionChecker to evaluate rules against Laravel’s cart.$rule = new CartTotalRule('gt', 50);
$promotion->addRule($rule);
Route::post('/coupons/{code}', [CouponController::class, 'apply']);
ProductVariant) may require abstraction.checkout.order.created event).PromotionAction (e.g., "Add gift product") and PromotionRule (e.g., "User has tag").ExpressionLanguage), migrate to Laravel alternatives (e.g., spatie/laravel-expression-evaluator).promotion.applied, coupon.redeemed).promotion_rules.conditions (e.g., cart_total, product_id).coupons.code (for fast redemption checks).Redis).Promotion::ACTIVE) may need database-level locking.| Failure Scenario | Mitigation |
|---|---|
| Rule evaluation errors | Use try-catch in PromotionChecker; log errors with context (e.g., cart ID). |
| Coupon exhaustion | Implement optimistic locking or queue delayed jobs for redemption. |
| Database deadlocks | Use transactions |
How can I help you explore Laravel packages today?