How to add custom total row in Invoice PDFAdd item to totals in pdf invoiceAdd Minus Sign in Invoice PDF Totals BlockHow to add custom product attribute in PDF invoice?Change sort order totals in invoice PDFAdd TAX pecentage (%) in PDF invoice summaryAdd Custom Attribute to PDF InvoiceMagento - Add order id to invoice PDFinvoice pdf add imageCustom Invoice PDFHow to remove only Total Tax from invoice pdf?

What is the advantage of carrying a tripod and ND-filters when you could use image stacking instead?

Pronoun introduced before its antecedent

When writing an error prompt, should we end the sentence with a exclamation mark or a dot?

How to decline physical affection from a child whose parents are pressuring them?

How bad would a partial hash leak be, realistically?

Credit card offering 0.5 miles for every cent rounded up. Too good to be true?

Could the Missouri River be running while Lake Michigan was frozen several meters deep?

Will TSA allow me to carry a Continuous Positive Airway Pressure (CPAP) device?

1980s (or earlier) book where people live a long time but they have short memories

What do we gain with higher order logics?

What are they doing to this poor rocket?

Is the capacitor drawn or wired wrongly?

Why is the relationship between frequency and pitch exponential?

Did thousands of women die every year due to illegal abortions before Roe v. Wade?

correct term describing the action of sending a brand-new ship out into its first seafaring trip

Traffic law UK, pedestrians

How to pass a regex when finding a directory path in bash?

In this example, which path would a monster affected by the Dissonant Whispers spell take?

How could a possessed body begin to rot and decay while it is still alive?

Comma Code - Ch. 4 Automate the Boring Stuff

How were concentration and extermination camp guards recruited?

What happened to all the nuclear material being smuggled after the fall of the USSR?

Why is c4 bad when playing the London against a King's Indian?

How much water is needed to create a Katana capable of cutting flesh, bones and wood?



How to add custom total row in Invoice PDF


Add item to totals in pdf invoiceAdd Minus Sign in Invoice PDF Totals BlockHow to add custom product attribute in PDF invoice?Change sort order totals in invoice PDFAdd TAX pecentage (%) in PDF invoice summaryAdd Custom Attribute to PDF InvoiceMagento - Add order id to invoice PDFinvoice pdf add imageCustom Invoice PDFHow to remove only Total Tax from invoice pdf?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I added pdf.xml in custom modules etc folder. But it is not reflecting in Invoice PDF.
I have debug and found that in the class MagentoSalesModelOrderPdfAbstractPdf, on line no. 676 I get custom row values but those row values gets omitted after the statement $total->setOrder($order)->setSource($source);



