Skip to main content
2 of 2
added 1189 characters in body
Monark Bhawani
  • 684
  • 1
  • 4
  • 12

Override DefaultInvoice.php file to render custom row in magento 2.4.4

I need to override Magento\Sales\Model\Order\Pdf\Items\Invoice\DefaultInvoice.php file to render a custom row in Magento 2.4.4

I tried with preferences like

<preference for="Magento\Sales\Model\Order\Pdf\Items\Invoice\DefaultInvoice" type="Vendor\Module\Model\Order\Pdf\Items\Invoice\DefaultInvoice"/>

it gives the following error while print the invoice pdf

Error: Cannot instantiate abstract class Magento\Framework\Model\ResourceModel\AbstractResource in /app/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php:50

This is related to gift wrap and I want to render item wise wrap items data like wrap image, wrap name, etc. like the below

If there are 2 items in order then 2 wrap data is available, so I need to show 2 raw but when I add

$this->_drawItemWrap($item, $page, $order);

line in getPdf function it throw error

Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid method Magento\Sales\Model\Order\Pdf\Items\Invoice\DefaultInvoice\Interceptor::drawWrap

I rendered that function like below

protected function _drawItemWrap(
  \Magento\Framework\DataObject $item,
  \Zend_Pdf_Page $page,
  \Magento\Sales\Model\Order $order
) {
  $type = $item->getOrderItem()->getProductType();
  $renderer = $this->_getRenderer($type);
  $renderer->setOrder($order);
  $renderer->setItem($item);
  $renderer->setPdf($this);
  $renderer->setPage($page);
  $renderer->setRenderedModel($this);
  $renderer->drawWrap();

  return $renderer->getPage();
}

I need to show wrap history like below image.

enter image description here

If anyone has the solution to rendering the custom row the same as the order item row then please suggest it.

Thank you so much.

Monark Bhawani
  • 684
  • 1
  • 4
  • 12