2

I would like to override file :

app/code/Magento/Swatches/view/frontend/templates/product/layered/renderer.phtml

In my own theme :

app/design/frontend/[VendorName]/[theme]/Magento_Swatches/templates/product/layered/renderer.phtml

It does not work. Is it a path problem? Do I copy it in the right place?

I followed this instruction but I think something is wrong for file I want to override : Magento 2 - Override base view file

Thank you in advance for your support.

I'm on Magento 2.3.1

Best regards, Florian

  • path seems correct to me. Please check theme is applied in which you overriding. If you are in production mode, you need to deploy content as well! – Pawan Apr 28 '19 at 6:52
  • Hi @Pawan, Thanks for your comment. The theme is good, and I already deployed content. But problem is still here :( Thanks ! – Jimmy Labuche Apr 28 '19 at 13:43
0

Thanks @ARUNPRABAKARAN-M,

I think this is the good solution cause now I've an error on product page.

Please see below :

1 exception(s):
Exception #0 (Exception): Warning: Invalid argument supplied for foreach() in /var/www/jkcmage/app/design/frontend/Smartwave/porto_child/Magento_Swatches/templates/product/view/renderer.phtml on line 16

Exception #0 (Exception): Warning: Invalid argument supplied for foreach() in /var/www/jkcmage/app/design/frontend/Smartwave/porto_child/Magento_Swatches/templates/product/view/renderer.phtml on line 16
<pre>#1 include() called at [lib/internal/Magento/Framework/View/TemplateEngine/Php.php:59]
#2 Magento\Framework\View\TemplateEngine\Php->render() called at [lib/internal/Magento/Framework/View/Element/Template.php:271]
#3 Magento\Framework\View\Element\Template->fetchView() called at [generated/code/Magento/Swatches/Block/Product/Renderer/Configurable/Interceptor.php:609]
#4 Magento\Swatches\Block\Product\Renderer\Configurable\Interceptor->fetchView() called at [lib/internal/Magento/Framework/View/Element/Template.php:301]
#5 Magento\Framework\View\Element\Template->_toHtml() called at [app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php:461]
#6 Magento\Swatches\Block\Product\Renderer\Configurable->getHtmlOutput() called at [app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php:439]
#7 Magento\Swatches\Block\Product\Renderer\Configurable->_toHtml() called at [lib/internal/Magento/Framework/View/Element/AbstractBlock.php:668]
#8 Magento\Framework\View\Element\AbstractBlock->toHtml() called at [app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php:429]
#9 Magento\Swatches\Block\Product\Renderer\Configurable->toHtml() called at [generated/code/Magento/Swatches/Block/Product/Renderer/Configurable/Interceptor.php:89]
#10 Magento\Swatches\Block\Product\Renderer\Configurable\Interceptor->toHtml() called at [lib/internal/Magento/Framework/View/Layout.php:557]
#11 Magento\Framework\View\Layout->_renderBlock() called at [lib/internal/Magento/Framework/View/Layout.php:533]
#12 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#13 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [lib/internal/Magento/Framework/View/Layout.php:488]
#14 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#15 Magento\Framework\View\Layout\Interceptor->renderElement() called at [lib/internal/Magento/Framework/View/Element/AbstractBlock.php:512]
#16 Magento\Framework\View\Element\AbstractBlock->getChildHtml() called at [generated/code/Magento/Catalog/Block/Product/View/Interceptor.php:778]
#17 Magento\Catalog\Block\Product\View\Interceptor->getChildHtml() called at [app/code/Magento/Catalog/view/frontend/templates/product/view/options/wrapper.phtml:15]
#18 include() called at [lib/internal/Magento/Framework/View/TemplateEngine/Php.php:59]
#19 Magento\Framework\View\TemplateEngine\Php->render() called at [lib/internal/Magento/Framework/View/Element/Template.php:271]
#20 Magento\Framework\View\Element\Template->fetchView() called at [generated/code/Magento/Catalog/Block/Product/View/Interceptor.php:544]
#21 Magento\Catalog\Block\Product\View\Interceptor->fetchView() called at [lib/internal/Magento/Framework/View/Element/Template.php:301]
#22 Magento\Framework\View\Element\Template->_toHtml() called at [lib/internal/Magento/Framework/View/Element/AbstractBlock.php:668]
#23 Magento\Framework\View\Element\AbstractBlock->toHtml() called at [generated/code/Magento/Catalog/Block/Product/View/Interceptor.php:869]
#24 Magento\Catalog\Block\Product\View\Interceptor->toHtml() called at [lib/internal/Magento/Framework/View/Layout.php:557]
#25 Magento\Framework\View\Layout->_renderBlock() called at [lib/internal/Magento/Framework/View/Layout.php:533]
#26 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#27 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [lib/internal/Magento/Framework/View/Layout.php:488]
#28 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#29 Magento\Framework\View\Layout\Interceptor->renderElement() called at [lib/internal/Magento/Framework/View/Element/AbstractBlock.php:543]
#30 Magento\Framework\View\Element\AbstractBlock->getChildChildHtml() called at [generated/code/Magento/Catalog/Block/Product/View/Interceptor.php:791]
#31 Magento\Catalog\Block\Product\View\Interceptor->getChildChildHtml() called at [app/code/Magento/Catalog/view/frontend/templates/product/view/form.phtml:32]
#32 include() called at [lib/internal/Magento/Framework/View/TemplateEngine/Php.php:59]
#33 Magento\Framework\View\TemplateEngine\Php->render() called at [lib/internal/Magento/Framework/View/Element/Template.php:271]
#34 Magento\Framework\View\Element\Template->fetchView() called at [generated/code/Magento/Catalog/Block/Product/View/Interceptor.php:544]
#35 Magento\Catalog\Block\Product\View\Interceptor->fetchView() called at [lib/internal/Magento/Framework/View/Element/Template.php:301]
#36 Magento\Framework\View\Element\Template->_toHtml() called at [lib/internal/Magento/Framework/View/Element/AbstractBlock.php:668]
#37 Magento\Framework\View\Element\AbstractBlock->toHtml() called at [generated/code/Magento/Catalog/Block/Product/View/Interceptor.php:869]
#38 Magento\Catalog\Block\Product\View\Interceptor->toHtml() called at [lib/internal/Magento/Framework/View/Layout.php:557]
#39 Magento\Framework\View\Layout->_renderBlock() called at [lib/internal/Magento/Framework/View/Layout.php:533]
#40 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#41 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [lib/internal/Magento/Framework/View/Layout.php:488]
#42 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#43 Magento\Framework\View\Layout\Interceptor->renderElement() called at [lib/internal/Magento/Framework/View/Layout.php:585]
#44 Magento\Framework\View\Layout->_renderContainer() called at [lib/internal/Magento/Framework/View/Layout.php:535]
#45 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#46 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [lib/internal/Magento/Framework/View/Layout.php:488]
#47 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#48 Magento\Framework\View\Layout\Interceptor->renderElement() called at [lib/internal/Magento/Framework/View/Layout.php:585]
#49 Magento\Framework\View\Layout->_renderContainer() called at [lib/internal/Magento/Framework/View/Layout.php:535]
#50 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#51 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [lib/internal/Magento/Framework/View/Layout.php:488]
#52 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#53 Magento\Framework\View\Layout\Interceptor->renderElement() called at [lib/internal/Magento/Framework/View/Layout.php:585]
#54 Magento\Framework\View\Layout->_renderContainer() called at [lib/internal/Magento/Framework/View/Layout.php:535]
#55 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#56 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [lib/internal/Magento/Framework/View/Layout.php:488]
#57 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#58 Magento\Framework\View\Layout\Interceptor->renderElement() called at [lib/internal/Magento/Framework/View/Layout.php:585]
#59 Magento\Framework\View\Layout->_renderContainer() called at [lib/internal/Magento/Framework/View/Layout.php:535]
#60 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#61 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [lib/internal/Magento/Framework/View/Layout.php:488]
#62 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#63 Magento\Framework\View\Layout\Interceptor->renderElement() called at [lib/internal/Magento/Framework/View/Layout.php:585]
#64 Magento\Framework\View\Layout->_renderContainer() called at [lib/internal/Magento/Framework/View/Layout.php:535]
#65 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#66 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [lib/internal/Magento/Framework/View/Layout.php:488]
#67 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#68 Magento\Framework\View\Layout\Interceptor->renderElement() called at [lib/internal/Magento/Framework/View/Layout.php:585]
#69 Magento\Framework\View\Layout->_renderContainer() called at [lib/internal/Magento/Framework/View/Layout.php:535]
#70 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#71 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [lib/internal/Magento/Framework/View/Layout.php:488]
#72 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#73 Magento\Framework\View\Layout\Interceptor->renderElement() called at [lib/internal/Magento/Framework/View/Layout.php:585]
#74 Magento\Framework\View\Layout->_renderContainer() called at [lib/internal/Magento/Framework/View/Layout.php:535]
#75 Magento\Framework\View\Layout->renderNonCachedElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:206]
#76 Magento\Framework\View\Layout\Interceptor->renderNonCachedElement() called at [lib/internal/Magento/Framework/View/Layout.php:488]
#77 Magento\Framework\View\Layout->renderElement() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:193]
#78 Magento\Framework\View\Layout\Interceptor->renderElement() called at [lib/internal/Magento/Framework/View/Layout.php:954]
#79 Magento\Framework\View\Layout->getOutput() called at [lib/internal/Magento/Framework/Interception/Interceptor.php:58]
#80 Magento\Framework\View\Layout\Interceptor->___callParent() called at [lib/internal/Magento/Framework/Interception/Interceptor.php:138]
#81 Magento\Framework\View\Layout\Interceptor->Magento\Framework\Interception\{closure}() called at [lib/internal/Magento/Framework/Interception/Interceptor.php:153]
#82 Magento\Framework\View\Layout\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:494]
#83 Magento\Framework\View\Layout\Interceptor->getOutput() called at [lib/internal/Magento/Framework/View/Result/Page.php:258]
#84 Magento\Framework\View\Result\Page->render() called at [lib/internal/Magento/Framework/View/Result/Layout.php:171]
#85 Magento\Framework\View\Result\Layout->renderResult() called at [lib/internal/Magento/Framework/Interception/Interceptor.php:58]
#86 Magento\Framework\View\Result\Page\Interceptor->___callParent() called at [lib/internal/Magento/Framework/Interception/Interceptor.php:138]
#87 Magento\Framework\View\Result\Page\Interceptor->Magento\Framework\Interception\{closure}() called at [lib/internal/Magento/Framework/Interception/Interceptor.php:153]
#88 Magento\Framework\View\Result\Page\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/View/Result/Page/Interceptor.php:130]
#89 Magento\Framework\View\Result\Page\Interceptor->renderResult() called at [lib/internal/Magento/Framework/App/Http.php:140]
#90 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:24]
#91 Magento\Framework\App\Http\Interceptor->launch() called at [lib/internal/Magento/Framework/App/Bootstrap.php:258]
#92 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:40]
</pre>

It seems that for override this file, something is still missing.

The renderer.phtml file I want override is currently the same as the original. Here is the content:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/** @var $block \Magento\Swatches\Block\LayeredNavigation\RenderLayered */
?>
<?php $swatchData = $block->getSwatchData(); ?>
<div class="swatch-attribute swatch-layered <?= /* @escapeNotVerified */ $swatchData['attribute_code'] ?>"
     attribute-code="<?= /* @escapeNotVerified */ $swatchData['attribute_code'] ?>"
     attribute-id="<?= /* @escapeNotVerified */ $swatchData['attribute_id'] ?>">
    <div class="swatch-attribute-options clearfix">
        <?php foreach ($swatchData['options'] as $option => $label): ?>
            <a href="<?= /* @escapeNotVerified */ $label['link'] ?>"
               aria-label="<?= /* @escapeNotVerified */ $label['label'] ?>"
               class="swatch-option-link-layered">
                <?php if (isset($swatchData['swatches'][$option]['type'])) { ?>
                    <?php switch ($swatchData['swatches'][$option]['type']) {
                        case '3':
                            ?>
                            <div class="swatch-option <?= /* @escapeNotVerified */ $label['custom_style'] ?>"
                                 tabindex="-1"
                                 option-type="3"
                                 option-id="<?= /* @escapeNotVerified */ $option ?>"
                                 option-label="<?= /* @escapeNotVerified */ $label['label'] ?>"
                                 option-tooltip-thumb=""
                                 option-tooltip-value=""
                                ></div>
                            <?php    break;
                        case '2':
                            ?>
                            <?php $swatchThumbPath = $block->getSwatchPath('swatch_thumb',
                            $swatchData['swatches'][$option]['value']); ?>
                            <?php $swatchImagePath = $block->getSwatchPath('swatch_image',
                            $swatchData['swatches'][$option]['value']); ?>
                            <div class="swatch-option image <?= /* @escapeNotVerified */ $label['custom_style'] ?>"
                                 tabindex="-1"
                                 option-type="2"
                                 option-id="<?= /* @escapeNotVerified */ $option ?>"
                                 option-label="BB<?= /* @escapeNotVerified */ $label['label'] ?>"
                                 option-tooltip-thumb="<?= /* @escapeNotVerified */ $swatchThumbPath ?>"
                                 option-tooltip-value=""
                                 style="background: url(<?= /* @escapeNotVerified */ $swatchImagePath ?>) no-repeat center; background-size: initial;"></div>
                            <?php    break;
                        case '1':
                            ?>
                            <div class="swatch-option color <?= /* @escapeNotVerified */ $label['custom_style'] ?>"
                                 tabindex="-1"
                                 option-type="1"
                                 option-id="<?= /* @escapeNotVerified */ $option ?>"
                                 option-label="<?= /* @escapeNotVerified */ $label['label'] ?>"
                                 option-tooltip-thumb=""
                                 option-tooltip-value="<?= /* @escapeNotVerified */ $swatchData['swatches'][$option]['value'] ?>"
                                 style="background: <?= /* @escapeNotVerified */ $swatchData['swatches'][$option]['value'] ?> no-repeat center; background-size: initial;"></div>
                            <?php    break;
                        case '0':
                        default:
                            ?>
                                <div class="swatch-option text <?= /* @escapeNotVerified */ $label['custom_style'] ?>"
                                     tabindex="-1"
                                     option-type="0"
                                     option-id="<?= /* @escapeNotVerified */ $option ?>"
                                     option-label="<?= /* @escapeNotVerified */ $label['label'] ?>"
                                     option-tooltip-thumb=""
                                     option-tooltip-value=""
                                    ><?= /* @escapeNotVerified */ $swatchData['swatches'][$option]['value'] ?></div>
                            <?php    break;
                    } ?>
                <?php } ?>
            </a>
        <?php endforeach; ?>
    </div>
</div>

<script>
    require(["jquery", "jquery/ui", "Magento_Swatches/js/swatch-renderer"], function ($) {
        $('.swatch-layered.<?= /* @escapeNotVerified */ $swatchData['attribute_code'] ?>')
            .find('[option-type="1"], [option-type="2"], [option-type="0"], [option-type="3"]')
            .SwatchRendererTooltip();
    });
</script>

I would like to modify the "case '2'".

How can I proceed ? I suppose I have to import this file in renderer.phtml : \Magento\Swatches\Block\LayeredNavigation\RenderLayered

But I would like to do it by the better way.

Thanks !

| improve this answer | |
  • You're telling me that their is a syntax error.... But this is the original file from magento Core. Can you please tell me more cause I don't see the error here. – Jimmy Labuche May 12 '19 at 18:42

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.