I want to overrid magento 2 address_book block, but I got an error like this:
Invalid template file: 'address/book.phtml' in module: 'Namespace_Module' block's name: 'address_book'
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\Customer\Block\Address\Book" type="Namespace\Module\Block\Address\Book"/>
</config>
Namespace\Module\Block\Address\Book.php :
namespace Lime\Courier\Block\Address;
use Magento\Customer\Api\AddressRepositoryInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Customer\Model\Address\Mapper;
class Book extends \Magento\Customer\Block\Address\Book
{
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
CustomerRepositoryInterface $customerRepository,
AddressRepositoryInterface $addressRepository,
\Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer,
\Magento\Customer\Model\Address\Config $addressConfig,
Mapper $addressMapper,
array $data = []
) {
$this->customerRepository = $customerRepository;
$this->currentCustomer = $currentCustomer;
$this->addressRepository = $addressRepository;
$this->_addressConfig = $addressConfig;
$this->addressMapper = $addressMapper;
parent::__construct($context, $customerRepository,$addressRepository,$currentCustomer,$addressConfig,$addressMapper, $data);
}
public function getAddressHtml(\Magento\Customer\Api\Data\AddressInterface $address = null)
{
if ($address !== null) {
/** @var \Magento\Customer\Block\Address\Renderer\RendererInterface $renderer */
$renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer();
return $renderer->renderArray($this->addressMapper->toFlatArray($address));
}
return '';
}
}
I think the problem is they search for template file in my module, but I just need to override the block file not the phtml file