Installation:
composer require ekyna/commerce-bundle
Add to config/bundles.php:
Ekyna\CommerceBundle\EkynaCommerceBundle::class => ['all' => true],
Database Migrations: Run migrations to set up required tables:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
First Use Case: Create a basic product entity and integrate it with the bundle’s product repository:
use Ekyna\CommerceBundle\Entity\Product;
$product = new Product();
$product->setName('Test Product');
$product->setPrice(19.99);
$em->persist($product);
$em->flush();
Configuration:
Check config/packages/ekyna_commerce.yaml (auto-generated) for default settings. Override as needed:
ekyna_commerce:
cart_lifetime: 2592000 # 30 days in seconds
payment_watch_interval: 86400 # 24 hours in seconds
Product Management:
Use the ProductRepository to fetch/products:
$repository = $entityManager->getRepository(Product::class);
$products = $repository->findBy(['category' => 'electronics']);
Cart Operations: Attach carts to users or sessions:
$cart = $cartManager->createCart();
$cart->addProduct($product, 2);
$cartManager->saveCart($cart);
Order Processing: Convert carts to orders and trigger payment workflows:
$order = $orderManager->createOrderFromCart($cart);
$payment = $paymentManager->processOrder($order);
Payment Handling:
Use the PaymentManager to track statuses:
$paymentManager->watchPayments(); // Manually trigger cron logic
Symfony Events:
Listen to ekyna_commerce.order.created or ekyna_commerce.payment.status_changed for custom logic.
// src/EventListener/OrderListener.php
public function onOrderCreated(OrderCreatedEvent $event) {
$this->sendNotification($event->getOrder());
}
Custom Entities:
Extend bundle entities (e.g., Product, Order) via inheritance or traits for domain-specific fields.
API Layer:
Expose cart/order endpoints using Symfony’s JsonResponse or API Platform:
#[Route('/api/cart', methods: ['GET'])]
public function getCart(CartManager $cartManager): JsonResponse {
return new JsonResponse($cartManager->getCurrentCart()->toArray());
}
Testing:
Use Ekyna\CommerceBundle\Tests\* as a reference for unit/integration tests. Mock the PaymentGateway interface for isolated tests.
Cron Dependency:
payment:watch and cart:purge commands must run daily. Schedule them via:
0 0 * * * cd /path/to/project && php bin/console ekyna_commerce:payment:watch -e prod >> /dev/null 2>&1
php bin/console ekyna_commerce:payment:watch --env=dev
Entity Lifecycle:
cart:purge to clean up abandoned carts (configurable via cart_lifetime).Cart::isExpired() to implement custom expiration logic.Payment Gateways:
PaymentGateway service implementing Ekyna\CommerceBundle\Payment\PaymentGatewayInterface.Ekyna\CommerceBundle\Event\PaymentFailedEvent listeners.Database Schema:
doctrine:schema:update --force cautiously.Enable Debug Mode:
Set EKYNA_COMMERCE_DEBUG=true in .env to log payment/cart operations to var/log/ekyna_commerce.log.
Common Issues:
ekyna_commerce.cart_id).payment:watch or check the payment_status column in the database.Product::getFinalPrice() if using dynamic pricing.Custom Fields: Add fields to entities via Doctrine extensions or traits:
// src/Entity/ProductExtension.php
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class ProductExtension {
#[ORM\Column(type: 'string', nullable: true)]
private ?string $sku = null;
// Getters/setters...
}
Payment Strategies:
Implement Ekyna\CommerceBundle\Payment\PaymentStrategyInterface for custom payment logic (e.g., subscriptions).
Shipping Methods:
Extend ShippingMethod entity or create a ShippingCalculator service to integrate with third-party APIs.
Event Subscribers: Subscribe to bundle events for real-time actions:
// config/services.yaml
Ekyna\CommerceBundle\EventSubscriber\YourSubscriber::class:
tags:
- { name: kernel.event_subscriber }
How can I help you explore Laravel packages today?