I am using the Eadesigndev_Pdfgenerator module like other people I've seen asking similar questions but none of the answers help. I have been trying to get this fixed for about 3 weeks and I'm getting nowhere.

I see in the modules' template body is {{layout area="frontend" handle="sales_email_order_invoice_items" invoice=$invoice order=$order}} which renders out the order items and also the shipping but when I export the pdf it looks terrible. I can add styling in the module so I can sort that.

What I need to do is add some extra blank columns to Magento/Sales/view/frontend/templates/email/invoice/items.phtml

Ideally I would like to separate the items and shipping so I can call them both in different parts of my template

For now I have created a module and in <vendor>/<module>/view/frontend/layout/sales_email_order_renderers.xml I have the following

<?xml version="1.0"?>
<page xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Creditmemo Items List" design_abstraction="custom">
        <referenceBlock name="sales.email.order.renderers">
            <block class="Magento\Sales\Block\Order\Email\Items\Order\DefaultOrder" as="default" template="<vendor>_<module>::email/items/order/default.phtml"/>

and in <vendor>/<module>/view/frontend/template/email/items/order/default.phtml I have the following (nothing changed yet)

 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.

// phpcs:disable Magento2.Templates.ThisInTemplate

/** @var $block \Magento\Sales\Block\Order\Email\Items\DefaultItems */

/** @var $_item \Magento\Sales\Model\Order\Item */
$_item = $block->getItem();
$_order = $_item->getOrder();
    <td class="item-info<?= ($block->getItemOptions() ? ' has-extra' : '') ?>">
        <p class="product-name"><?= $block->escapeHtml($_item->getName()) ?></p>
        <p class="sku"><?= $block->escapeHtml(__('SKU')) ?>: <?= $block->escapeHtml($block->getSku($_item)) ?></p>
        <?php if ($block->getItemOptions()) : ?>
            <dl class="item-options">
            <?php foreach ($block->getItemOptions() as $option) : ?>
                <dt><strong><em><?= $block->escapeHtml($option['label']) ?></em></strong></dt>
                    <?= /* @noEscape */  nl2br($block->escapeHtml($option['value'])) ?>
            <?php endforeach; ?>
        <?php endif; ?>
        <?php $addInfoBlock = $block->getProductAdditionalInformationBlock(); ?>
        <?php if ($addInfoBlock) :?>
            <?= $addInfoBlock->setItem($_item)->toHtml() ?>
        <?php endif; ?>
        <?= $block->escapeHtml($_item->getDescription()) ?>
    <td class="item-qty"><?= (float) $_item->getQtyOrdered() ?></td>
    <td class="item-price">
        <?= /* @noEscape */ $block->getItemPrice($_item) ?>
<?php if ($_item->getGiftMessageId()
    && $_giftMessage = $this->helper(\Magento\GiftMessage\Helper\Message::class)
) : ?>
    <td colspan="3" class="item-extra">
        <table class="message-gift">
                    <h3><?= $block->escapeHtml(__('Gift Message')) ?></h3>
                    <strong><?= $block->escapeHtml(__('From:')) ?></strong> <?= $block->escapeHtml($_giftMessage->getSender()) ?>
                    <br /><strong><?= $block->escapeHtml(__('To:')) ?></strong> <?= $block->escapeHtml($_giftMessage->getRecipient()) ?>
                    <br /><strong><?= $block->escapeHtml(__('Message:')) ?></strong>
                    <br /><?= $block->escapeHtml($_giftMessage->getMessage()) ?>
<?php endif; ?>

When I print the invoice, the rest of the invoice prints fine with all my layout however nothing is rendered for the items.

I have also created a test module with my own layout handle just to echo hello (idea taken from another question related to invoice customisation) and that never rendered anything either.

What is the correct way of overriding Magento_Sales so I can call the layout file to render the items and if possible how could I do the same in a separate layout to call just the shipping part so I can render that elsewhere in my invoice.

Any help or advice appreciated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.