5

I created one custom field in sales_order table, field name is mycstfield.

I save my value in that field sucessfully when order is placed.

Now, I want to send that field value in following places.

  1. Order Email (From Admin)

enter image description here

  1. Inoive Email and Invoice Print (PDF)

enter image description here

  1. Shipment Print

enter image description here

  1. Credit Memo Email and Credit Memo Print (PDF)

enter image description here

Can Any one have idea about this, How can I do this.

6
  • what does it means "I want to send that field value in following places."?
    – LucScu
    Commented Jul 24, 2017 at 10:42
  • means I need to send this customer field value in following places. Commented Jul 24, 2017 at 12:04
  • could you explain better what are you meaning as "following places"? do you want a button next send mail and print with your custom field?
    – LucScu
    Commented Jul 24, 2017 at 20:39
  • I am tryting to send my custom field "mycstfield" in the PDF & email which is send to customer while we click on above mension places. Now are you getting my point. Commented Jul 25, 2017 at 3:00
  • Ok, now it's a bit more clear, last question to understand completely: do you know that both email and pdf has a similar template, with information above the product table, product table, totals. In which position of these do you want insert your custom field?
    – LucScu
    Commented Jul 25, 2017 at 6:55

1 Answer 1

4

I give my answer about order email. Other emails and pdf should works with the same logic.

You have to look at \vendor\magento\module-sales\view\frontend\layout\sales_email_order_items.xml

where the block with class Magento\Sales\Block\Order\Email\Items has the template \vendor\magento\module-sales\view\frontend\templates\order\items.phtml

In this template the line <?php echo $block->getChildHtml('order_totals') ?> calls the block with totals (always defined in sales_email_order_items.xml)

...
<block class="Magento\Sales\Block\Order\Totals" name="order_totals" template="order/totals.phtml">
...

This template starts with

<?php foreach ($block->getTotals() as $_code => $_total): ?>

where $block is a Magento\Sales\Block\Order\Totals instance.

Then, to add your custom field to totals, try to write a plugin related to one public method of this class, i think you could choose addTotal() or addTotalBefore(), in this way your custom field will be added to $this->_totals array and it will be printed from the foreach loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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