Installation
composer require dywee/order-bundle
Ensure knplabs/knp-paginator-bundle is also installed (required dependency).
Register the Bundle
Add to config/bundles.php:
Dywee\OrderBundle\DyweeOrderBundle::class => ['all' => true],
Basic Configuration
Configure in config/packages/dywee_order.yaml (or config/services.yaml):
parameters:
order_bundle.is_price_ttc: true
order_bundle.sell_type: both # 'buy', 'rent', or 'both'
order_bundle.order_connexion_permission: anon # 'anon', 'registered', or 'both'
First Use Case: Create an Order
Inject the OrderManager service and use its methods:
use Dywee\OrderBundle\Manager\OrderManager;
public function createOrder(OrderManager $orderManager) {
$order = $orderManager->createOrder();
$order->setCustomer($customerEntity);
$order->setItems([$product1, $product2]);
$orderManager->saveOrder($order);
}
Order Creation & Management
OrderManager to handle CRUD operations:
$order = $orderManager->findOrder($orderId);
$orderManager->updateOrder($order);
$orderManager->cancelOrder($order);
OrderItemManager for line-item operations:
$orderItem = $orderManager->addItemToOrder($order, $product, $quantity);
Paginated Order Lists
use Knp\Component\Pager\PaginatorInterface;
public function listOrders(PaginatorInterface $paginator, OrderManager $orderManager) {
$orders = $orderManager->getAllOrders();
return $this->render('order/list.html.twig', [
'orders' => $paginator->paginate($orders, $request->query->getInt('page', 1))
]);
}
Permission-Based Access
order_connexion_permission to control visibility:
anon: Public access (e.g., guest checkout).registered: Requires authentication.both: Hybrid logic (e.g., anonymous view, registered edit).Price Handling
is_price_ttc to toggle tax-inclusive pricing:
order_bundle.is_price_ttc: false # Defaults to excluding tax
OrderManager::calculateTotal() to compute totals dynamically.Sell Type Logic
buy, rent, or both modes:
if ($orderManager->getSellType() === 'rent') {
$order->setRentalTerms($terms);
}
Missing KNP Paginator
Class 'Knp\Component\Pager\PaginatorInterface' not found.knplabs/knp-paginator-bundle and register it in bundles.php.Configuration Overrides
services.yaml may not apply if the bundle expects them in parameters:.order_bundle.is_price_ttc).Sell Type Mismatches
buy/rent logic without checking getSellType() can break features.if ($orderManager->getSellType() !== 'both' && $order->isRental()) {
throw new \LogicException('Rental orders not supported in current mode.');
}
Permission Logic
anon mode may expose sensitive data (e.g., order IDs) to guests.order_connexion_permission: registered for admin dashboards and anon for public-facing pages.Price TTC Quirks
is_price_ttc: true affects all price calculations, including discounts.$subtotal = $orderManager->calculateSubtotal($order);
$total = $orderManager->isPriceTtc() ? $subtotal : $subtotal + ($subtotal * $taxRate);
Order State Inspection
Use var_dump($order->getState()) to debug workflows (e.g., pending, cancelled).
Event Listeners
The bundle may dispatch events (e.g., order.created). Override them in your EventSubscriber:
public static function getSubscribedEvents() {
return [
'order.created' => 'onOrderCreated',
];
}
Database Schema
order and order_item tables to understand relationships:
php bin/console doctrine:schema:dump
order: id, customer_id, state, created_at, total_ttc.order_item: order_id, product_id, quantity, unit_price.Custom Order States
Extend the OrderState enum or add a state_machine configuration to support workflows like:
# config/packages/workflow.yaml
dywee_order:
supports_markers: true
markers:
payment_required: { label: 'Payment Required' }
Validation Rules
Override the OrderValidator service to add constraints:
# config/services.yaml
Dywee\OrderBundle\Validator\OrderValidator:
arguments:
$constraints: ['@validator.constraint_collection']
tags: [validator]
API Integration
Use the bundle’s entities with API Platform or Symfony’s Serializer:
# config/packages/api_platform.yaml
resources:
Dywee\OrderBundle\Entity\Order:
collectionOperations:
get:
security: "is_granted('ROLE_ADMIN')"
How can I help you explore Laravel packages today?