Jump to content

[Résolu] Facture : Notice: Trying to access array offset on value of type bool


Addicte

Recommended Posts

Bonjour,

 

j'ai une erreur  très récente lorsque je veux voir les nouvelles factures :

Notice: Trying to access array offset on value of type bool

Ligne 19 du fichier override/classes/order/OrderInvoice.php

  $invoiceNumber = DocumentReferences::getReference($this->id, 'invoice')['reference'];

    * date: 2024-09-26 11:35:01

    * version: 1.7.0

    */

    public function getInvoiceNumberFormatted($id_lang, $id_shop = null, $oldFormat = false)

    {

        $invoiceNumber = DocumentReferences::getReference($this->id, 'invoice')['reference'];

        if ($oldFormat || $invoiceNumber == NULL) {

            return parent::getInvoiceNumberFormatted($id_lang, $id_shop);

        }

        return $invoiceNumber;

    }

 

Si quelqu'un a une solution je prends ^^

 

Edited by Addicte (see edit history)
Link to comment
Share on other sites

Ben vérifier que DocumentReferences::getReference($this->id, 'invoice') n'est pas null avant de lui demander la reference

$invoiceNumber = NULL;

if($document = DocumentReferences::getReference($this->id, 'invoice')) {
    $invoiceNumber = $document['reference'];
}
if ($oldFormat || $invoiceNumber == NULL) {
   return parent::getInvoiceNumberFormatted($id_lang, $id_shop);
} 

return $invoiceNumber;

 

Link to comment
Share on other sites

Merci, je cherchais justement comment faire ^^
Pour la solution :
 

public function getInvoiceNumberFormatted($id_lang, $id_shop = null, $oldFormat = false)
{
    $referenceData = DocumentReferences::getReference($this->id, 'invoice');

    if (!is_array($referenceData) || !isset($referenceData['reference']) || $oldFormat || $referenceData['reference'] == null) {
        return parent::getInvoiceNumberFormatted($id_lang, $id_shop);
    }

    return $referenceData['reference'];
}

 

ou celle de Eolia :

 

$invoiceNumber = NULL;

if($document = DocumentReferences::getReference($this->id, 'invoice')) {
    $invoiceNumber = $document['reference'];
}
if ($oldFormat || $invoiceNumber == NULL) {
   return parent::getInvoiceNumberFormatted($id_lang, $id_shop);
} 

return $invoiceNumber;

 

Link to comment
Share on other sites

  • Addicte changed the title to [Résolu] Facture : Notice: Trying to access array offset on value of type bool

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...