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

forced script text/x-magento-init to get it work #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<design>
<loading_img><![CDATA[]]></loading_img>
<loading_text><![CDATA[<em>Loading products...</em>]]></loading_text>
<done_text></done_text>
<done_text><![CDATA[<em>Congratulations, you've reached the end of the internet.</em>]]></done_text>
<hide_toolbar>1</hide_toolbar>
<local_mode>0</local_mode>
<extra_scroll_px>150</extra_scroll_px>
Expand Down
1 change: 1 addition & 0 deletions etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<module name="Strategery_Infinitescroll" setup_version="0.2.3"/>
<sequence>
<module name="Magento_Catalog"/>
<module name="Magento_Swatches"/>
</sequence>
</config>
13 changes: 13 additions & 0 deletions view/frontend/layout/infinitescroll.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,18 @@
<referenceContainer name="content">
<block class="Strategery\Infinitescroll\Block\Init" name="infinitescroll.init" template="Strategery_Infinitescroll::js.phtml"/>
</referenceContainer>

<!-- @todo: Is possibile to add another block instead of rewrite? -->
<referenceBlock name="category.product.type.details.renderers">
<block class="Magento\Swatches\Block\Product\Renderer\Listing\Configurable"
name="category.product.type.details.renderers.configurable" as="configurable"
template="Strategery_Infinitescroll::product/listing/renderer.phtml"
ifconfig="catalog/frontend/show_swatches_in_product_list">
<arguments>
<argument name="configurable_view_model"
xsi:type="object">Magento\Swatches\ViewModel\Product\Renderer\Configurable</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
61 changes: 61 additions & 0 deletions view/frontend/templates/product/listing/renderer.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
?>
<?php
/** @var $block \Magento\Swatches\Block\Product\Renderer\Listing\Configurable */
$productId = $block->getProduct()->getId();
/** @var \Magento\Swatches\ViewModel\Product\Renderer\Configurable $configurableViewModel */
$configurableViewModel = $block->getConfigurableViewModel()
?>
<div class="swatch-opt-<?= $block->escapeHtmlAttr($productId) ?>"
data-role="swatch-option-<?= $block->escapeHtmlAttr($productId) ?>"></div>

<div class="x-magento-init" style='display:none;'>
{
"[data-role=swatch-option-<?= $block->escapeJs($productId) ?>]": {
"Magento_Swatches/js/swatch-renderer": {
"selectorProduct": ".product-item-details",
"onlySwatches": true,
"enableControlLabel": false,
"numberToShow": <?= $block->escapeJs($block->getNumberSwatchesPerProduct()) ?>,
"jsonConfig": <?= /* @noEscape */ $block->getJsonConfig() ?>,
"jsonSwatchConfig": <?= /* @noEscape */ $block->getJsonSwatchConfig() ?>,
"mediaCallback": "<?= $block->escapeJs($block->escapeUrl($block->getMediaCallback())) ?>",
"jsonSwatchImageSizeConfig": <?= /* @noEscape */ $block->getJsonSwatchSizeConfig() ?>
}
}
}
</div>

<script type="text/x-magento-init">
{
"[data-role=swatch-option-<?= $block->escapeJs($productId) ?>]": {
"Magento_Swatches/js/swatch-renderer": {
"selectorProduct": ".product-item-details",
"onlySwatches": true,
"enableControlLabel": false,
"numberToShow": <?= $block->escapeJs($block->getNumberSwatchesPerProduct()) ?>,
"jsonConfig": <?= /* @noEscape */ $block->getJsonConfig() ?>,
"jsonSwatchConfig": <?= /* @noEscape */ $block->getJsonSwatchConfig() ?>,
"mediaCallback": "<?= $block->escapeJs($block->escapeUrl($block->getMediaCallback())) ?>",
"jsonSwatchImageSizeConfig": <?= /* @noEscape */ $block->getJsonSwatchSizeConfig() ?>
}
}
}
</script>

<script type="text/x-magento-init">
{
"[data-role=priceBox][data-price-box=product-id-<?= $block->escapeJs($productId) ?>]": {
"priceBox": {
"priceConfig": {
"priceFormat": <?= /* @noEscape */ $block->getPriceFormatJson(); ?>,
"prices": <?= /* @noEscape */ $block->getPricesJson(); ?>
}
}
}
}
</script>
6 changes: 6 additions & 0 deletions view/frontend/web/js/infinitescroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ define([
});
window.ias.on('render', function(items){
SgyIAS._log({eventName: 'render', items: items});

$(items).each(function() {
var swatchRender = '<script type="text/x-magento-init">' + $(this).find('.x-magento-init').html() + '</script>';
$(this).find('div[data-role^="swatch-option-"]').append(swatchRender);
});

});
window.ias.on('rendered', function(items){
SgyIAS._log({eventName: 'render', items: items});
Expand Down