skip to Main Content

i am creating a custom module and i want to include a custom phtml file above the attributes on the configurable product page…

Click here to see the requirements

Please take a look on the module files i have created and what i have done after some google search –

  • 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="MagentoConfigurableProductBlockProductViewTypeConfigurable" type="Bay20WarehouseConfigurableBlockRewriteProductView" />  
</config>
  • view/frontened/layout/catalog_product_view_type_configurable.xml
<?xml version="1.0"?>
    <!--
    /**
     * Copyright © 2015 Magento. 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">
        <body>
            <attribute name="class" value="page-product-configurable"/>
            <referenceBlock name="product.info.options.wrapper">
                <block class="MagentoConfigurableProductBlockProductViewTypeConfigurable" name="product.info.options.configurable" as="options_configurable" before="-" template="product/view/type/options/configurable.phtml"/>
            </referenceBlock>
            
        </body>
  • view/templates/product/view/type/options/configurable.phtml
 <?php
    
    /** @var $block MagentoConfigurableProductBlockProductViewTypeConfigurable*/
    //$_product    = $block->getProduct();
    //$_attributes = $block->decorateArray($block->getAllowAttributes());
    
    ?>
    
    <p>Hello there</p>

but i am not able to get the file on configurable product view page, What’s wrong i am doing, please let me know.

thanks

2

Answers


  1. I have achieved by this way.

    view/frontened/layout/catalog_product_view_type_configurable.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="product.info.main">
            <block after="product.info.price" class="TestMymoduleBlockPosts" name="extra" template="Test_Mymodule::extra.phtml" /> 
        </referenceBlock>        
    </body>
    

    view/templates/extra.phtml

    <?php echo "<p>Extra Block</p>";
    
    Login or Signup to reply.
  2. create file as

    app/code/Vendor/Module/view/frontend/layout/catalog_product_view.xml

    file: catalog_product_view.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>
            <referenceContainer name="product.info.main">
                <block class="MagentoCatalogBlockProductView" after="product.info.price" 
                as="custom"
                    template="Vendor_Module::product/view/custom.phtml"/>
            </referenceContainer>
        </body>
    </page>
    

    in PHTML file

    app/code/Vendor/Module/view/frontend/templates/product/view/cusrom.phtml

    <div class='custom-box'>
        <span class="custom">
                hii from custom.phtml file
        </span>
    </div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search