init
This commit is contained in:
+121
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
// phpcs:disable PSR2.ControlStructures.SwitchDeclaration
|
||||
// phpcs:disable Generic.WhiteSpace.ScopeIndent
|
||||
|
||||
/** @var $block \Magento\Swatches\Block\LayeredNavigation\RenderLayered */
|
||||
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
|
||||
/** @var \Magento\Framework\Escaper $escaper */
|
||||
?>
|
||||
<?php $swatchData = $block->getSwatchData(); ?>
|
||||
<div class="swatch-attribute swatch-layered <?= $block->escapeHtmlAttr($swatchData['attribute_code']) ?>"
|
||||
data-attribute-code="<?= $block->escapeHtmlAttr($swatchData['attribute_code']) ?>"
|
||||
data-attribute-id="<?= $block->escapeHtmlAttr($swatchData['attribute_id']) ?>">
|
||||
<div class="swatch-attribute-options clearfix">
|
||||
<?php foreach ($swatchData['options'] as $option => $label): ?>
|
||||
<a href="<?= $block->escapeUrl($label['link']) ?>" rel="nofollow"
|
||||
aria-label="<?= $block->escapeHtmlAttr($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 <?= $block->escapeHtmlAttr($label['custom_style']) ?>"
|
||||
tabindex="-1"
|
||||
data-option-type="3"
|
||||
data-option-id="<?= $block->escapeHtmlAttr($option) ?>"
|
||||
data-option-label="<?= $block->escapeHtmlAttr($label['label']) ?>"
|
||||
data-option-tooltip-thumb=""
|
||||
data-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']
|
||||
);
|
||||
$escapedUrl = $block->escapeUrl($swatchImagePath);
|
||||
?>
|
||||
<div class="swatch-option image <?= $block->escapeHtmlAttr($label['custom_style']) ?>"
|
||||
tabindex="-1"
|
||||
data-option-type="2"
|
||||
data-option-id="<?= $block->escapeHtmlAttr($option) ?>"
|
||||
data-option-label="<?= $block->escapeHtmlAttr($label['label']) ?>"
|
||||
data-option-tooltip-thumb="<?= $block->escapeUrl($swatchThumbPath) ?>"
|
||||
data-option-tooltip-value="">
|
||||
</div>
|
||||
<?php
|
||||
$element = 'swatchImageOption' . $escaper->escapeJs($option);
|
||||
$script = 'var ' . $element
|
||||
. ' = document.querySelector(\'div[data-option-id="' . $escaper->escapeJs($option)
|
||||
. '"]\');' . PHP_EOL;
|
||||
$script .= $element . '.style.background = "url(\''
|
||||
. $escapedUrl . '\') no-repeat center";' . PHP_EOL;
|
||||
$script .= $element . '.style.backgroundSize = "initial";';
|
||||
?>
|
||||
<?= /* @noEscape*/ $secureRenderer->renderTag('script', [], $script, false); ?>
|
||||
<?php break;
|
||||
case '1':
|
||||
?>
|
||||
<div class="swatch-option color <?= $block->escapeHtmlAttr($label['custom_style']) ?>"
|
||||
tabindex="-1"
|
||||
data-option-type="1"
|
||||
data-option-id="<?= $block->escapeHtmlAttr($option) ?>"
|
||||
data-option-label="<?= $block->escapeHtmlAttr($label['label']) ?>"
|
||||
data-option-tooltip-thumb=""
|
||||
data-option-tooltip-value="<?= $block->escapeHtmlAttr(
|
||||
$swatchData['swatches'][$option]['value']
|
||||
) ?>">
|
||||
</div>
|
||||
<?php
|
||||
$element = 'swatchImageOption' . $escaper->escapeJs($option);
|
||||
$backgroundValue = isset($swatchData['swatches'][$option]['value']) ? $escaper->escapeJs(
|
||||
str_replace('\'', '\\\'', $swatchData['swatches'][$option]['value'])
|
||||
) : '';
|
||||
$script = 'var ' . $element
|
||||
. ' = document.querySelector(\'div[data-option-id="' . $escaper->escapeJs($option)
|
||||
. '"]\');' . PHP_EOL;
|
||||
$script .= $element . '.style.background = "' . $backgroundValue
|
||||
. ' no-repeat center";' . PHP_EOL;
|
||||
$script .= $element . '.style.backgroundSize = "initial";';
|
||||
?>
|
||||
<?= /* @noEscape*/ $secureRenderer->renderTag('script', [], $script, false); ?>
|
||||
<?php break;
|
||||
case '0':
|
||||
default:
|
||||
?>
|
||||
<div class="swatch-option text <?= $block->escapeHtmlAttr($label['custom_style']) ?>"
|
||||
tabindex="-1"
|
||||
data-option-type="0"
|
||||
data-option-id="<?= $block->escapeHtmlAttr($option) ?>"
|
||||
data-option-label="<?= $block->escapeHtmlAttr($label['label']) ?>"
|
||||
data-option-tooltip-thumb=""
|
||||
data-option-tooltip-value=""
|
||||
><?= $block->escapeHtml($swatchData['swatches'][$option]['value']) ?></div>
|
||||
<?php break;
|
||||
} ?>
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php $scriptString = <<<script
|
||||
|
||||
require(["jquery", "Magento_Swatches/js/swatch-renderer"], function ($) {
|
||||
$('.swatch-layered.{$block->escapeJs($swatchData['attribute_code'])}')
|
||||
.find('[data-option-type="1"], [data-option-type="2"], [data-option-type="0"], [data-option-type="3"]')
|
||||
.SwatchRendererTooltip();
|
||||
});
|
||||
|
||||
script;
|
||||
?>
|
||||
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Swatches\Block\Product\Renderer\Listing\Configurable;
|
||||
use Magento\Swatches\ViewModel\Product\Renderer\Configurable as ConfigurableViewModel;
|
||||
|
||||
/** @var Configurable $block */
|
||||
/** @var Product $product */
|
||||
$product = $block->getProduct()
|
||||
?>
|
||||
<?php if ($product && $product->isAvailable()): ?>
|
||||
<?php $productId = $product->getId() ?>
|
||||
<?php /** @var ConfigurableViewModel $configurableViewModel */ ?>
|
||||
<?php $configurableViewModel = $block->getConfigurableViewModel() ?>
|
||||
<div class="swatch-opt-<?= $block->escapeHtmlAttr($productId) ?>"
|
||||
data-role="swatch-option-<?= $block->escapeHtmlAttr($productId) ?>"></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() ?>,
|
||||
"showTooltip": <?= $block->escapeJs($configurableViewModel->getShowSwatchTooltip()) ?>
|
||||
}
|
||||
}
|
||||
}
|
||||
</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>
|
||||
<?php endif; ?>
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
?>
|
||||
<?php
|
||||
/** @var $block \Magento\Swatches\Block\Product\Renderer\Configurable */
|
||||
/** @var \Magento\Swatches\ViewModel\Product\Renderer\Configurable $configurableViewModel */
|
||||
$configurableViewModel = $block->getConfigurableViewModel()
|
||||
?>
|
||||
<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": <?= /* @noEscape */ $swatchOptions = $block->getJsonConfig() ?>,
|
||||
"jsonSwatchConfig": <?= /* @noEscape */ $swatchOptions = $block->getJsonSwatchConfig() ?>,
|
||||
"mediaCallback": "<?= $block->escapeJs($block->escapeUrl($block->getMediaCallback())) ?>",
|
||||
"gallerySwitchStrategy": "<?= $block->escapeJs($block->getVar('gallery_switch_strategy', 'Magento_ConfigurableProduct')) ?: 'replace'; ?>",
|
||||
"jsonSwatchImageSizeConfig": <?= /* @noEscape */ $block->getJsonSwatchSizeConfig() ?>,
|
||||
"showTooltip": <?= $block->escapeJs($configurableViewModel->getShowSwatchTooltip()) ?>
|
||||
}
|
||||
},
|
||||
"*" : {
|
||||
"Magento_Swatches/js/catalog-add-to-cart": {}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
require([
|
||||
'jquery'
|
||||
], function ($) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Add selected swatch attributes to redirect url
|
||||
*
|
||||
* @see Magento_Catalog/js/catalog-add-to-cart
|
||||
*/
|
||||
$('body').on('catalogCategoryAddToCartRedirect', function (event, data) {
|
||||
$(data.form).find('[name*="super"]').each(function (index, item) {
|
||||
var $item = $(item),
|
||||
attr;
|
||||
|
||||
if ($item.attr('data-attr-name')) {
|
||||
attr = $item.attr('data-attr-name');
|
||||
} else {
|
||||
attr = $item.parent().attr('attribute-code');
|
||||
}
|
||||
data.redirectParameters.push(attr + '=' + $item.val());
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
require([
|
||||
'jquery',
|
||||
'Magento_ConfigurableProduct/js/options-updater'
|
||||
], function ($, Updater) {
|
||||
'use strict';
|
||||
|
||||
var selectors = {
|
||||
formSelector: '#product_addtocart_form',
|
||||
swatchSelector: '.swatch-opt'
|
||||
},
|
||||
swatchWidgetName = 'mage-SwatchRenderer',
|
||||
widgetInitEvent = 'swatch.initialized',
|
||||
|
||||
/**
|
||||
* Sets all configurable swatch attribute's selected values
|
||||
*/
|
||||
updateSwatchOptions = function () {
|
||||
var swatchWidget = $(selectors.swatchSelector).data(swatchWidgetName);
|
||||
|
||||
if (!swatchWidget || !swatchWidget._EmulateSelectedByAttributeId) {
|
||||
return;
|
||||
}
|
||||
swatchWidget._EmulateSelectedByAttributeId(this.productOptions);
|
||||
},
|
||||
updater = new Updater(widgetInitEvent, updateSwatchOptions);
|
||||
|
||||
updater.listen();
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user