Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable option renderer template override is not possible #4400

Closed
yagneshponkiya opened this issue May 4, 2016 · 12 comments
Closed

Configurable option renderer template override is not possible #4400

yagneshponkiya opened this issue May 4, 2016 · 12 comments
Labels
bug report Component: Catalog Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@yagneshponkiya
Copy link

yagneshponkiya commented May 4, 2016

Steps to reproduce

  1. Have Created custom module to override Magento_ConfigurableProduct::product/view/type/options/configurable.phtml using module.
    2.Llayout code in catalog_product_view_type_configurable.xml

<referenceBlock name="product.info.options.configurable"> <action method="setTemplate"> <argument name='template' xsi:type="string">Namespace_ModuleName::product/view/type/options/configurable.phtml</argument> </action> </referenceBlock>
3 After lot of struggling i was not able to override template file because of below code in

Magento\Swatches\Block\Product\Renderer\Configurable

class Configurable extends \Magento\ConfigurableProduct\Block\Product\View\Type\Configurable
{
    /**
     * Path to template file with Swatch renderer.
     */
    const SWATCH_RENDERER_TEMPLATE = "Magento_Swatches::product/view/renderer.phtml";

    /**
     * Path to default template file with standard Configurable renderer.
     */
    const CONFIGURABLE_RENDERER_TEMPLATE = "Magento_ConfigurableProduct::product/view/type/options/configurable.phtml";
/**
     * @codeCoverageIgnore
     * @return string
     */
    protected function getRendererTemplate()
    {
        return $this->isProductHasSwatchAttribute ?
            self::SWATCH_RENDERER_TEMPLATE : self::CONFIGURABLE_RENDERER_TEMPLATE;
    }

Above constant doesn't allow me to override template how should i do that ?

@mkastaneda
Copy link

Override Magento\Swatches\Block\Product\Renderer\Configurable via plugin. Use method beforeSetTemplate.

http://magento.stackexchange.com/questions/98636/update-const-template-at-magento-2-class

@yagneshponkiya
Copy link
Author

Thank you for the updates, Yes, i already did that.

Look at the below code written in xml, Below code is of no use. It should allow to override template using xml as template path is defined in xml. don't you think so ?

vendor/magento/module-configurable-product/view/frontend/layout/catalog_product_view_type_configurable.xml

 <referenceBlock name="product.info.options.wrapper">
            <block class="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable" name="product.info.options.configurable" as="options_configurable" before="-" template="product/view/type/options/configurable.phtml"/>
        </referenceBlock>

@mkastaneda
Copy link

mkastaneda commented May 18, 2016

Correct, since the template filename is harcoded as a class property, it seems to override any xml update. I do think hardcoding that into core files is not the best practice, however, plugins certainly give the ability to modify that behavior with no major issues.

This should be either well documented or removed because what if a front-end developer comes up with this issue ? his gonna have a hard time on this one. Overriding templates should be always possible via XML I agree with you.

Good luck !

@yagneshponkiya
Copy link
Author

Thanks, Can we expect these changes in upcoming release ?

@4DallasC
Copy link

4DallasC commented May 24, 2016

Hello @mkastaneda

I've got a similar problem in vendor\magento\module-catalog\view\adminhtml\layout\CATALOG_PRODUCT_COMPOSITE_CONFIGURE.xml

where someone forgot to add the name for the block:-

<block class="Magento\Catalog\Block\Adminhtml\Product\Composite\Fieldset\Options" template="catalog/product/composite/fieldset/options.phtml">
.....
</block>

and I can't reference it in my extension's layout.

Can someone please add a name.

@cparadigm
Copy link

cparadigm commented Jul 31, 2017

Same issue can't override:

catalog\view\adminhtml\layout\CATALOG_PRODUCT_COMPOSITE_CONFIGURE.xml

Please fix this issue, it's super quick to fix and causes big problems. Now as a work around I have to write ugly overrides to have my changes.

@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Component: Catalog Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Sep 11, 2017
@magento-engcom-team
Copy link
Contributor

@YaguPatel, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.
We tested the issue on 2.3.0-dev, 2.2.0, 2.1.9

@magento-engcom-team magento-engcom-team added the Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch label Dec 12, 2017
@rparsi-commer
Copy link

@magento-engcom-team I reproduced the issue using CE edition version 2.1.10
Due to the hard coded template path here
\Magento\Swatches\Block\Product\Renderer\Configurable class - line 41

you can't override the Magento_ConfigurableProduct::product/view/type/options/configurable.phtml
template in custom modules using the typical layout/template override mechanism.
I had to create a Plugin class as indicated by @mkastaneda

Why does this Magento module use hard coded template paths?
Will this be changed in future releases?
These hard coded paths are annoying to deal with for developers.

@MikeSheward
Copy link

Confirmed this is still an issue on Magento 2 CE 2.2.3

taskula pushed a commit to Hypernova-Oy/magento2 that referenced this issue Jun 25, 2019
[Magento Community Engineering] Community Contributions - GraphQL
@nkarthickannan
Copy link

@magento-engcom-team How can I reopen this issue? The problem is still there in Magento Open Source 2.3.3.

@OvalMedia
Copy link

Still not fixed in 2.4.2.

@OvalMedia
Copy link

Still not fixed in 2.4.7-p1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Catalog Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests