1

I'm trying to override the COA-search.phtml file found in vendor/magento/module-newsletter/view/frontend/templates

<div>
    <p style="font-weight:bold;">Search for a Certificate of Analysis by Lot Number below:</p> 
    <div>
        <form action="/technical-support/certificate-of-analysis.html" method="get" name="search">
            <input type="text" name="keyword" id="keyword" />
            <div class="actions" style="margin-top:10px;">
                <button class="action primary" title="Search" type="submit" aria-label="Search">Search</button>
            </div>
        </form>
        <br/>
        <?php
            if(isset($_GET['keyword'])){
                $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
                $customerSession = $objectManager->get('\Magento\Customer\Model\Session');
                $documentRoot = $_SERVER['DOCUMENT_ROOT'];
                $filename = $_GET['keyword'];
                $filepath = $documentRoot."/COA/".$filename.".pdf";
                if(file_exists($filepath)){
                    if($customerSession->isLoggedIn()){
                        echo "<p><img src='/pub/media/images/etc/pdf.jpg' alt='PDF'><a href='/COA/$filename.pdf' title='Certificate of Analysis' target='_blank'>$filename</a></p>";
                    }else{
                        echo "Certificate of Analysis found, please <a href='/customer/account/login/' title='login'>login</a> or <a href='/customer/account/create/' title='register'>register</a> to access the Certificate of Analysis.";
                    }
                }else{
                    echo "<p>Certificate of Analysis for Lot Number $filename does not exist or not available at this time. Please contact <a href='mailto:[email protected]' title='Email sales'>[email protected]</a> for further assistance.</p>";
                }
            }
        ?>
    </div>
</div>

In my app/code folder I have place this newer phtml file in the app/code/Sciencell/COAs/view/frontend/templates

I have a registration.php file app/code/Sciencell/COAs

<?php /**
* Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Sciencell_COAs',
__DIR__
);

I have a module.xml in app/code/Sciencell/COAs/etc

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Sciencell_COAs" setup_version="0.0.1">
        <sequence>
            <module name="Magento_Newsletter"/>
        </sequence>
    </module>
</config>

And finally a newsletter_manage_index.xml in my app/code/Sciencell/COAs/view/frontend/layout

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="customer_account"/>
    <body>
        <referenceContainer name="content">
            <block class="Magento\Customer\Block\Newsletter" name="customer_newsletter" cacheable="false" template="Sciencell_COAs::COA_search.phtml">
                <container name="customer.newsletter.form.before" as="form_before" label="Newsletter Subscription Form Before" htmlTag="div" htmlClass="rewards"/>
            </block>
        </referenceContainer>
    </body>
</page>

I can see the module is enabled in the config.php file. So what am I missing? Why are the changes not being reflected. I've tried it all. bin/magento setup:upgrade, compile, deploy, reindex, cache. I've also tried deleting folders rm -rf pub/static/adminhtml pub/static/frontend var/cache var/composer_home/ var/page_cache/ var/view_preprocessed/ generated/ generated/*

1 Answer 1

0

**Change newsletter_manage_index.xml file with below code

<?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">
    <update handle="customer_account"/>
    <body>
        <referenceBlock name="customer_newsletter" template="Sciencell_COAs::COA_search.phtml">
        </referenceBlock>
    </body>
</page>
3
  • Thanks for responding, but It didn't work. How important is the naming convention for the xml file? I changed it to default.xml. I checked on my admin page for the block I want to override. Its called 'coa-search' so I changed the referenceBlock name to that instead of "customer_newsletter?" Also what value should go into handle in the update tag?
    – Zei
    Commented Nov 16, 2021 at 18:31
  • I'm not sure how the COA_search.phtml file in the vendor was created. But when I used your xml to override the subscribe.phtml. It worked. How do you figure out what the referenceBlock name is?
    – Zei
    Commented Nov 19, 2021 at 20:17
  • The block you want to override should be taken as referenceBlock while overriding the phtml file in custom module. If you find the solution then accept the solution. Thanks Commented Nov 22, 2021 at 4:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.