Documentation

Configuration of the Order Printer

The Order Printer offers extensive configuration options to adapt the system to your specific requirements.

Environment Configuration

The main configuration is done via the .env.local file. Here are the most important settings:

Shopware API Configuration

# Shopware API Access
SHOPWARE_HOST=https://your-shopware-domain.de
SHOPWARE_CLIENT_ID=your_client_id
SHOPWARE_CLIENT_SECRET=your_client_secret

# API Timeout (in seconds)
SHOPWARE_API_TIMEOUT=30

# API Rate Limiting
SHOPWARE_API_RATE_LIMIT=100
SHOPWARE_API_RATE_LIMIT_INTERVAL=60

Printer Configuration

# Printer name (must match CUPS)
PRINTER_NAME=TM-T20

# Printer resolution (DPI)
PRINTER_DPI=203

# Characters per line
PRINTER_CHARACTERS_PER_LINE=42

# Print speed (1-5, 1 = slow, 5 = fast)
PRINTER_SPEED=3

# Printer density (1-15)
PRINTER_DENSITY=10

System Configuration

# Polling interval (in seconds)
POLLING_INTERVAL=10

# Maximum number of concurrent print jobs
MAX_CONCURRENT_PRINTS=5

# Queue timeout (in seconds)
QUEUE_TIMEOUT=300

# Data directory for receipt archive
DATA_DIR="/data/receipts/"

# Log level (debug, info, notice, warning, error, critical, alert, emergency)
LOG_LEVEL=info

Receipt Formatting

Standard Receipt Layout

The Order Printer generates receipts with the following standard layout:

┌────────────────────────────────────────┐
│              YOUR SHOP NAME             │
│    Sample Street 123 • 12345 Sample City │
│          Tel: 01234/567890              │
├────────────────────────────────────────┤
│                RECEIPT #1001             │
│            11.01.2024 14:30            │
├────────────────────────────────────────┤
│ Customer: Max Mustermann                 │
│ Tel: 0176/12345678                       │
├────────────────────────────────────────┤
│ 1x Pizza Margherita              8,99 € │
│ 2x Spaghetti Bolognese          15,98 € │
│ 1x Salad Caesar                  5,99 € │
├────────────────────────────────────────┤
│ Subtotal:                        30,96 € │
│ Delivery costs:                   2,50 € │
│ Total:                           33,46 € │
├────────────────────────────────────────┤
│ Payment method: Cash                      │
│ Delivery type: Pickup                     │
├────────────────────────────────────────┤
│           Thank you for your             │
│                purchase!                 │
└────────────────────────────────────────┘

Customize Receipt Layout

You can change the receipt layout by adjusting the ReceiptFormatter class:

// In src/Infra/Printer/Epson/ReceiptFormatter.php

public function formatHeader(): self
{
    $this->content .= self::ALIGN_CENTER;
    $this->content .= self::DOUBLE_WIDTH_ON;
    $this->content .= "YOUR SHOP NAME\n";
    $this->content .= self::DOUBLE_WIDTH_OFF;
    $this->content .= self::ALIGN_CENTER;
    $this->content .= "Sample Street 123 • 12345 Sample City\n";
    $this->content .= "Tel: 01234/567890\n";
    $this->content .= self::FEED;
    
    return $this;
}

To add a logo to the receipt, you need to convert the logo to ESC/POS bitmap:

# Convert logo (requires ImageMagick)
convert logo.png -resize 384x128 -colorspace Gray -dither None logo.bmp

# Convert logo to ESC/POS format
php bin/console order-printer:convert-logo logo.bmp logo.escpos

Then you can include the logo in the ReceiptFormatter class:

public function addLogo(): self
{
    $logoPath = __DIR__ . '/../../../public/logo.escpos';
    if (file_exists($logoPath)) {
        $this->content .= file_get_contents($logoPath);
        $this->content .= self::FEED;
    }
    
    return $this;
}

Advanced Configuration

Multiple Printers

For multiple printers, you can set up different CUPS queues:

# Set up kitchen printer
lpadmin -p KitchenPrinter -E -v usb://Epson/TM-U220 -m drv:///sample.drv/generic.ppd

# Set up cashier printer  
lpadmin -p CashierPrinter -E -v usb://Epson/TM-T88 -m drv:///sample.drv/generic.ppd

Then you can dynamically select the printer based on the order type:

// In your print logic
$printerName = $order->isTakeaway() ? 'KitchenPrinter' : 'CashierPrinter';

Order Filtering

You can filter the orders to be retrieved by adjusting the OrderRepository class:

// In src/Infra/Shopware/OrderRepository.php

public function findNewNumbers(): array
{
    // Only orders with certain payment methods
    $paymentMethods = ['cash', 'card'];
    
    // Only orders above a certain value
    $minOrderValue = 5.00;
    
    // Only orders for certain delivery types
    $deliveryTypes = ['delivery', 'takeaway'];
    
    return $this->shopwareClient->getOrders(
        $paymentMethods,
        $minOrderValue,
        $deliveryTypes
    );
}

Notifications

You can set up notifications for certain events:

# In config/packages/messenger.yaml

framework:
    messenger:
        routing:
            'Veliu\OrderPrinter\Domain\Event\OrderPrintedEvent': async
            'Veliu\OrderPrinter\Domain\Event\PrintFailedEvent': failed

Then you can create event listeners:

#[AsMessageHandler]
final class OrderPrintedNotificationHandler
{
    public function __construct(
        private MailerInterface $mailer,
        private string $adminEmail
    ) {}
    
    public function __invoke(OrderPrintedEvent $event): void
    {
        $email = (new Email())
            ->from('noreply@shopbite.de')
            ->to($this->adminEmail)
            ->subject('Order printed: ' . $event->orderNumber)
            ->text('The order ' . $event->orderNumber . ' has been successfully printed.');
        
        $this->mailer->send($email);
    }
}

Performance Optimization

Caching

Enable caching for frequently retrieved data:

# In config/packages/cache.yaml

framework:
    cache:
        app: cache.adapter.filesystem
        default_redis_provider: 'redis://localhost'
        pools:
            shopware.cache:
                adapter: cache.adapter.redis
                default_lifetime: 3600

Batch Processing

For high order volumes, you can enable batch processing:

# Batch Configuration
BATCH_SIZE=10
BATCH_INTERVAL=30

Load Distribution

For systems with high throughput, you can set up multiple workers:

# Start multiple workers
bin/console messenger:consume async --limit=10 --time-limit=3600 &
bin/console messenger:consume async --limit=10 --time-limit=3600 &
bin/console messenger:consume async --limit=10 --time-limit=3600 &

Security

API Security

  • Enforce HTTPS: Ensure your Shopware instance uses HTTPS
  • IP Restriction: Restrict API access to specific IP addresses
  • Rate Limiting: Configure appropriate rate limits

Printer Security

  • Printer IP Restriction: Restrict access to the printer
  • Printer Password: Set up a printer password
  • Encryption: Use encrypted connections for network printers

Maintenance Configuration

Log Rotation

Set up log rotation to save disk space:

# Logrotate Configuration (/etc/logrotate.d/order-printer)
/var/log/order-printer-*.log {
    daily
    rotate 7
    compress
    delaycompress
    missingok
    notifempty
    create 644 www-data www-data
}

Data Cleanup

Set up regular data cleanup:

# Cron job for data cleanup (daily at 3 AM)
0 3 * * * /path/to/project/bin/console order-printer:cleanup --days=30

Next Steps