How to override address/grid.phtml in Magento 2?

You can override the grid.phtml file to manage additional addresses of the customer.

If the customer has multiple addresses available, it will be displayed in the Additional Address Entries section of the Address book page. You can add/update the new column to the address list on the page using overriding grid template file.

Magento\Customer\Block\Address\Grid Block class is used to manage the grid template file. You can override using theme or module level,

1. Theme Level,

app/design/frontend/{Vendor}/{themename}/Magento_Customer/templates/address/grid.phtml

2. Module Level,
When you explore the customer_address_index.xml file from the customer module, You can see the address_book block that will be used to display an address book page on the frontend.

File Path: app/code/Jesadiya/Book/view/frontend/layout/customer_address_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="address_grid">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Jesadiya_Book::address/grid.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Create Template file to override grid.phtml,
app/code/Jesadiya/Book/view/frontend/templates/address/grid.phtml

Keep the required content from the Core template and modify your changes. You can also override Address book.phtml in Magento 2

Clear Cache to see changes,
php bin/magento cache:flush

How to override address/book phtml in Magento 2?

You can override the book.phtml file in Magento 2 using XML.
Book template used to display the address book of the customer with default billing and shipping address at the top of the Address book page.

Magento\Customer\Block\Address\Book

Book Block class contains the native method for the template.
You can override using theme or module level, Continue reading “How to override address/book phtml in Magento 2?”

How to check customer is authenticated in Magento 2?

Customer Authentication using Magento 2 to check customer types like its a guest user or login user.

There are many occasions when you need to check customer authentic status and based on the login customer only you need to show a specific page otherwise redirect it to the login page.

Verify the customer has valid authentication using \Magento\Customer\Model\Session Class. add the Customer Session class to the __construct() method of your Controller. Continue reading “How to check customer is authenticated in Magento 2?”