protected function insertTotals($page, $source)
{
$order = $source->getOrder();
$totals = $this->_getTotalsList();
$lineBlock = ['lines' => [], 'height' => 15];
foreach ($totals as $total) {
echo "<pre>";print_r($total->getData());// I get custom row values here
$total->setOrder($order)->setSource($source);//But those get lost here


This is a protected function so I cannot add plugin also.



EDIT



Pdf.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/pdf_file.xsd">
<totals>
<total name="custfee">
<title translate="true">Custom Fee</title>
<font_size>7</font_size>
<display_zero>true</display_zero>
<sort_order>100</sort_order>
</total>
</totals>
</config>









share|improve this question
























  • Can you share the code of pdf.xml first.

    – Dhiren Vasoya
    Feb 18 '17 at 4:34











  • Please see my edit

    – piyush_systematix
    Feb 18 '17 at 6:33











  • See my answer below.

    – Khoa TruongDinh
    Feb 20 '17 at 14:27

















1















I added pdf.xml in custom modules etc folder. But it is not reflecting in Invoice PDF.
I have debug and found that in the class MagentoSalesModelOrderPdfAbstractPdf, on line no. 676 I get custom row values but those row values gets omitted after the statement $total->setOrder($order)->setSource($source);



protected function insertTotals($page, $source)
{
$order = $source->getOrder();
$totals = $this->_getTotalsList();
$lineBlock = ['lines' => [], 'height' => 15];
foreach ($totals as $total) {
echo "<pre>";print_r($total->getData());// I get custom row values here
$total->setOrder($order)->setSource($source);//But those get lost here


This is a protected function so I cannot add plugin also.



EDIT



Pdf.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/pdf_file.xsd">
<totals>
<total name="custfee">
<title translate="true">Custom Fee</title>
<font_size>7</font_size>
<display_zero>true</display_zero>
<sort_order>100</sort_order>
</total>
</totals>
</config>









share|improve this question
























  • Can you share the code of pdf.xml first.

    – Dhiren Vasoya
    Feb 18 '17 at 4:34











  • Please see my edit

    – piyush_systematix
    Feb 18 '17 at 6:33











  • See my answer below.

    – Khoa TruongDinh
    Feb 20 '17 at 14:27













1












1








1








I added pdf.xml in custom modules etc folder. But it is not reflecting in Invoice PDF.
I have debug and found that in the class MagentoSalesModelOrderPdfAbstractPdf, on line no. 676 I get custom row values but those row values gets omitted after the statement $total->setOrder($order)->setSource($source);



protected function insertTotals($page, $source)
{
$order = $source->getOrder();
$totals = $this->_getTotalsList();
$lineBlock = ['lines' => [], 'height' => 15];
foreach ($totals as $total) {
echo "<pre>";print_r($total->getData());// I get custom row values here
$total->setOrder($order)->setSource($source);//But those get lost here


This is a protected function so I cannot add plugin also.



EDIT



Pdf.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/pdf_file.xsd">
<totals>
<total name="custfee">
<title translate="true">Custom Fee</title>
<font_size>7</font_size>
<display_zero>true</display_zero>
<sort_order>100</sort_order>
</total>
</totals>
</config>









share|improve this question
















I added pdf.xml in custom modules etc folder. But it is not reflecting in Invoice PDF.
I have debug and found that in the class MagentoSalesModelOrderPdfAbstractPdf, on line no. 676 I get custom row values but those row values gets omitted after the statement $total->setOrder($order)->setSource($source);



protected function insertTotals($page, $source)
{
$order = $source->getOrder();
$totals = $this->_getTotalsList();
$lineBlock = ['lines' => [], 'height' => 15];
foreach ($totals as $total) {
echo "<pre>";print_r($total->getData());// I get custom row values here
$total->setOrder($order)->setSource($source);//But those get lost here


This is a protected function so I cannot add plugin also.



EDIT



Pdf.xml



<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Sales:etc/pdf_file.xsd">
<totals>
<total name="custfee">
<title translate="true">Custom Fee</title>
<font_size>7</font_size>
<display_zero>true</display_zero>
<sort_order>100</sort_order>
</total>
</totals>
</config>






magento-2.1 invoice pdf totals






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 18 '17 at 7:43









Khoa TruongDinh

22.5k64491




22.5k64491










asked Feb 18 '17 at 3:51









piyush_systematixpiyush_systematix

96431930




96431930












  • Can you share the code of pdf.xml first.

    – Dhiren Vasoya
    Feb 18 '17 at 4:34











  • Please see my edit

    – piyush_systematix
    Feb 18 '17 at 6:33











  • See my answer below.

    – Khoa TruongDinh
    Feb 20 '17 at 14:27

















  • Can you share the code of pdf.xml first.

    – Dhiren Vasoya
    Feb 18 '17 at 4:34











  • Please see my edit

    – piyush_systematix
    Feb 18 '17 at 6:33











  • See my answer below.

    – Khoa TruongDinh
    Feb 20 '17 at 14:27
















Can you share the code of pdf.xml first.

– Dhiren Vasoya
Feb 18 '17 at 4:34





Can you share the code of pdf.xml first.

– Dhiren Vasoya
Feb 18 '17 at 4:34













Please see my edit

– piyush_systematix
Feb 18 '17 at 6:33





Please see my edit

– piyush_systematix
Feb 18 '17 at 6:33













See my answer below.

– Khoa TruongDinh
Feb 20 '17 at 14:27





See my answer below.

– Khoa TruongDinh
Feb 20 '17 at 14:27










1 Answer
1






active

oldest

votes


















0














After debugging the MagentoSalesModelOrderPdfAbstractPdf::insertTotals():



$total->setOrder($order)->setSource($source);


On this line, Magento simply sets two Objects data to the current total object for using later. You can get the Order and Source (Invoice object - MagentoSalesModelOrderInvoice) data:



$total->getOrder()->getData(); // Order data
$total->getSource()->getData(); // Invoice data
//Get specific data from total object
$total->getSourceField();
$total->getSortOrder();


enter image description here



If we're trying to var dump or print the total object, the page can be crashed because this object is "heavy" after set order and invoice source object.



I think your problem comes $total->canDisplay() or $total->getTotalsForDisplay().



1) MagentoSalesModelOrderPdfTotalDefaultTotal::canDisplay(). This method will check:



  • Amount is not equal to zero.

  • Or, in your pdf.xml config, you have declare <display_zero>true</display_zero>. Set to true if you want to display zero amount.

2) MagentoSalesModelOrderPdfTotalDefaultTotal::getTotalsForDisplay(): Get array of arrays with totals information for displaying in PDF






share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f160586%2fhow-to-add-custom-total-row-in-invoice-pdf%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    After debugging the MagentoSalesModelOrderPdfAbstractPdf::insertTotals():



    $total->setOrder($order)->setSource($source);


    On this line, Magento simply sets two Objects data to the current total object for using later. You can get the Order and Source (Invoice object - MagentoSalesModelOrderInvoice) data:



    $total->getOrder()->getData(); // Order data
    $total->getSource()->getData(); // Invoice data
    //Get specific data from total object
    $total->getSourceField();
    $total->getSortOrder();


    enter image description here



    If we're trying to var dump or print the total object, the page can be crashed because this object is "heavy" after set order and invoice source object.



    I think your problem comes $total->canDisplay() or $total->getTotalsForDisplay().



    1) MagentoSalesModelOrderPdfTotalDefaultTotal::canDisplay(). This method will check:



    • Amount is not equal to zero.

    • Or, in your pdf.xml config, you have declare <display_zero>true</display_zero>. Set to true if you want to display zero amount.

    2) MagentoSalesModelOrderPdfTotalDefaultTotal::getTotalsForDisplay(): Get array of arrays with totals information for displaying in PDF






    share|improve this answer





























      0














      After debugging the MagentoSalesModelOrderPdfAbstractPdf::insertTotals():



      $total->setOrder($order)->setSource($source);


      On this line, Magento simply sets two Objects data to the current total object for using later. You can get the Order and Source (Invoice object - MagentoSalesModelOrderInvoice) data:



      $total->getOrder()->getData(); // Order data
      $total->getSource()->getData(); // Invoice data
      //Get specific data from total object
      $total->getSourceField();
      $total->getSortOrder();


      enter image description here



      If we're trying to var dump or print the total object, the page can be crashed because this object is "heavy" after set order and invoice source object.



      I think your problem comes $total->canDisplay() or $total->getTotalsForDisplay().



      1) MagentoSalesModelOrderPdfTotalDefaultTotal::canDisplay(). This method will check:



      • Amount is not equal to zero.

      • Or, in your pdf.xml config, you have declare <display_zero>true</display_zero>. Set to true if you want to display zero amount.

      2) MagentoSalesModelOrderPdfTotalDefaultTotal::getTotalsForDisplay(): Get array of arrays with totals information for displaying in PDF






      share|improve this answer



























        0












        0








        0







        After debugging the MagentoSalesModelOrderPdfAbstractPdf::insertTotals():



        $total->setOrder($order)->setSource($source);


        On this line, Magento simply sets two Objects data to the current total object for using later. You can get the Order and Source (Invoice object - MagentoSalesModelOrderInvoice) data:



        $total->getOrder()->getData(); // Order data
        $total->getSource()->getData(); // Invoice data
        //Get specific data from total object
        $total->getSourceField();
        $total->getSortOrder();


        enter image description here



        If we're trying to var dump or print the total object, the page can be crashed because this object is "heavy" after set order and invoice source object.



        I think your problem comes $total->canDisplay() or $total->getTotalsForDisplay().



        1) MagentoSalesModelOrderPdfTotalDefaultTotal::canDisplay(). This method will check:



        • Amount is not equal to zero.

        • Or, in your pdf.xml config, you have declare <display_zero>true</display_zero>. Set to true if you want to display zero amount.

        2) MagentoSalesModelOrderPdfTotalDefaultTotal::getTotalsForDisplay(): Get array of arrays with totals information for displaying in PDF






        share|improve this answer















        After debugging the MagentoSalesModelOrderPdfAbstractPdf::insertTotals():



        $total->setOrder($order)->setSource($source);


        On this line, Magento simply sets two Objects data to the current total object for using later. You can get the Order and Source (Invoice object - MagentoSalesModelOrderInvoice) data:



        $total->getOrder()->getData(); // Order data
        $total->getSource()->getData(); // Invoice data
        //Get specific data from total object
        $total->getSourceField();
        $total->getSortOrder();


        enter image description here



        If we're trying to var dump or print the total object, the page can be crashed because this object is "heavy" after set order and invoice source object.



        I think your problem comes $total->canDisplay() or $total->getTotalsForDisplay().



        1) MagentoSalesModelOrderPdfTotalDefaultTotal::canDisplay(). This method will check:



        • Amount is not equal to zero.

        • Or, in your pdf.xml config, you have declare <display_zero>true</display_zero>. Set to true if you want to display zero amount.

        2) MagentoSalesModelOrderPdfTotalDefaultTotal::getTotalsForDisplay(): Get array of arrays with totals information for displaying in PDF







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 18 '17 at 10:01

























        answered Feb 18 '17 at 7:42









        Khoa TruongDinhKhoa TruongDinh

        22.5k64491




        22.5k64491



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f160586%2fhow-to-add-custom-total-row-in-invoice-pdf%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?