Commit f40e71c1 authored by David Kopecek's avatar David Kopecek Committed by Jonathan Sacksick
Browse files

Issue #3249988 by Dave Kopecek, idebr: Error: Call to a member function toUrl() on null.

parent 0beeaf4b
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -97,18 +97,19 @@ class Invoice extends CommerceContentEntityBase implements InvoiceInterface {
  public function toUrl($rel = 'canonical', array $options = []) {
    // For better UX, the collection URL of invoices that are created for a
    // single order should be the list of invoices for that specific order.
    $invoice_collection_url = NULL;
    if ($rel === 'collection' && count($this->get('orders')) === 1) {
      $order = $this->get('orders')->first()->entity;
      if ($order) {
        if ($this->bundle() === 'default') {
        $invoice_collection_url = $order->toUrl('invoices', $options);
          return $order->toUrl('invoices', $options);
        }
        elseif ($this->bundle() === 'credit_memo') {
        $invoice_collection_url = $order->toUrl('credit-memos', $options);
          return $order->toUrl('credit-memos', $options);
        }
      }
    }

    return $invoice_collection_url ?? parent::toUrl($rel, $options);
    return parent::toUrl($rel, $options);
  }

  /**