( paper_formatting.xsl ) <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="UTF-8" indent="yes"/> <xsl:template match="/"> <html> <head> <title><xsl:value-of select="paper_export/document_metadata/title"/></title> <style> @page size: <xsl:value-of select="paper_export/page_settings/paper_size"/> <xsl:value-of select="paper_export/page_settings/orientation"/>; margin: <xsl:value-of select="paper_export/page_settings/margin_top"/> <xsl:value-of select="paper_export/page_settings/margin_right"/> <xsl:value-of select="paper_export/page_settings/margin_bottom"/> <xsl:value-of select="paper_export/page_settings/margin_left"/>; body font-family: Arial, Helvetica, sans-serif; font-size: 12px; line-height: 1.4; color: #333; .header text-align: center; margin-bottom: 30px; padding-bottom: 20px; border-bottom: 2px solid #333; .company-name font-size: 24px; font-weight: bold; margin-bottom: 10px; .company-details font-size: 11px; color: #666; .product-table width: 100%; border-collapse: collapse; margin-bottom: 30px; .product-table th background-color: #f0f0f0; border: 1px solid #ddd; padding: 10px; text-align: left; font-weight: bold; .product-table td border: 1px solid #ddd; padding: 8px; vertical-align: top; .footer position: fixed; bottom: 0; width: 100%; text-align: center; font-size: 10px; color: #666; border-top: 1px solid #ddd; padding-top: 10px; .page-break page-break-before: always; .summary margin-top: 30px; padding: 15px; background-color: #f9f9f9; border: 1px solid #ddd; </style> </head> <body> <div class="header"> <div class="company-name"> <xsl:value-of select="paper_export/document_metadata/company"/> </div> <div class="company-details"> <xsl:value-of select="paper_export/document_metadata/address"/><br/> Tel: <xsl:value-of select="paper_export/document_metadata/phone"/> | Email: <xsl:value-of select="paper_export/document_metadata/email"/> </div> <h2>Product Catalog Export</h2> <div>Generated: <xsl:value-of select="paper_export/@generated"/></div> </div> <table class="product-table"> <thead> <tr> <th>ID</th> <th>Product Name</th> <th>Model</th> <th>Price</th> <th>Stock</th> </tr> </thead> <tbody> <xsl:for-each select="paper_export/products/product"> <tr> <td><xsl:value-of select="product_id"/></td> <td> <strong><xsl:value-of select="name"/></strong> <xsl:if test="short_description != ''"> <br/><small><xsl:value-of select="short_description"/></small> </xsl:if> </td> <td><xsl:value-of select="model"/></td> <td><xsl:value-of select="pricing/price"/></td> <td><xsl:value-of select="inventory/quantity"/></td> </tr> </xsl:for-each> </tbody> </table> <div class="summary"> <strong>Summary Report</strong><br/> Total Products: <xsl:value-of select="paper_export/summary/total_products"/><br/> Export Date: <xsl:value-of select="paper_export/summary/export_date"/><br/> Generated By: <xsl:value-of select="paper_export/document_metadata/generated_by"/> </div> <div class="footer"> Page <xsl:value-of select="position()"/> of <xsl:value-of select="last()"/> | Generated from OpenCart System </div> </body> </html> </xsl:template> </xsl:stylesheet> 3. Front-end Button/Link (in template) <a href="<?php echo $this->url->link('extension/feed/paper_export', 'format=A4&orientation=portrait&limit=100', true); ?>" class="btn btn-primary" target="_blank"> <i class="fa fa-file-pdf-o"></i> Export to Paper Format </a> 4. System Settings (Admin → Extensions → Feeds) Add database entry in oc_extension table:
1. XML Export Controller ( catalog/controller/extension/feed/paper_export.php ) <?php class ControllerExtensionFeedPaperExport extends Controller public function index() // Check if user is logged in if (!$this->customer->isLogged()) $this->response->redirect($this->url->link('account/login', '', true)); $this->load->model('catalog/product'); $this->load->model('tool/image'); // Get parameters $paper_format = $this->request->get('format') ?? 'A4'; $orientation = $this->request->get('orientation') ?? 'portrait'; $product_limit = $this->request->get('limit') ?? 50; // Fetch products $filter_data = array( 'start' => 0, 'limit' => $product_limit ); $products = $this->model_catalog_product->getProducts($filter_data); // Build XML structure $xml = new DOMDocument('1.0', 'UTF-8'); $xml->formatOutput = true; // Root element $root = $xml->createElement('paper_export'); $root->setAttribute('generated', date('Y-m-d H:i:s')); $root->setAttribute('format', $paper_format); $root->setAttribute('orientation', $orientation); $xml->appendChild($root); // Document metadata $metadata = $xml->createElement('document_metadata'); $metadata->appendChild($xml->createElement('title', $this->config->get('config_name') . ' - Product Export')); $metadata->appendChild($xml->createElement('company', $this->config->get('config_name'))); $metadata->appendChild($xml->createElement('address', $this->config->get('config_address'))); $metadata->appendChild($xml->createElement('phone', $this->config->get('config_telephone'))); $metadata->appendChild($xml->createElement('email', $this->config->get('config_email'))); $metadata->appendChild($xml->createElement('generated_by', $this->customer->getFirstName() . ' ' . $this->customer->getLastName())); $root->appendChild($metadata); // Page settings $page_settings = $xml->createElement('page_settings'); $page_settings->appendChild($xml->createElement('paper_size', $paper_format)); $page_settings->appendChild($xml->createElement('orientation', $orientation)); $page_settings->appendChild($xml->createElement('margin_top', '20mm')); $page_settings->appendChild($xml->createElement('margin_bottom', '20mm')); $page_settings->appendChild($xml->createElement('margin_left', '15mm')); $page_settings->appendChild($xml->createElement('margin_right', '15mm')); $root->appendChild($page_settings); // Products list $products_node = $xml->createElement('products'); $products_node->setAttribute('count', count($products)); foreach ($products as $product) $product_node = $xml->createElement('product'); // Basic info $product_node->appendChild($xml->createElement('product_id', $product['product_id'])); $product_node->appendChild($xml->createElement('name', htmlspecialchars($product['name']))); $product_node->appendChild($xml->createElement('model', htmlspecialchars($product['model']))); $product_node->appendChild($xml->createElement('sku', htmlspecialchars($product['sku']))); // Prices $prices = $xml->createElement('pricing'); $prices->appendChild($xml->createElement('price', $this->currency->format($product['price'], $this->session->data['currency']))); $prices->appendChild($xml->createElement('special', $product['special'] ? $this->currency->format($product['special'], $this->session->data['currency']) : '')); $prices->appendChild($xml->createElement('tax', $product['tax_class_id'])); $product_node->appendChild($prices); // Stock info $stock = $xml->createElement('inventory'); $stock->appendChild($xml->createElement('quantity', $product['quantity'])); $stock->appendChild($xml->createElement('stock_status', htmlspecialchars($product['stock_status']))); $stock->appendChild($xml->createElement('in_stock', $product['quantity'] > 0 ? 'yes' : 'no')); $product_node->appendChild($stock); // Dimensions and weight $measurements = $xml->createElement('measurements'); $measurements->appendChild($xml->createElement('length', $product['length'])); $measurements->appendChild($xml->createElement('width', $product['width'])); $measurements->appendChild($xml->createElement('height', $product['height'])); $measurements->appendChild($xml->createElement('weight', $product['weight'])); $measurements->appendChild($xml->createElement('length_class', $product['length_class_id'])); $measurements->appendChild($xml->createElement('weight_class', $product['weight_class_id'])); $product_node->appendChild($measurements); // Description (limited for paper) $desc = strip_tags(html_entity_decode($product['description'], ENT_QUOTES, 'UTF-8')); $desc_short = strlen($desc) > 500 ? substr($desc, 0, 500) . '...' : $desc; $product_node->appendChild($xml->createElement('short_description', htmlspecialchars($desc_short))); // Images if ($product['image']) $image_node = $xml->createElement('images'); $image_node->appendChild($xml->createElement('main', HTTP_SERVER . 'image/' . $product['image'])); $product_node->appendChild($image_node); $products_node->appendChild($product_node); $root->appendChild($products_node); // Summary statistics $summary = $xml->createElement('summary'); $summary->appendChild($xml->createElement('total_products', count($products))); $summary->appendChild($xml->createElement('total_pages', ceil(count($products) / 20))); // ~20 products per page $summary->appendChild($xml->createElement('export_date', date('Y-m-d'))); $summary->appendChild($xml->createElement('export_time', date('H:i:s'))); $root->appendChild($summary); // Output XML $this->response->addHeader('Content-Type: application/xml'); $this->response->addHeader('Content-Disposition: attachment; filename="product_export_' . date('Y-m-d') . '.xml"'); $this->response->setOutput($xml->saveXML()); opencart xml export
Be the first to know all exciting news & information about Global Paint Protection Film.