Installation
composer require dywee/shipment-bundle
Add to config/bundles.php (Symfony) or config/app.php (Laravel via bridge):
Dywee\ShipmentBundle\DyweeShipmentBundle::class => ['all' => true],
Database Migration
Run the bundle’s migrations (check vendor/dywee/shipment-bundle/migrations/ for raw SQL or use Doctrine migrations if integrated):
php artisan migrate # (if using Laravel bridge)
Key tables: shipments, shipment_items, shipment_statuses.
First Use Case: Create a Shipment
use Dywee\ShipmentBundle\Entity\Shipment;
use Dywee\ShipmentBundle\Entity\ShipmentItem;
$shipment = new Shipment();
$shipment->setSender('John Doe');
$shipment->setRecipient('Jane Smith');
$shipment->setTrackingNumber('TRK12345');
$item = new ShipmentItem();
$item->setProduct('Laptop');
$item->setQuantity(1);
$shipment->addItem($item);
$entityManager->persist($shipment);
$entityManager->flush();
CRUD Operations
Use the bundle’s repository (Dywee\ShipmentBundle\Repository\ShipmentRepository) for common queries:
$shipments = $shipmentRepo->findBy(['status' => 'pending']);
Status Management
Define custom statuses via YAML/Doctrine extensions (see Resources/config/shipment_statuses.yml):
# config/packages/dywee_shipment.yaml
dywee_shipment:
statuses:
- { name: 'pending', label: 'Pending' }
- { name: 'shipped', label: 'Shipped' }
Integration with Orders
Link shipments to order IDs (extend Shipment entity):
$shipment->setOrderId($order->getId());
API Endpoints Use Symfony’s serializers (or Laravel’s API resources) to expose shipments:
// Symfony Controller
#[Route('/api/shipments', methods: ['GET'])]
public function listShipments(ShipmentRepository $repo): JsonResponse
{
return $this->json($repo->findAll());
}
Event Listeners Hook into shipment status changes (e.g., trigger notifications):
// src/EventListener/ShipmentStatusListener.php
public function onShipmentStatusChange(ShipmentStatusEvent $event)
{
if ($event->getNewStatus() === 'shipped') {
$this->notifyCustomer($event->getShipment());
}
}
Batch Processing
Use Doctrine’s BATCH_SIZE for bulk updates:
$shipments = $shipmentRepo->findBy(['status' => 'pending'], null, 100);
foreach ($shipments as $shipment) {
$shipment->setStatus('processed');
}
$entityManager->flush();
Entity Manager Conflicts
EntityManager is properly bridged (check config/packages/doctrine.yaml for custom EM names).Status Validation
dywee_shipment.yaml before first use.php artisan cache:clear # (Laravel bridge)
Tracking Number Uniqueness
$table->string('tracking_number')->unique();
Translation Issues
pending) rely on Symfony’s translation system. Ensure locales are configured in config/packages/framework.yaml.Log Entity Changes Enable Doctrine logging to track persisted changes:
# config/packages/doctrine.yaml
doctrine:
dbal:
logging: true
logging_format: '%%timestamp%% %%sql%%'
Check Event Dispatching
Verify listeners are subscribed in services.yaml:
services:
App\EventListener\ShipmentStatusListener:
tags:
- { name: kernel.event_listener, event: dywee.shipment.status_change, method: onShipmentStatusChange }
Custom Fields
Extend the Shipment entity (e.g., add estimatedDeliveryDate):
// src/Entity/Shipment.php
#[ORM\Column(type: 'date')]
private ?\DateTimeInterface $estimatedDeliveryDate = null;
Carrier Integration
Override the Shipment class to add carrier-specific fields (e.g., dhlTrackingUrl):
public function getCarrierUrl(): ?string
{
return $this->carrier === 'dhl' ? "https://track.dhl.com/..." : null;
}
Validation Rules Add constraints via Symfony’s validator (e.g., validate tracking number format):
use Symfony\Component\Validator\Constraints as Assert;
#[Assert\Regex("/^[A-Z0-9]{6,}$/")]
private ?string $trackingNumber;
How can I help you explore Laravel packages today?