I have overwritten the Tax class for IGST calculation customization. It's working fine on my local system. After I uploaded the live server it's not working, I don't know where anything I missed.

For this stuff, I have written below logic.


<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <type name="Magento\Tax\Model\Sales\Pdf\Tax">
        <plugin name="OverWritePdfTax" type="ABCSolutions\IGST\Model\Sales\Pdf\Tax" />



namespace ABCSolutions\IGST\Model\Sales\Pdf;

class Tax extends \Magento\Tax\Model\Sales\Pdf\Tax{

    public function aroundGetTotalsForDisplay(\Magento\Tax\Model\Sales\Pdf\Tax $tax, callable $proceed)
        $totals = [];
        $totals = $proceed();

        $isValidAmount = false;
        $tempTotal =  array();
        $tempETotal = array();
        $tempI = 0;
        $totalCount = count($totals) - 1;
        $tempTaxAmount = 0;
        $tempAmount = 0;

        foreach($totals as $t){
            if($totalCount == $tempI){
                $tempTaxAmount = $t['amount']/2;
                $tempTaxAmount = number_format($tempTaxAmount,2,'.','');
                $tempAmount = number_format($t['amount'],2,'.','');

        foreach($totals as $t){
            if(($t['title'] == "SGST") || ($t['title'] == "CGST")){
                $SAmount = number_format($t['amount'],2,'.','');
                if($tempTaxAmount == $SAmount){
                    $isValidAmount = true;
                    $isValidAmount = false;

            $tempETotal = $totals;
            //Change the totals according to IGST
            $tempTaxAmount = $tempAmount/2;
            foreach($tempETotal as $t){
                    if(($t['title'] == "SGST") || ($t['title'] == "CGST")){

                        $tempTotal[] = array(
                            'amount' => number_format("$tempTaxAmount",2,'.',''),
                            'label' => $t['label'],
                            'font_size' => $t['font_size'],
                            'percent' => number_format($t['percent'],2,'.',''),
                            'title' => $t['title'],
                            'tax_amount' => number_format($tempTaxAmount,2,'.',''),
                            'base_tax_amount' => number_format($tempTaxAmount,2,'.','')
                        if($t['label'] == "Tax:"){
                            $tempTotal[] = array(
                                'amount' => number_format($t['amount'],2,'.',''),
                                'label' => $t['label'],
                                'font_size' => $t['font_size']
           $totals = $tempTotal;
        return $totals;


Here $totals = $proceed(); it's returning the $total value i.e SGST,CGST and Tax in local system.

After successfully working I deployed the live server it's not working. When I debug the code $totals = $proceed(); returning empty Array().

I don't know why it's not working.

Any suggestion on this?


Once you call proceed means you are calling core method. So if you want to apply login on total before it calculated then without calling core procees apply your logic and return total.

Note: Remove $totals = $proceed();

For more guidance you can refer DevDocs

  • Then how can? give an example of code to do this. – Bojjaiah Dec 20 '17 at 11:17
  • copy code of core function and put it in your function! and don't call proceed(), now you can place your logic in between that code. – Ronak Chauhan Dec 20 '17 at 11:21
  • It's returning error Call to undefined method Magento\Tax\Model\ResourceModel\Sales\Order\Tax\Collection::getOrder() at the starting of the method. Can you please suggest me how to do? – Bojjaiah Dec 20 '17 at 11:49
  • Use $tax instead of $this when you call core methods – Ronak Chauhan Dec 20 '17 at 11:50
  • Let me check... – Bojjaiah Dec 20 '17 at 11:53

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.