Skip to content

Commit 1350c77

Browse files
authored
Issues magento#10559 -Extend swatch using mixins
For Magento 2.2
1 parent 9e5f7c4 commit 1350c77

File tree

1 file changed

+26
-29
lines changed
  • app/code/Magento/Swatches/view/frontend/templates/product/listing

1 file changed

+26
-29
lines changed

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

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,33 @@
55
*/
66
?>
77
<?php /** @var $block \Magento\Swatches\Block\Product\Renderer\Listing\Configurable */ ?>
8-
<div class="swatch-opt-<?= /* @escapeNotVerified */ $block->getProduct()->getId() ?>"></div>
9-
<script>
10-
require([
11-
'jquery',
12-
'jquery/ui',
13-
'Magento_Swatches/js/swatch-renderer',
14-
'Magento_Swatches/js/catalog-add-to-cart',
15-
'priceBox'
16-
], function ($) {
17-
var jsonConfig = <?= /* @escapeNotVerified */ $block->getJsonConfig() ?>;
8+
<div class="swatch-opt-<?= /* @escapeNotVerified */ $block->getProduct()->getId() ?>" data-role="swatch-option-<?= /* @escapeNotVerified */ $block->getProduct()->getId() ?>"></div>
189

19-
$('.swatch-opt-<?= /* @escapeNotVerified */ $block->getProduct()->getId() ?>').SwatchRenderer({
20-
selectorProduct: '.product-item-details',
21-
onlySwatches: true,
22-
enableControlLabel: false,
23-
numberToShow: <?= /* @escapeNotVerified */ $block->getNumberSwatchesPerProduct() ?>,
24-
jsonConfig: jsonConfig,
25-
jsonSwatchConfig: <?= /* @escapeNotVerified */ $block->getJsonSwatchConfig() ?>,
26-
mediaCallback: '<?= /* @escapeNotVerified */ $block->getMediaCallback() ?>'
27-
});
28-
29-
var dataPriceBoxSelector = '[data-role=priceBox]',
30-
dataProductIdSelector = '[data-product-id=<?= $block->escapeHtml($block->getProduct()->getId()) ?>]',
31-
priceBoxes = $(dataPriceBoxSelector + dataProductIdSelector);
10+
<script type="text/x-magento-init">
11+
{
12+
"[data-role=swatch-option-<?= /* @escapeNotVerified */ $block->getProduct()->getId() ?>]": {
13+
"Magento_Swatches/js/swatch-renderer": {
14+
"selectorProduct": ".product-item-details",
15+
"onlySwatches": true,
16+
"enableControlLabel": false,
17+
"numberToShow": <?= /* @escapeNotVerified */ $block->getNumberSwatchesPerProduct(); ?>,
18+
"jsonConfig": <?= /* @escapeNotVerified */ $block->getJsonConfig(); ?>,
19+
"jsonSwatchConfig": <?= /* @escapeNotVerified */ $block->getJsonSwatchConfig(); ?>,
20+
"mediaCallback": "<?= /* @escapeNotVerified */ $block->getMediaCallback() ?>"
21+
}
22+
}
23+
}
24+
</script>
3225

33-
priceBoxes.priceBox({
34-
'priceConfig': {
35-
priceFormat: jsonConfig.priceFormat,
36-
prices: jsonConfig.prices
26+
<script type="text/x-magento-init">
27+
{
28+
"[data-role=priceBox][data-price-box=product-id-<?= $block->escapeHtml($block->getProduct()->getId()) ?>]": {
29+
"priceBox": {
30+
"priceConfig": {
31+
"priceFormat": <?= $block->getPriceFormatJson(); ?>,
32+
"prices": <?= $block->getPricesJson(); ?>
33+
}
3734
}
38-
});
39-
});
35+
}
36+
}
4037
</script>

0 commit comments

Comments
 (0)