Hi,
We never end up getting any ideal solution at that time and ended up with
custom function to override the order template. Cannot share whole files
but do check the below code as a pointer on how to get the order items and
product information.
// Get the order items
$items = $order->getAllItems();
$productName = [];
$productOption = [];
// Creating table with items info
$product_grid = '
style="border: solid 1px lightblue;text-align: center;background:
#e4efff;"> Name Qty ';
foreach ($items as $i => $item) {
//$productName[$i] = $item->getData('name').' QTY: '.$item->getData('qty');
//$productName[$i] = json_encode($item); // for debug
$product = $this->_productRepositoryFactory->create()
->getById($item->getProductId());
$img_url = $this->_storeManager->getStore()->getBaseUrl().'
pub/media/catalog/product'.$product->getData('thumbnail');
// get product options
$productOption[$i] = $item->getProduct()->getTypeInstance(true)->
getOrderOptions($item->getProduct());
//$productName[$i] = $item->getData('name');
$productOptionlabel = [];
$productOptionvalue = [];
if ($productOption) {
foreach ($productOption as $k => $option) {
if (isset($option['options'])) {
$productOptionlabel[$k] = $option['options'][0]['label'];
$productOptionvalue[$k] = $option['options'][0]['value'];
}
}
}
$product_grid .= '
';
$product_grid .= ''.$item->getData('name').' SKU: '.$item->getSku();
if (!empty($productOptionvalue)) { $product_grid .= ''; foreach ($productOptionvalue as $option) { $options = explode(',', $option); foreach ($options as $each_option) { $product_grid .= '- ';
$product_grid .= $each_option; $product_grid .= ' '; } } $product_grid .= ' '; }
$product_grid .= ' | ';
$product_grid .= ''.$item->getData('qty').' |
';
$img_url = '';
}
$product_grid .= '
';
// now add this table to email template
I hope this helps.
Thanks,