Hi All,
I try to override Magento_Swatchs renderer.phtml In order to change the way the configurations are displayed and I get an error even with the original Magento file.
Error I get :
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>I simply pasted this file :
app/code/Magento/Swatches/view/frontend/templates/product/layered/renderer.phtml
Here :
app/design/frontend/[VendorName]/[theme]/Magento_Swatches/templates/product/view/renderer.phtml
Content of Renderer.phtml :
<?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="<?= /* @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>
<div class="swatch-opt" data-role="swatch-options"></div>
<script type="text/x-magento-init">
{
"[data-role=swatch-options]": {
"Magento_Swatches/js/swatch-renderer": {
"jsonConfig": <?= /* @escapeNotVerified */ $swatchOptions = $block->getJsonConfig() ?>,
"jsonSwatchConfig": <?php /* @escapeNotVerified */
echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
"mediaCallback": "<?= /* @escapeNotVerified */ $block->getMediaCallback() ?>",
"gallerySwitchStrategy": "<?php /* @escapeNotVerified */ echo $block->getVar('gallery_switch_strategy',
'Magento_ConfigurableProduct') ?: 'replace'; ?>",
"jsonSwatchImageSizeConfig": <?php /* @noEscape */ echo $block->getJsonSwatchSizeConfig() ?>
}
},
"*" : {
"Magento_Swatches/js/catalog-add-to-cart": {}
}
}
</script>
<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>
What I would like to do :
I would like to change the display caused by the "case '2':"
Could someone tell me what I'm doing wrong?
Magento 2.3.1 Community EDITION.
Thanks in advance !
Regards,
Florian