3

In Magento-2 I generate PDF invoice and successfully edit the layout of PDF. There is one More thing to change the label of Discount

Current Label is Discount(Coupon Code) want change in Discount(Coupon Code -inclusive tax)

I already try many things like (1) change in en_US.csv but it doesn't work with me

Thanks In Advance.

3

You can do it by following method as pdf discount section cannot be managed by csv. If you check the code then you will like below which not supports translations(i18n):

$title = __($this->getTitle());
if ($this->getTitleSourceField()) {
    $label = $title . ' (' . $this->getTitleDescription() . '):';
} else {
    $label = $title . ':';
}

So you need to modify that section.

OR

If you are using single language then do the following:

Override DefaultTotal.php by adding following line to your module's di.xml

<preference for="Magento\Sales\Model\Order\Pdf\Total\DefaultTotal" type="[Vendor]\[Module]\Model\Order\Pdf\Total\DefaultTotal" />

And create DefaultTotal.php under

app/code/[Vendor]/[Module]/Model/Order/Pdf/Total/DefaultTotal.php

and add the below code:

<?php
namespace [Vendor]\[Module]\Model\Order\Pdf\Total;

class DefaultTotal extends \Magento\Sales\Model\Order\Pdf\Total\DefaultTotal
{
    public function getTotalsForDisplay()
    {
        $amount = $this->getOrder()->formatPriceTxt($this->getAmount());
        if ($this->getAmountPrefix()) {
            $amount = $this->getAmountPrefix() . $amount;
        }

        $title = __($this->getTitle());
        if ($this->getTitleSourceField()) {
            if($title == 'Discount'){
                $label = $title . ' (' . $this->getTitleDescription() . ' -inclusive tax):';
            }
            else{
                $label = $title . ' (' . $this->getTitleDescription() . '):';   
            }
        } else {
            $label = $title . ':';
        }

        $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
        $total = ['amount' => $amount, 'label' => $label, 'font_size' => $fontSize];
        return [$total];
    }
}

Hope this helps!

  • Thank You for your time and your answer, it works fine with me..... – Akash Agrawal Jan 3 at 10:02
0

Try adding adding your translation strings to your file theme :

app/design/frontend/vendorname/themename/i18n/en_US.csv

Like this :

"Grand Total","Big Total"

Note : be careful with spaces at the end of some translations

  • it was reflected in only Admin Panel, not in PDF invoice, I also need to change in PDF invoice. – Akash Agrawal Jan 3 at 9:00

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.