0

I need to override below template file using custom module

Magento_ConfigurableProduct::product/view/type/options/configurable.phtml

2

=> create file under :

app/code/Vendor/Modulename/view/frontend/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.options.configurable">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Vendor_Modulename::product/view/type/options/configurable.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

=> Set your templae file at below location :

app/code/Vendor/Modulename/view/frontend/templates/product/view/type/options/configurable.phtml

Clear cache.

1

Hi I got answers after research. Hope it helps to someone.

Add below code in 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\Swatches\Block\Product\Renderer\Configurable" type="VendorName\Module\Block\Product\Renderer\Configurable" />
</config>

create a Configurable.php at path "app/code/Tm/Stockinfo/Block/Product/Renderer/Configurable.php"and add below code.

<?php

namespace VendorName\Module\Block\Product\Renderer;

class Configurable extends \Magento\Swatches\Block\Product\Renderer\Configurable {
    protected function getRendererTemplate() {
      return $this->isProductHasSwatchAttribute ?
      self::SWATCH_RENDERER_TEMPLATE : 'VendorName_Module::product/view/type/options/configurable.phtml';
   }
}

Create template file "Configurable.phtml". at below location.

app/code/Vendor/Modulename/view/frontend/templates/product/view/type/options/configurable.phtml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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