init
This commit is contained in:
@@ -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