-
Notifications
You must be signed in to change notification settings - Fork 0
feat: [E-Commerce] Integration: PDF invoice generation #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # PDF Invoice Generation | ||
|
|
||
| This module provides PDF invoice generation functionality for the e-commerce system, allowing orders to be converted to professional-looking PDF invoices. | ||
|
|
||
| ## Components | ||
|
|
||
| ### PDFInvoiceGenerator Class | ||
| The main invoice generation engine that: | ||
| - Creates professional invoice layouts in HTML | ||
| - Converts HTML to PDF using DomPDF (if available) or falls back to HTML | ||
| - Includes all relevant order information: | ||
| - Company details | ||
| - Customer information | ||
| - Order details and items | ||
| - Shipping information | ||
| - Detailed totals (subtotal, tax, shipping, discounts, grand total) | ||
| - Invoice number and dates | ||
|
|
||
| ### Order Model Integration | ||
| The Order model has been enhanced with: | ||
| - `generateInvoice()` method to create PDF invoices | ||
| - `getInvoiceLink()` method to retrieve download links | ||
| - `getInvoiceFilename()` method to get appropriate filenames | ||
|
|
||
| ### Invoice Controller | ||
| A dedicated controller to handle invoice downloads at `/order/invoice/{order-id}` | ||
|
|
||
| ## Features | ||
|
|
||
| ### Professional Layout | ||
| - Clean, business-appropriate design | ||
| - Organized sections for all invoice information | ||
| - Proper alignment and spacing | ||
| - Print-ready formatting | ||
|
|
||
| ### Complete Information | ||
| - Company header with contact information | ||
| - Customer billing and shipping details | ||
| - Detailed order items with quantities and prices | ||
| - Complete breakdown of costs (subtotal, tax, shipping, discounts) | ||
| - Grand total prominently displayed | ||
|
|
||
| ### Flexible Output Modes | ||
| - Download PDF directly | ||
| - View PDF inline in browser | ||
| - Generate PDF string for custom handling | ||
|
|
||
| ### Fallback Mechanism | ||
| - Uses DomPDF if available for proper PDF generation | ||
| - Falls back to HTML with print suggestions if library missing | ||
|
|
||
| ## Usage | ||
|
|
||
| ### In Templates | ||
| ```ss | ||
| <a href="$InvoiceLink" class="btn btn-primary">Download Invoice</a> | ||
| ``` | ||
|
|
||
| ### In Code | ||
| ```php | ||
| // Generate and download invoice | ||
| $order->generateInvoice('download'); | ||
|
|
||
| // Generate invoice to view inline | ||
| $order->generateInvoice('inline'); | ||
|
|
||
| // Get invoice download link | ||
| $link = $order->getInvoiceLink(); | ||
| ``` | ||
|
|
||
| ### Direct Access | ||
| Invoices can be accessed directly via: | ||
| ``` | ||
| /order/invoice/{order-id} | ||
| ``` | ||
|
|
||
| ## Requirements | ||
|
|
||
| The system works best with the DomPDF library installed: | ||
| ``` | ||
| composer require dompdf/dompdf | ||
| ``` | ||
|
|
||
| If DomPDF is not available, the system will generate HTML that can be printed to PDF. | ||
|
|
||
| ## Configuration | ||
|
|
||
| The system is configured via YAML: | ||
| - Routes for invoice access | ||
| - Default settings for PDF generation | ||
| - Integration with Order model | ||
|
|
||
| ## Integration Points | ||
|
|
||
| The PDF invoice system integrates seamlessly with: | ||
| - The existing Order model | ||
| - The e-commerce workflow | ||
| - The CMS for administrative access | ||
| - Customer-facing pages for download access | ||
|
|
||
| This provides a complete solution for generating professional invoices that meet business requirements while maintaining integration with the existing e-commerce system. |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,31 @@ | ||||||||||
| --- | ||||||||||
| Name: pdf-invoice-config | ||||||||||
| --- | ||||||||||
| # Register the PDF invoice functionality | ||||||||||
|
|
||||||||||
| # Add invoice extension to Order model | ||||||||||
| Order: | ||||||||||
| extensions: | ||||||||||
| - OrderInvoiceExtension | ||||||||||
|
|
||||||||||
| # Configure routes for invoice downloads | ||||||||||
| --- | ||||||||||
| Name: invoice-routes | ||||||||||
| After: | ||||||||||
| - '#coreroutes' | ||||||||||
| - '#modelascontrollerroutes' | ||||||||||
| --- | ||||||||||
| SilverStripe\Control\Director: | ||||||||||
| rules: | ||||||||||
| 'order/invoice//$ID': 'InvoiceController' | ||||||||||
|
|
||||||||||
| # Define required dependencies | ||||||||||
| --- | ||||||||||
| Name: dompdf-defaults | ||||||||||
| --- | ||||||||||
| # Default settings for DomPDF if installed | ||||||||||
| Dompdf\Dompdf: | ||||||||||
| options: | ||||||||||
| default_font: 'Arial' | ||||||||||
| isRemoteEnabled: true | ||||||||||
| isJavascriptEnabled: true | ||||||||||
|
Comment on lines
+30
to
+31
|
||||||||||
| isRemoteEnabled: true | |
| isJavascriptEnabled: true | |
| isRemoteEnabled: false | |
| isJavascriptEnabled: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Config attaches
OrderInvoiceExtensiontoOrder, butOrderalready definesgenerateInvoice(),getInvoiceLink(), andgetInvoiceFilename()directly. This makes the extension redundant (and can cause confusion about which implementation is used). Prefer keeping these methods in one place: either remove the extension/config or remove the methods fromOrderand rely on the extension.