0

In the "New Shipment" email templates, I am trying to add additional content to display the items that did not get shipped, such as in the case of a surprise out-of-stock item.

app/design/frontend/Vendor/theme/Magento_Sales/layout/sales_email_order_pending_shipment_items.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
    <block class="Magento\Sales\Block\Order\Email\Items" name="pending.items" template="Magento_Sales::email/shipment/pending_items.phtml"/>
</body>

app/design/frontend/Vendor/theme/Magento_Sales/templates/email/shipment/pending_items.phtml

<?php
/** @var $block \Magento\Sales\Block\Order\Email\Items */
?>
<?php $_order = $block->getOrder() ?>
<?php if ($_order) : ?>
<?php $_items = $_order->getAllVisibleItems(); ?>
<?php
foreach ($_items as $item) {
    if ($item->getQtyOrdered() > $item->getQtyShipped()) {
        $pendingItems[] = [
            'name' => $item->getName(),
            'sku' => $item->getSku(),
            'qty_remaining' => $item->getQtyOrdered() - $item->getQtyShipped(),
        ];
    }
}
?>
<?php if (!empty($pendingItems)): ?>
    <h2>Items Yet to be Shipped</h2>
    <ul>
        <?php foreach ($pendingItems as $item): ?>
            <li><?php echo $item['name']; ?> (<?php echo $item['sku']; ?>) - Remaining Qty: <?php echo $item['qty_remaining']; ?></li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>
<?php endif; ?>

I have added my new layout handle to the email template in Magento.

updated email template

When I get my test email, after shipping only one of the items in my order, the items that did not ship do not display.

test email

What am I missing to get this to work?

1 Answer 1

0

It looks like I had the "order" value wrong in the layout code in the email template in Magento wrong.

I had:

{{layout handle="sales_email_order_pending_shipment_items" order=$order}}

Updated to:

{{layout handle="sales_email_order_pending_shipment_items" order_id=$order_id}}

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.