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

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form