Product Image in invoice email template Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?how to display product image in sales/order/view/ pageMagento 2 product image in new order emailHow can I get product list with its detail in rest API I'm on magento2Area code not setProduct Image does not load on product pageModel class not found in …/magento/framework/ObjectManager/Factory/AbstractFactory.php:93Magento 2: Products images are not showing on category pageM2 - disappearing image after(Solved) Magento 2, Add product image in all transaction emails(shipment, invoice, credit memo)Magento 2 get custom attribute of a single product inside a pluginGetting Errors after MySQL database importMsrpPriceCalculator Exception
When speaking, how do you change your mind mid-sentence?
Is Vivien of the Wilds + Wilderness Reclamation a competitive combo?
enable https on private network
Does using the Inspiration rules for character defects encourage My Guy Syndrome?
When does Bran Stark remember Jamie pushing him?
Indexes with the same object_id but different names
Can I take recommendation from someone I met at a conference?
How can I wire a 9-position switch so that each position turns on one more LED than the one before?
Is it accepted to use working hours to read general interest books?
Lights are flickering on and off after accidentally bumping into light switch
If gravity precedes the formation of a solar system, where did the mass come from that caused the gravity?
Why do C and C++ allow the expression (int) + 4*5?
Why aren't these two solutions equivalent? Combinatorics problem
FME Console for testing
Why do people think Winterfell crypts is the safest place for women, children & old people?
What is the definining line between a helicopter and a drone a person can ride in?
Is "ein Herz wie das meine" an antiquated or colloquial use of the possesive pronoun?
How can I delete rows in the text?
What's the connection between Mr. Nancy and fried chicken?
Output the slug and name of a CPT single post taxonomy term
Determinant of a matrix with 2 equal rows
How to ask rejected full-time candidates to apply to teach individual courses?
Can this water damage be explained by lack of gutters and grading issues?
How was Lagrange appointed professor of mathematics so early?
Product Image in invoice email template
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?how to display product image in sales/order/view/ pageMagento 2 product image in new order emailHow can I get product list with its detail in rest API I'm on magento2Area code not setProduct Image does not load on product pageModel class not found in …/magento/framework/ObjectManager/Factory/AbstractFactory.php:93Magento 2: Products images are not showing on category pageM2 - disappearing image after(Solved) Magento 2, Add product image in all transaction emails(shipment, invoice, credit memo)Magento 2 get custom attribute of a single product inside a pluginGetting Errors after MySQL database importMsrpPriceCalculator Exception
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to get product images for invoice email template. I used below code. But I am only getting Magento placeholder image in email template.
<td>
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_id = $_item->getOrderItem()->getProduct();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);
$_imagehelper = $objectManager->get('MagentoCatalogHelperImage');
$image_url = $_imagehelper->init($product, 'cart_page_product_thumbnail')->getUrl();
?>
<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
</td>
magento2 placeholder-image sales-invoice
add a comment |
I am trying to get product images for invoice email template. I used below code. But I am only getting Magento placeholder image in email template.
<td>
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_id = $_item->getOrderItem()->getProduct();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);
$_imagehelper = $objectManager->get('MagentoCatalogHelperImage');
$image_url = $_imagehelper->init($product, 'cart_page_product_thumbnail')->getUrl();
?>
<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
</td>
magento2 placeholder-image sales-invoice
you can't use PHP in email templates
– Philipp Sander
Mar 21 at 7:13
i did not use in my email template directly, i added this code in my file "Magento_Sales/templates/email/items/shipment/default.phtml"
– mohana
Mar 21 at 7:54
Do you mean the order email?
– Dava Gordon
Apr 12 at 10:57
Try the below answer and keep post your complete phtml
– Prathap Gunasekaran
Apr 13 at 3:24
add a comment |
I am trying to get product images for invoice email template. I used below code. But I am only getting Magento placeholder image in email template.
<td>
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_id = $_item->getOrderItem()->getProduct();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);
$_imagehelper = $objectManager->get('MagentoCatalogHelperImage');
$image_url = $_imagehelper->init($product, 'cart_page_product_thumbnail')->getUrl();
?>
<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
</td>
magento2 placeholder-image sales-invoice
I am trying to get product images for invoice email template. I used below code. But I am only getting Magento placeholder image in email template.
<td>
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_id = $_item->getOrderItem()->getProduct();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);
$_imagehelper = $objectManager->get('MagentoCatalogHelperImage');
$image_url = $_imagehelper->init($product, 'cart_page_product_thumbnail')->getUrl();
?>
<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
</td>
magento2 placeholder-image sales-invoice
magento2 placeholder-image sales-invoice
edited Apr 12 at 10:24
Jaimin Sutariya
9,47122055
9,47122055
asked Mar 21 at 6:20
mohanamohana
8214
8214
you can't use PHP in email templates
– Philipp Sander
Mar 21 at 7:13
i did not use in my email template directly, i added this code in my file "Magento_Sales/templates/email/items/shipment/default.phtml"
– mohana
Mar 21 at 7:54
Do you mean the order email?
– Dava Gordon
Apr 12 at 10:57
Try the below answer and keep post your complete phtml
– Prathap Gunasekaran
Apr 13 at 3:24
add a comment |
you can't use PHP in email templates
– Philipp Sander
Mar 21 at 7:13
i did not use in my email template directly, i added this code in my file "Magento_Sales/templates/email/items/shipment/default.phtml"
– mohana
Mar 21 at 7:54
Do you mean the order email?
– Dava Gordon
Apr 12 at 10:57
Try the below answer and keep post your complete phtml
– Prathap Gunasekaran
Apr 13 at 3:24
you can't use PHP in email templates
– Philipp Sander
Mar 21 at 7:13
you can't use PHP in email templates
– Philipp Sander
Mar 21 at 7:13
i did not use in my email template directly, i added this code in my file "Magento_Sales/templates/email/items/shipment/default.phtml"
– mohana
Mar 21 at 7:54
i did not use in my email template directly, i added this code in my file "Magento_Sales/templates/email/items/shipment/default.phtml"
– mohana
Mar 21 at 7:54
Do you mean the order email?
– Dava Gordon
Apr 12 at 10:57
Do you mean the order email?
– Dava Gordon
Apr 12 at 10:57
Try the below answer and keep post your complete phtml
– Prathap Gunasekaran
Apr 13 at 3:24
Try the below answer and keep post your complete phtml
– Prathap Gunasekaran
Apr 13 at 3:24
add a comment |
4 Answers
4
active
oldest
votes
I found the solution but it's getting parent thumbnail image, i like to get if product has selected in swatch option, that swatch option need to display.
example: if i select red colour, red colour swatch image need to display.
$productId = $_item->getProductId();
$objectManagerHere = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);
$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$imageHelper = $_objectManager->get('MagentoCatalogHelperImage');
$image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize(80, 80)->getUrl();
<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
add a comment |
I have override DefaultInvoice
class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice
public function draw()
$order = $this->getOrder();
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$lines = [];
// draw Product image
$productImage = $this->getProductImage($item, $page);
// draw Product name
$lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
$lines[0][] = array(
'text' => $productImage,
'is_image' => 1,
'feed' => 200
);
// draw SKU
$lines[0][] = [
'text' => $this->string->split($this->getSku($item), 17),
'feed' => 370,
'align' => 'right',
];
// draw QTY
$lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];
// draw item Prices
$i = 0;
$prices = $this->getItemPricesForDisplay();
$feedPrice = 425;
$feedSubtotal = $feedPrice + 140;
foreach ($prices as $priceData)
if (isset($priceData['label']))
// draw Price label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
// draw Subtotal label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
$i++;
// draw Price
$lines[$i][] = [
'text' => $priceData['price'],
'feed' => $feedPrice,
'font' => 'bold',
'align' => 'right',
];
// draw Subtotal
$lines[$i][] = [
'text' => $priceData['subtotal'],
'feed' => $feedSubtotal,
'font' => 'bold',
'align' => 'right',
];
$i++;
// draw Tax
$lines[0][] = [
'text' => $order->formatPriceTxt($item->getTaxAmount()),
'feed' => 515,
'font' => 'bold',
'align' => 'right',
];
// custom options
$options = $this->getItemOptions();
if ($options)
foreach ($options as $option)
// draw options label
$lines[][] = [
'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
'font' => 'italic',
'feed' => 35,
];
if ($option['value'])
if (isset($option['print_value']))
$printValue = $option['print_value'];
else
$printValue = $this->filterManager->stripTags($option['value']);
$values = explode(', ', $printValue);
foreach ($values as $value)
$lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
$lineBlock = ['lines' => $lines, 'height' => 20];
$page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);
$this->setPage($page);
/*
* Return Value of custom attribute
* */
private function getProductImage($item, &$page)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productId = $item->getOrderItem()->getProductId();
$image = $objectManager->get('MagentoCatalogModelProduct')->load($productId);
if (!is_null($image))
try
$imagePath = '/catalog/product/'.$image->getSmallImage();
$filesystem = $objectManager->get('MagentoFrameworkFilesystem');
$media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
if ($media_dir->isFile($imagePath))
return $media_dir->getAbsolutePath($imagePath);
else
return null;
catch (Exception $e)
return false;
Which returns me PDF like this. (working on Image rotation :) )
UPDATED
For variant based product - based on configure product's attribute
selection
class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice
public function draw()
$order = $this->getOrder();
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$lines = [];
// draw Product image
$productImage = $this->getProductImage($item, $page);
// draw Product name
$lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
$lines[0][] = array(
'text' => $productImage,
'is_image' => 1,
'feed' => 200
);
// draw SKU
$lines[0][] = [
'text' => $this->string->split($this->getSku($item), 17),
'feed' => 370,
'align' => 'right',
];
// draw QTY
$lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];
// draw item Prices
$i = 0;
$prices = $this->getItemPricesForDisplay();
$feedPrice = 425;
$feedSubtotal = $feedPrice + 140;
foreach ($prices as $priceData)
if (isset($priceData['label']))
// draw Price label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
// draw Subtotal label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
$i++;
// draw Price
$lines[$i][] = [
'text' => $priceData['price'],
'feed' => $feedPrice,
'font' => 'bold',
'align' => 'right',
];
// draw Subtotal
$lines[$i][] = [
'text' => $priceData['subtotal'],
'feed' => $feedSubtotal,
'font' => 'bold',
'align' => 'right',
];
$i++;
// draw Tax
$lines[0][] = [
'text' => $order->formatPriceTxt($item->getTaxAmount()),
'feed' => 515,
'font' => 'bold',
'align' => 'right',
];
// custom options
$options = $this->getItemOptions();
if ($options)
foreach ($options as $option)
// draw options label
$lines[][] = [
'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
'font' => 'italic',
'feed' => 35,
];
if ($option['value'])
if (isset($option['print_value']))
$printValue = $option['print_value'];
else
$printValue = $this->filterManager->stripTags($option['value']);
$values = explode(', ', $printValue);
foreach ($values as $value)
$lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
$lineBlock = ['lines' => $lines, 'height' => 20];
$page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);
$this->setPage($page);
/*
* Return Value of custom attribute
* */
private function getProductImage($item, &$page)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productId = $item->getOrderItem()->getProductId();
$data = $objectManager->get('MagentoCatalogModelProductRepository')->get($item->getSku());
$image = $data->getImage();
if (!is_null($image))
try
$imagePath = '/catalog/product/'.$image;
$filesystem = $objectManager->get('MagentoFrameworkFilesystem');
$media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
if ($media_dir->isFile($imagePath))
return $media_dir->getAbsolutePath($imagePath);
else
return null;
catch (Exception $e)
return false;
Here's simple product's image in Invoice based of variant selection of
configure product.
More References
Reference 1 , Reference 2 , Reference 3
add a comment |
You can replace following line in your code
$product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);
With following line
$product = $objectManagerHere->get('MagentoCatalogModelProductRepository')->get($_item->getSku());
With this, you can get appropriate simple product of configurable product.
add a comment |
I think you should try with cart_page_product_thumbnail
instead of product_thumbnail_image
in your get product image code.
Your code should be like this.
$image_url = $imageHelper->init($product, 'cart_page_product_thumbnail')->setImageFile($product->getFile())->resize(80, 80)->getUrl();
I have used the above code to display product image in the Email template and it is working fine with configurable products. and I think it also works for the invoice email template.
I have also seen so many users use cart_page_product_thumbnail
please check below reference link.
- Product image in-new order email
- Display product image in sales order view-page
I hope it helps!
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266775%2fproduct-image-in-invoice-email-template%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
I found the solution but it's getting parent thumbnail image, i like to get if product has selected in swatch option, that swatch option need to display.
example: if i select red colour, red colour swatch image need to display.
$productId = $_item->getProductId();
$objectManagerHere = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);
$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$imageHelper = $_objectManager->get('MagentoCatalogHelperImage');
$image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize(80, 80)->getUrl();
<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
add a comment |
I found the solution but it's getting parent thumbnail image, i like to get if product has selected in swatch option, that swatch option need to display.
example: if i select red colour, red colour swatch image need to display.
$productId = $_item->getProductId();
$objectManagerHere = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);
$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$imageHelper = $_objectManager->get('MagentoCatalogHelperImage');
$image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize(80, 80)->getUrl();
<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
add a comment |
I found the solution but it's getting parent thumbnail image, i like to get if product has selected in swatch option, that swatch option need to display.
example: if i select red colour, red colour swatch image need to display.
$productId = $_item->getProductId();
$objectManagerHere = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);
$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$imageHelper = $_objectManager->get('MagentoCatalogHelperImage');
$image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize(80, 80)->getUrl();
<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
I found the solution but it's getting parent thumbnail image, i like to get if product has selected in swatch option, that swatch option need to display.
example: if i select red colour, red colour swatch image need to display.
$productId = $_item->getProductId();
$objectManagerHere = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);
$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$imageHelper = $_objectManager->get('MagentoCatalogHelperImage');
$image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize(80, 80)->getUrl();
<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
edited Apr 12 at 6:57
answered Mar 21 at 9:06
mohanamohana
8214
8214
add a comment |
add a comment |
I have override DefaultInvoice
class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice
public function draw()
$order = $this->getOrder();
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$lines = [];
// draw Product image
$productImage = $this->getProductImage($item, $page);
// draw Product name
$lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
$lines[0][] = array(
'text' => $productImage,
'is_image' => 1,
'feed' => 200
);
// draw SKU
$lines[0][] = [
'text' => $this->string->split($this->getSku($item), 17),
'feed' => 370,
'align' => 'right',
];
// draw QTY
$lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];
// draw item Prices
$i = 0;
$prices = $this->getItemPricesForDisplay();
$feedPrice = 425;
$feedSubtotal = $feedPrice + 140;
foreach ($prices as $priceData)
if (isset($priceData['label']))
// draw Price label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
// draw Subtotal label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
$i++;
// draw Price
$lines[$i][] = [
'text' => $priceData['price'],
'feed' => $feedPrice,
'font' => 'bold',
'align' => 'right',
];
// draw Subtotal
$lines[$i][] = [
'text' => $priceData['subtotal'],
'feed' => $feedSubtotal,
'font' => 'bold',
'align' => 'right',
];
$i++;
// draw Tax
$lines[0][] = [
'text' => $order->formatPriceTxt($item->getTaxAmount()),
'feed' => 515,
'font' => 'bold',
'align' => 'right',
];
// custom options
$options = $this->getItemOptions();
if ($options)
foreach ($options as $option)
// draw options label
$lines[][] = [
'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
'font' => 'italic',
'feed' => 35,
];
if ($option['value'])
if (isset($option['print_value']))
$printValue = $option['print_value'];
else
$printValue = $this->filterManager->stripTags($option['value']);
$values = explode(', ', $printValue);
foreach ($values as $value)
$lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
$lineBlock = ['lines' => $lines, 'height' => 20];
$page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);
$this->setPage($page);
/*
* Return Value of custom attribute
* */
private function getProductImage($item, &$page)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productId = $item->getOrderItem()->getProductId();
$image = $objectManager->get('MagentoCatalogModelProduct')->load($productId);
if (!is_null($image))
try
$imagePath = '/catalog/product/'.$image->getSmallImage();
$filesystem = $objectManager->get('MagentoFrameworkFilesystem');
$media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
if ($media_dir->isFile($imagePath))
return $media_dir->getAbsolutePath($imagePath);
else
return null;
catch (Exception $e)
return false;
Which returns me PDF like this. (working on Image rotation :) )
UPDATED
For variant based product - based on configure product's attribute
selection
class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice
public function draw()
$order = $this->getOrder();
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$lines = [];
// draw Product image
$productImage = $this->getProductImage($item, $page);
// draw Product name
$lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
$lines[0][] = array(
'text' => $productImage,
'is_image' => 1,
'feed' => 200
);
// draw SKU
$lines[0][] = [
'text' => $this->string->split($this->getSku($item), 17),
'feed' => 370,
'align' => 'right',
];
// draw QTY
$lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];
// draw item Prices
$i = 0;
$prices = $this->getItemPricesForDisplay();
$feedPrice = 425;
$feedSubtotal = $feedPrice + 140;
foreach ($prices as $priceData)
if (isset($priceData['label']))
// draw Price label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
// draw Subtotal label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
$i++;
// draw Price
$lines[$i][] = [
'text' => $priceData['price'],
'feed' => $feedPrice,
'font' => 'bold',
'align' => 'right',
];
// draw Subtotal
$lines[$i][] = [
'text' => $priceData['subtotal'],
'feed' => $feedSubtotal,
'font' => 'bold',
'align' => 'right',
];
$i++;
// draw Tax
$lines[0][] = [
'text' => $order->formatPriceTxt($item->getTaxAmount()),
'feed' => 515,
'font' => 'bold',
'align' => 'right',
];
// custom options
$options = $this->getItemOptions();
if ($options)
foreach ($options as $option)
// draw options label
$lines[][] = [
'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
'font' => 'italic',
'feed' => 35,
];
if ($option['value'])
if (isset($option['print_value']))
$printValue = $option['print_value'];
else
$printValue = $this->filterManager->stripTags($option['value']);
$values = explode(', ', $printValue);
foreach ($values as $value)
$lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
$lineBlock = ['lines' => $lines, 'height' => 20];
$page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);
$this->setPage($page);
/*
* Return Value of custom attribute
* */
private function getProductImage($item, &$page)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productId = $item->getOrderItem()->getProductId();
$data = $objectManager->get('MagentoCatalogModelProductRepository')->get($item->getSku());
$image = $data->getImage();
if (!is_null($image))
try
$imagePath = '/catalog/product/'.$image;
$filesystem = $objectManager->get('MagentoFrameworkFilesystem');
$media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
if ($media_dir->isFile($imagePath))
return $media_dir->getAbsolutePath($imagePath);
else
return null;
catch (Exception $e)
return false;
Here's simple product's image in Invoice based of variant selection of
configure product.
More References
Reference 1 , Reference 2 , Reference 3
add a comment |
I have override DefaultInvoice
class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice
public function draw()
$order = $this->getOrder();
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$lines = [];
// draw Product image
$productImage = $this->getProductImage($item, $page);
// draw Product name
$lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
$lines[0][] = array(
'text' => $productImage,
'is_image' => 1,
'feed' => 200
);
// draw SKU
$lines[0][] = [
'text' => $this->string->split($this->getSku($item), 17),
'feed' => 370,
'align' => 'right',
];
// draw QTY
$lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];
// draw item Prices
$i = 0;
$prices = $this->getItemPricesForDisplay();
$feedPrice = 425;
$feedSubtotal = $feedPrice + 140;
foreach ($prices as $priceData)
if (isset($priceData['label']))
// draw Price label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
// draw Subtotal label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
$i++;
// draw Price
$lines[$i][] = [
'text' => $priceData['price'],
'feed' => $feedPrice,
'font' => 'bold',
'align' => 'right',
];
// draw Subtotal
$lines[$i][] = [
'text' => $priceData['subtotal'],
'feed' => $feedSubtotal,
'font' => 'bold',
'align' => 'right',
];
$i++;
// draw Tax
$lines[0][] = [
'text' => $order->formatPriceTxt($item->getTaxAmount()),
'feed' => 515,
'font' => 'bold',
'align' => 'right',
];
// custom options
$options = $this->getItemOptions();
if ($options)
foreach ($options as $option)
// draw options label
$lines[][] = [
'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
'font' => 'italic',
'feed' => 35,
];
if ($option['value'])
if (isset($option['print_value']))
$printValue = $option['print_value'];
else
$printValue = $this->filterManager->stripTags($option['value']);
$values = explode(', ', $printValue);
foreach ($values as $value)
$lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
$lineBlock = ['lines' => $lines, 'height' => 20];
$page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);
$this->setPage($page);
/*
* Return Value of custom attribute
* */
private function getProductImage($item, &$page)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productId = $item->getOrderItem()->getProductId();
$image = $objectManager->get('MagentoCatalogModelProduct')->load($productId);
if (!is_null($image))
try
$imagePath = '/catalog/product/'.$image->getSmallImage();
$filesystem = $objectManager->get('MagentoFrameworkFilesystem');
$media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
if ($media_dir->isFile($imagePath))
return $media_dir->getAbsolutePath($imagePath);
else
return null;
catch (Exception $e)
return false;
Which returns me PDF like this. (working on Image rotation :) )
UPDATED
For variant based product - based on configure product's attribute
selection
class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice
public function draw()
$order = $this->getOrder();
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$lines = [];
// draw Product image
$productImage = $this->getProductImage($item, $page);
// draw Product name
$lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
$lines[0][] = array(
'text' => $productImage,
'is_image' => 1,
'feed' => 200
);
// draw SKU
$lines[0][] = [
'text' => $this->string->split($this->getSku($item), 17),
'feed' => 370,
'align' => 'right',
];
// draw QTY
$lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];
// draw item Prices
$i = 0;
$prices = $this->getItemPricesForDisplay();
$feedPrice = 425;
$feedSubtotal = $feedPrice + 140;
foreach ($prices as $priceData)
if (isset($priceData['label']))
// draw Price label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
// draw Subtotal label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
$i++;
// draw Price
$lines[$i][] = [
'text' => $priceData['price'],
'feed' => $feedPrice,
'font' => 'bold',
'align' => 'right',
];
// draw Subtotal
$lines[$i][] = [
'text' => $priceData['subtotal'],
'feed' => $feedSubtotal,
'font' => 'bold',
'align' => 'right',
];
$i++;
// draw Tax
$lines[0][] = [
'text' => $order->formatPriceTxt($item->getTaxAmount()),
'feed' => 515,
'font' => 'bold',
'align' => 'right',
];
// custom options
$options = $this->getItemOptions();
if ($options)
foreach ($options as $option)
// draw options label
$lines[][] = [
'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
'font' => 'italic',
'feed' => 35,
];
if ($option['value'])
if (isset($option['print_value']))
$printValue = $option['print_value'];
else
$printValue = $this->filterManager->stripTags($option['value']);
$values = explode(', ', $printValue);
foreach ($values as $value)
$lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
$lineBlock = ['lines' => $lines, 'height' => 20];
$page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);
$this->setPage($page);
/*
* Return Value of custom attribute
* */
private function getProductImage($item, &$page)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productId = $item->getOrderItem()->getProductId();
$data = $objectManager->get('MagentoCatalogModelProductRepository')->get($item->getSku());
$image = $data->getImage();
if (!is_null($image))
try
$imagePath = '/catalog/product/'.$image;
$filesystem = $objectManager->get('MagentoFrameworkFilesystem');
$media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
if ($media_dir->isFile($imagePath))
return $media_dir->getAbsolutePath($imagePath);
else
return null;
catch (Exception $e)
return false;
Here's simple product's image in Invoice based of variant selection of
configure product.
More References
Reference 1 , Reference 2 , Reference 3
add a comment |
I have override DefaultInvoice
class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice
public function draw()
$order = $this->getOrder();
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$lines = [];
// draw Product image
$productImage = $this->getProductImage($item, $page);
// draw Product name
$lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
$lines[0][] = array(
'text' => $productImage,
'is_image' => 1,
'feed' => 200
);
// draw SKU
$lines[0][] = [
'text' => $this->string->split($this->getSku($item), 17),
'feed' => 370,
'align' => 'right',
];
// draw QTY
$lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];
// draw item Prices
$i = 0;
$prices = $this->getItemPricesForDisplay();
$feedPrice = 425;
$feedSubtotal = $feedPrice + 140;
foreach ($prices as $priceData)
if (isset($priceData['label']))
// draw Price label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
// draw Subtotal label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
$i++;
// draw Price
$lines[$i][] = [
'text' => $priceData['price'],
'feed' => $feedPrice,
'font' => 'bold',
'align' => 'right',
];
// draw Subtotal
$lines[$i][] = [
'text' => $priceData['subtotal'],
'feed' => $feedSubtotal,
'font' => 'bold',
'align' => 'right',
];
$i++;
// draw Tax
$lines[0][] = [
'text' => $order->formatPriceTxt($item->getTaxAmount()),
'feed' => 515,
'font' => 'bold',
'align' => 'right',
];
// custom options
$options = $this->getItemOptions();
if ($options)
foreach ($options as $option)
// draw options label
$lines[][] = [
'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
'font' => 'italic',
'feed' => 35,
];
if ($option['value'])
if (isset($option['print_value']))
$printValue = $option['print_value'];
else
$printValue = $this->filterManager->stripTags($option['value']);
$values = explode(', ', $printValue);
foreach ($values as $value)
$lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
$lineBlock = ['lines' => $lines, 'height' => 20];
$page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);
$this->setPage($page);
/*
* Return Value of custom attribute
* */
private function getProductImage($item, &$page)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productId = $item->getOrderItem()->getProductId();
$image = $objectManager->get('MagentoCatalogModelProduct')->load($productId);
if (!is_null($image))
try
$imagePath = '/catalog/product/'.$image->getSmallImage();
$filesystem = $objectManager->get('MagentoFrameworkFilesystem');
$media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
if ($media_dir->isFile($imagePath))
return $media_dir->getAbsolutePath($imagePath);
else
return null;
catch (Exception $e)
return false;
Which returns me PDF like this. (working on Image rotation :) )
UPDATED
For variant based product - based on configure product's attribute
selection
class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice
public function draw()
$order = $this->getOrder();
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$lines = [];
// draw Product image
$productImage = $this->getProductImage($item, $page);
// draw Product name
$lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
$lines[0][] = array(
'text' => $productImage,
'is_image' => 1,
'feed' => 200
);
// draw SKU
$lines[0][] = [
'text' => $this->string->split($this->getSku($item), 17),
'feed' => 370,
'align' => 'right',
];
// draw QTY
$lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];
// draw item Prices
$i = 0;
$prices = $this->getItemPricesForDisplay();
$feedPrice = 425;
$feedSubtotal = $feedPrice + 140;
foreach ($prices as $priceData)
if (isset($priceData['label']))
// draw Price label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
// draw Subtotal label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
$i++;
// draw Price
$lines[$i][] = [
'text' => $priceData['price'],
'feed' => $feedPrice,
'font' => 'bold',
'align' => 'right',
];
// draw Subtotal
$lines[$i][] = [
'text' => $priceData['subtotal'],
'feed' => $feedSubtotal,
'font' => 'bold',
'align' => 'right',
];
$i++;
// draw Tax
$lines[0][] = [
'text' => $order->formatPriceTxt($item->getTaxAmount()),
'feed' => 515,
'font' => 'bold',
'align' => 'right',
];
// custom options
$options = $this->getItemOptions();
if ($options)
foreach ($options as $option)
// draw options label
$lines[][] = [
'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
'font' => 'italic',
'feed' => 35,
];
if ($option['value'])
if (isset($option['print_value']))
$printValue = $option['print_value'];
else
$printValue = $this->filterManager->stripTags($option['value']);
$values = explode(', ', $printValue);
foreach ($values as $value)
$lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
$lineBlock = ['lines' => $lines, 'height' => 20];
$page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);
$this->setPage($page);
/*
* Return Value of custom attribute
* */
private function getProductImage($item, &$page)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productId = $item->getOrderItem()->getProductId();
$data = $objectManager->get('MagentoCatalogModelProductRepository')->get($item->getSku());
$image = $data->getImage();
if (!is_null($image))
try
$imagePath = '/catalog/product/'.$image;
$filesystem = $objectManager->get('MagentoFrameworkFilesystem');
$media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
if ($media_dir->isFile($imagePath))
return $media_dir->getAbsolutePath($imagePath);
else
return null;
catch (Exception $e)
return false;
Here's simple product's image in Invoice based of variant selection of
configure product.
More References
Reference 1 , Reference 2 , Reference 3
I have override DefaultInvoice
class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice
public function draw()
$order = $this->getOrder();
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$lines = [];
// draw Product image
$productImage = $this->getProductImage($item, $page);
// draw Product name
$lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
$lines[0][] = array(
'text' => $productImage,
'is_image' => 1,
'feed' => 200
);
// draw SKU
$lines[0][] = [
'text' => $this->string->split($this->getSku($item), 17),
'feed' => 370,
'align' => 'right',
];
// draw QTY
$lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];
// draw item Prices
$i = 0;
$prices = $this->getItemPricesForDisplay();
$feedPrice = 425;
$feedSubtotal = $feedPrice + 140;
foreach ($prices as $priceData)
if (isset($priceData['label']))
// draw Price label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
// draw Subtotal label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
$i++;
// draw Price
$lines[$i][] = [
'text' => $priceData['price'],
'feed' => $feedPrice,
'font' => 'bold',
'align' => 'right',
];
// draw Subtotal
$lines[$i][] = [
'text' => $priceData['subtotal'],
'feed' => $feedSubtotal,
'font' => 'bold',
'align' => 'right',
];
$i++;
// draw Tax
$lines[0][] = [
'text' => $order->formatPriceTxt($item->getTaxAmount()),
'feed' => 515,
'font' => 'bold',
'align' => 'right',
];
// custom options
$options = $this->getItemOptions();
if ($options)
foreach ($options as $option)
// draw options label
$lines[][] = [
'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
'font' => 'italic',
'feed' => 35,
];
if ($option['value'])
if (isset($option['print_value']))
$printValue = $option['print_value'];
else
$printValue = $this->filterManager->stripTags($option['value']);
$values = explode(', ', $printValue);
foreach ($values as $value)
$lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
$lineBlock = ['lines' => $lines, 'height' => 20];
$page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);
$this->setPage($page);
/*
* Return Value of custom attribute
* */
private function getProductImage($item, &$page)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productId = $item->getOrderItem()->getProductId();
$image = $objectManager->get('MagentoCatalogModelProduct')->load($productId);
if (!is_null($image))
try
$imagePath = '/catalog/product/'.$image->getSmallImage();
$filesystem = $objectManager->get('MagentoFrameworkFilesystem');
$media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
if ($media_dir->isFile($imagePath))
return $media_dir->getAbsolutePath($imagePath);
else
return null;
catch (Exception $e)
return false;
Which returns me PDF like this. (working on Image rotation :) )
UPDATED
For variant based product - based on configure product's attribute
selection
class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice
public function draw()
$order = $this->getOrder();
$item = $this->getItem();
$pdf = $this->getPdf();
$page = $this->getPage();
$lines = [];
// draw Product image
$productImage = $this->getProductImage($item, $page);
// draw Product name
$lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
$lines[0][] = array(
'text' => $productImage,
'is_image' => 1,
'feed' => 200
);
// draw SKU
$lines[0][] = [
'text' => $this->string->split($this->getSku($item), 17),
'feed' => 370,
'align' => 'right',
];
// draw QTY
$lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];
// draw item Prices
$i = 0;
$prices = $this->getItemPricesForDisplay();
$feedPrice = 425;
$feedSubtotal = $feedPrice + 140;
foreach ($prices as $priceData)
if (isset($priceData['label']))
// draw Price label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
// draw Subtotal label
$lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
$i++;
// draw Price
$lines[$i][] = [
'text' => $priceData['price'],
'feed' => $feedPrice,
'font' => 'bold',
'align' => 'right',
];
// draw Subtotal
$lines[$i][] = [
'text' => $priceData['subtotal'],
'feed' => $feedSubtotal,
'font' => 'bold',
'align' => 'right',
];
$i++;
// draw Tax
$lines[0][] = [
'text' => $order->formatPriceTxt($item->getTaxAmount()),
'feed' => 515,
'font' => 'bold',
'align' => 'right',
];
// custom options
$options = $this->getItemOptions();
if ($options)
foreach ($options as $option)
// draw options label
$lines[][] = [
'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
'font' => 'italic',
'feed' => 35,
];
if ($option['value'])
if (isset($option['print_value']))
$printValue = $option['print_value'];
else
$printValue = $this->filterManager->stripTags($option['value']);
$values = explode(', ', $printValue);
foreach ($values as $value)
$lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
$lineBlock = ['lines' => $lines, 'height' => 20];
$page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);
$this->setPage($page);
/*
* Return Value of custom attribute
* */
private function getProductImage($item, &$page)
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productId = $item->getOrderItem()->getProductId();
$data = $objectManager->get('MagentoCatalogModelProductRepository')->get($item->getSku());
$image = $data->getImage();
if (!is_null($image))
try
$imagePath = '/catalog/product/'.$image;
$filesystem = $objectManager->get('MagentoFrameworkFilesystem');
$media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);
if ($media_dir->isFile($imagePath))
return $media_dir->getAbsolutePath($imagePath);
else
return null;
catch (Exception $e)
return false;
Here's simple product's image in Invoice based of variant selection of
configure product.
More References
Reference 1 , Reference 2 , Reference 3
edited Apr 18 at 11:10
answered Apr 18 at 8:14
AadityaAaditya
4,45621139
4,45621139
add a comment |
add a comment |
You can replace following line in your code
$product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);
With following line
$product = $objectManagerHere->get('MagentoCatalogModelProductRepository')->get($_item->getSku());
With this, you can get appropriate simple product of configurable product.
add a comment |
You can replace following line in your code
$product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);
With following line
$product = $objectManagerHere->get('MagentoCatalogModelProductRepository')->get($_item->getSku());
With this, you can get appropriate simple product of configurable product.
add a comment |
You can replace following line in your code
$product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);
With following line
$product = $objectManagerHere->get('MagentoCatalogModelProductRepository')->get($_item->getSku());
With this, you can get appropriate simple product of configurable product.
You can replace following line in your code
$product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);
With following line
$product = $objectManagerHere->get('MagentoCatalogModelProductRepository')->get($_item->getSku());
With this, you can get appropriate simple product of configurable product.
answered Apr 18 at 5:00
Yash ShahYash Shah
93628
93628
add a comment |
add a comment |
I think you should try with cart_page_product_thumbnail
instead of product_thumbnail_image
in your get product image code.
Your code should be like this.
$image_url = $imageHelper->init($product, 'cart_page_product_thumbnail')->setImageFile($product->getFile())->resize(80, 80)->getUrl();
I have used the above code to display product image in the Email template and it is working fine with configurable products. and I think it also works for the invoice email template.
I have also seen so many users use cart_page_product_thumbnail
please check below reference link.
- Product image in-new order email
- Display product image in sales order view-page
I hope it helps!
add a comment |
I think you should try with cart_page_product_thumbnail
instead of product_thumbnail_image
in your get product image code.
Your code should be like this.
$image_url = $imageHelper->init($product, 'cart_page_product_thumbnail')->setImageFile($product->getFile())->resize(80, 80)->getUrl();
I have used the above code to display product image in the Email template and it is working fine with configurable products. and I think it also works for the invoice email template.
I have also seen so many users use cart_page_product_thumbnail
please check below reference link.
- Product image in-new order email
- Display product image in sales order view-page
I hope it helps!
add a comment |
I think you should try with cart_page_product_thumbnail
instead of product_thumbnail_image
in your get product image code.
Your code should be like this.
$image_url = $imageHelper->init($product, 'cart_page_product_thumbnail')->setImageFile($product->getFile())->resize(80, 80)->getUrl();
I have used the above code to display product image in the Email template and it is working fine with configurable products. and I think it also works for the invoice email template.
I have also seen so many users use cart_page_product_thumbnail
please check below reference link.
- Product image in-new order email
- Display product image in sales order view-page
I hope it helps!
I think you should try with cart_page_product_thumbnail
instead of product_thumbnail_image
in your get product image code.
Your code should be like this.
$image_url = $imageHelper->init($product, 'cart_page_product_thumbnail')->setImageFile($product->getFile())->resize(80, 80)->getUrl();
I have used the above code to display product image in the Email template and it is working fine with configurable products. and I think it also works for the invoice email template.
I have also seen so many users use cart_page_product_thumbnail
please check below reference link.
- Product image in-new order email
- Display product image in sales order view-page
I hope it helps!
answered Apr 18 at 7:10
Chirag PatelChirag Patel
2,648423
2,648423
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266775%2fproduct-image-in-invoice-email-template%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
you can't use PHP in email templates
– Philipp Sander
Mar 21 at 7:13
i did not use in my email template directly, i added this code in my file "Magento_Sales/templates/email/items/shipment/default.phtml"
– mohana
Mar 21 at 7:54
Do you mean the order email?
– Dava Gordon
Apr 12 at 10:57
Try the below answer and keep post your complete phtml
– Prathap Gunasekaran
Apr 13 at 3:24