0

I need to override below template file using custom module

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

Nikolas
2,31113 silver badges17 bronze badges
asked Apr 3, 2018 at 6:30

2 Answers 2

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.

Rohan Hapani
17.6k9 gold badges57 silver badges99 bronze badges
answered Apr 3, 2018 at 6:34
2
  • Thanks Rakesh for your answers. i applied this solution and its not override, please refer this link github.com/magento/magento2/issues/4400 Commented Apr 3, 2018 at 7:04
  • try with above solutions in default.xml instead of catalog_product_view_type_configurable.xml file Commented Apr 3, 2018 at 7:05
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

answered Apr 3, 2018 at 7:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.