3

I am using magento-2.0.0 . I am trying to overtire

vendor/magento/module-grouped-product/view/frontend/templates/product/view/type/default.phtml with my module template.

My module layout code of

frontend/layout/catalog_product_view_type_grouped.xml

<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.grouped">
            <action method='setTemplate'>
                <argument name="template" xsi:type="string">Namespace_Modulename::availability.phtml</argument>
            </action>           
        </referenceBlock>        
    </body>
</page>

Default file code /vendor/magento/module-grouped-product/view/frontend/layout/catalog_product_view_type_grouped.xml

<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-grouped"/>
        <referenceContainer name="product.info.form.content">
            <block class="Magento\GroupedProduct\Block\Product\View\Type\Grouped" name="product.info.grouped" before="product.info.addtocart" template="product/view/type/grouped.phtml"/>
            <container name="product.info.grouped.extra" after="product.info.grouped" before="product.info.grouped" as="product_type_data_extra" label="Product Extra Info"/>
        </referenceContainer>
        <referenceContainer name="product.info.grouped.extra">
            <block class="Magento\GroupedProduct\Block\Stockqty\Type\Grouped" template="Magento_CatalogInventory::stockqty/composite.phtml"/>
        </referenceContainer>

        <referenceContainer name="product.info.type">

          <!-- below block i am trying to overrite-->

            <block class="Magento\GroupedProduct\Block\Product\View\Type\Grouped" as="product.info.grouped" template="product/view/type/default.phtml"/>

        </referenceContainer>
    </body>
</page>

My problem is there is no name attribute alias is as="product.info.grouped" . Alias is already used in above code.

<block class="Magento\GroupedProduct\Block\Product\View\Type\Grouped" name="product.info.grouped" before="product.info.addtocart" template="product/view/type/grouped.phtml"/>

So My template render at product/view/type/grouped.phtml instead of product/view/type/default.phtml

I can able to give different name attribute and use it in my module.But I am developing extension . Is it magento bug? Any help would be much appreciated

4 Answers 4

4

This is what I end up doing to override the vendor/magento/module-grouped-product/view/frontend/templates/product/view/type/grouped.phtml template from Magento_GroupedProduct module.

Created new layout file catalog_product_view_type_grouped.xml at location Namespace/Module/view/frontend/layout/catalog_product_view_type_grouped.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.grouped">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Namespace_Module::catalog/product/view/type/grouped.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>
0
1

I added below code to my layout file

frontend/layout/catalog_product_view_type_grouped.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.type">
                <block class="Magento\GroupedProduct\Block\Product\View\Type\Grouped" template="Namespace_Modulename::group-available.phtml" />             
         </referenceContainer>  
    </body>
</page>

It is working for me.May be it helpful to other.

1
  • amazing thanks this solved my issue as well. I am wondering though is that the right way??
    – PVL
    Jun 23, 2016 at 19:19
-1

Edit your layout file as below:

In your Module frontend/layout/catalog_product_view_type_grouped.xml

<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.type">
                <block class="Magento\GroupedProduct\Block\Product\View\Type\Grouped" as="product.info.grouped" template="Namespace_Modulename::availability.phtml"/>

            </referenceContainer>      
        </body>
    </page>

Also update your system as magento 2.0 is having many bugs.

Not in this issue but it may cause errors sometime somewhere as 2.0 is unstable version.

1
-2

For overwriting a phtml file of a module you must put the file in Magento_Modulename/templates/product/view/type/default.phtml.

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.