Unable to create different documents

Created on 22 September 2023, over 1 year ago
Updated 23 September 2023, over 1 year ago

Problem/Motivation

Hi.

After installing the mudule I'm unable to use different templates for creating different documents. I used the instructions in de documentation:

"
The base theme for default order documents is commerce_order_document. For specific default order documents, use the document ID (machine name) for the template name:

commerce-order-document--DOCUMENT-ID.html.twig
commerce-order-document--DOCUMENT-ID--entity-print.html.twig (for PDF version of document)
"

Steps to reproduce

I created a new template 'commerce-order-document--factura.html.twig' and in Documents settings I created a document with machine name 'factura'. However I can only select between extention 'Default' and 'Receipt'. For 'Default' the standard commerce-order-document.html.twig tamplate is used and for 'Receipt' the receipt template form the Commerce core is used.

How can I select the custom 'commerce-order-document--factura.html.twig' template and use it for a document? What am I missing?

My aim is to use the commerce-order-document module for creating packing slips and invoices (I'll add additional custom fields for invoice number and invoice date)

Proposed resolution

It would be nice if differente templates can be selected in the Extention select box when creating a document (now only 'Default' and 'Receipt')

Thanks very much!

πŸ’¬ Support request
Status

Closed: works as designed

Version

1.0

Component

Documentation

Created by

πŸ‡ͺπŸ‡ΈSpain henkpotman

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @henkpotman
  • πŸ‡ΊπŸ‡ΈUnited States lisastreeter

    Hi! I'm not sure why you're having trouble--it sounds like you want to do precisely what this module is designed to do.

    If you select "Default" as the plugin, set the machine name for your document type to "factura", and create template 'commerce-order-document--factura.html.twig' in your custom theme, that theme should be used for your "Factura" documents. You don't need to "select" anything in the configuration. The code is written in a way that first Drupal will attempt to find a template named 'commerce-order-document--factura.html.twig' and then only use the standard 'commerce-order-document.html.twig' template if the document-type-specific template can't be found. Maybe try rebuilding caches?

    I'm doing it right now for a order document type named "proforma." Here are screenshots:

  • πŸ‡ΊπŸ‡ΈUnited States lisastreeter

    One more comment, regarding your solution in the "Proposed Resolution." It is possible to provide more options than just Default and Receipt. However, to do so you need to write custom code to implement a new Order Document plugin. In one of my screenshots above, there's an "Invoice" option. That appears because I have custom plugin code that starts like this:

    <?php
    
    namespace Drupal\my_module\Plugin\Commerce\OrderDocument;
    
    use Drupal\commerce_order\Entity\OrderInterface;
    use Drupal\commerce_order_document\Plugin\Commerce\OrderDocument\OrderDocumentBase;
    use Drupal\commerce_order_document\Plugin\Commerce\OrderDocument\OrderDocumentInterface;
    
    /**
     * Provides the Invoice order document.
     *
     * @CommerceOrderDocument(
     *   id = "my_invoice",
     *   label = "Invoice",
     *   display_label = "Invoice",
     * )
     */
    class MyInvoice extends OrderDocumentBase implements OrderDocumentInterface {

    And then in my buildOrderDocument I explicitly set the theme (template) that should be used to generate documents. That template file can have any name I want. It's not limited to the commerce-order-document--DOCUMENT-ID.html.twig format. For example, the template for this plugin could be named my-order-invoice.html.twig or anything else I want.

  • πŸ‡ͺπŸ‡ΈSpain henkpotman

    Thanks very much for your extensive comments and information!

    I found my mistake. I placed the custom templates in the commerce_order_document/templates folder. According to your indications it should be places in the theme templates folder. I did and now it's working fine!

    I think your module is great, just what many people will need to make any type of document (packing slips, proforma invoice, invoice..).

    You made my day! Again, thanks a lot for your time and help!

  • Status changed to Closed: works as designed over 1 year ago
Production build 0.71.5 2024