Order_Nr in commerce-invoice.html.twig

Created on 18 March 2021, over 3 years ago
Updated 10 May 2023, about 1 year ago

Problem/Motivation

In Germany we need the order_number displayed on the Invoice and Credit memo.
So we need Order_Nr in commerce-invoice.html.twig
like

i tried to extract Order Nr. in Invoice.php like

/**
* {@inheritdoc}
*/
public function getOrderNumber() {
return $this->get('order_number')->value;
}

where can i find the correct object?

✨ Feature request
Status

Active

Version

2.0

Component

Code

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India rkchallengers

    Added the following lines in commer_invoice.module worked to me. Thanks @max

    function template_preprocess_commerce_invoice(array &$variables) {
    /** @var Drupal\commerce_invoice\Entity\InvoiceInterface $invoice */
    $invoice = $variables['elements']['#commerce_invoice'];
    $token = \Drupal::token();
    $invoice_type_data = $invoice->getData('invoice_type', []);
    $invoice_type = InvoiceType::create($invoice_type_data);
    $invoice_id = $variables['elements']['#commerce_invoice']->id();
    $order_id = \Drupal\commerce_invoice\Entity\Invoice::load($invoice_id)->getOrders()[0]->id();
    $order_number = \Drupal\commerce_invoice\Entity\Invoice::load($invoice_id)->getOrders()[0]->getOrderNumber();
    $variables['order_id'] = $order_id;
    $variables['order_number'] = $order_number;

Production build 0.69.0 2024