0

Magento 2.3.2

In my invoice PDF if Shipping & Handling amount is null or 0 it hides that row like this:

enter image description here

But I want to to display it as $0.00 if the price is null like this:

enter image description here

I found this file /vendor/magento/module-sales/Model/Order/Pdf/Total/DefaultTotal.php, in this file there is a function canDisplay() which is responsible for hiding the Title and Amount from Total section in invoice PDF. so I did some changes in function to display Shipping and Handling if it's $0.00:

public function canDisplay()
{   
    $amount = $this->getAmount();

    /* TO DISPLAY SHIPPING & HANDLING IN INVOICE PDF IF ITS $0.00 - PARTAB SAIFUDDIN */
    if(strtolower($this->getTitle()) == "shipping & handling" && $amount == 0){
        return true;
    }

    return $this->getDisplayZero() === 'true' || $amount != 0;
}

and I got the result as I want, but when I override this file it didn't work and I find out that "Shipping & Handling" doesn't exist in echo $this->getTitle(), these are the titles which I got in a file which I override:

Discount
Adjustment Refund
Adjustment Fee

and these are the titles which I got in core file:

Subtotal
Tax
Shipping & Handling
Grand Total

I don't understand why I'm not getting "Shipping & Handling" in my overridden file...

Thank You.

0

So, the issue is resolved, there is a file /vendor/magento/module-tax/Model/Sales/Pdf/Shipping.php, I override this file and add canDisplay() function in it:

public function canDisplay()
{
    $amount = $this->getAmount();
    /* TO DISPLAY SHIPPING & HANDLING IN INVOICE PDF IF ITS $0.00 - PARTAB SAIFUDDIN */
    if(strtolower($this->getTitle()) == "shipping & handling" && $amount == 0){
        return true;
    }
    return $this->getDisplayZero() === 'true' || $amount != 0;
}

and I get result as I want:

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.