I'm trying to show the order comments history on the invoice (Magento 2.2.6)
I've written the following override:
app/code/Denial/InvoiceComments/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Sales\Block\Order\Comments" type="Denial\InvoiceComments\Block\Rewrite\Order\Comments" />
</config>
And
app/code/Denial/InvoiceComments/Block/Rewrite/Order/Comments.php
<?php
namespace Denial\InvoiceComments\Block\Rewrite\Order;
class Comments extends \Magento\Framework\View\Element\Template
{
public function getComments()
{
if ($this->_commentCollection === null) {
$entity = $this->getEntity();
if ($entity instanceof \Magento\Sales\Model\Order\Invoice) {
$this->_commentCollection = $this->_invoiceCollectionFactory->create();
$this->_commentCollection = $this->_orderCollectionFactory->create();
}
}
return $this->_commentCollection;
}
}
Is this right? Have I missed any steps? I ran di:compile but the order comments aren't showing up, only the invoice comments. Am I adding to the commentCollection correctly?