Skip to content

Commit f93f18f

Browse files
author
Slabko,Michael(mslabko)
committed
Merge pull request #308 from magento-goinc/pr-308
[SWAT] Bug fixes
2 parents df54675 + 4559c7e commit f93f18f

File tree

4 files changed

+35
-54
lines changed

4 files changed

+35
-54
lines changed

app/code/Magento/Catalog/view/adminhtml/web/js/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ define([
2525
totalItems: 0,
2626
rendered: 0,
2727
template: mageTemplate('#row-template'),
28-
isReadOnly: config.idReadOnly,
28+
isReadOnly: config.isReadOnly,
2929
add: function (data, render) {
3030
var isNewOption = false,
3131
element;

app/code/Magento/Catalog/view/frontend/templates/product/view/attribute.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Product view template
1111
*
12-
* @see \Magento\Catalog\Block\Product\View
12+
* @see \Magento\Catalog\Block\Product\View\Description
1313
*/
1414
?>
1515
<?php

app/code/Magento/Swatches/view/frontend/web/js/SwatchRenderer.js

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,11 @@
66
define([
77
'jquery',
88
'underscore',
9-
'jquery/ui'
9+
'jquery/ui',
10+
'jquery/jquery.parsequery'
1011
], function ($, _) {
1112
'use strict';
1213

13-
/**
14-
* Parse params
15-
* @param {String} query
16-
* @returns {{}}
17-
*/
18-
function parseParams(query) {
19-
var re = /([^&=]+)=?([^&]*)/g,
20-
decodeRE = /\+/g, // Regex for replacing addition symbol with a space
21-
22-
/**
23-
* Return decoded URI component
24-
*
25-
* @param {String} str
26-
* @returns {String}
27-
*/
28-
decode = function (str) {
29-
return decodeURIComponent(str.replace(decodeRE, ' '));
30-
},
31-
params = {},
32-
e,
33-
k,
34-
v;
35-
36-
while ((e = re.exec(query)) != null) {
37-
38-
k = decode(e[1]);
39-
v = decode(e[2]);
40-
41-
if (k.substring(k.length - 2) === '[]') {
42-
k = k.substring(0, k.length - 2);
43-
(params[k] || (params[k] = [])).push(v);
44-
} else {
45-
params[k] = v;
46-
}
47-
}
48-
49-
return params;
50-
}
51-
5214
/**
5315
* Render tooltips by attributes (only to up).
5416
* Required element attributes:
@@ -341,7 +303,8 @@ define([
341303
$widget._Rewind(container);
342304

343305
//Emulate click on all swatches from Request
344-
$widget._EmulateSelected();
306+
$widget._EmulateSelected($.parseQuery());
307+
$widget._EmulateSelected($widget._getSelectedAttributes());
345308
},
346309

347310
/**
@@ -747,7 +710,7 @@ define([
747710
.find('.price-box.price-final_price').attr('data-product-id');
748711
}
749712

750-
additional = parseParams(window.location.search.substring(1));
713+
additional = $.parseQuery();
751714

752715
$widget._XhrKiller();
753716
$widget._EnableProductMediaLoader($this);
@@ -893,18 +856,36 @@ define([
893856

894857
/**
895858
* Emulate mouse click on all swatches that should be selected
896-
*
859+
* @param {Object} [selectedAttributes]
897860
* @private
898861
*/
899-
_EmulateSelected: function () {
900-
var $widget = this,
901-
$this = $widget.element,
902-
request = parseParams(window.location.search.substring(1));
862+
_EmulateSelected: function (selectedAttributes) {
863+
$.each(selectedAttributes, $.proxy(function (attributeCode, optionId) {
864+
this.element.find('.' + this.options.classes.attributeClass +
865+
'[attribute-code="' + attributeCode + '"] [option-id="' + optionId + '"]').trigger('click');
866+
}, this));
867+
},
903868

904-
$.each(request, function (key, value) {
905-
$this.find('.' + $widget.options.classes.attributeClass +
906-
'[attribute-code="' + key + '"] [option-id="' + value + '"]').trigger('click');
907-
});
869+
/**
870+
* Get default options values settings with either URL query parameters
871+
* @private
872+
*/
873+
_getSelectedAttributes: function () {
874+
var hashIndex = window.location.href.indexOf('#'),
875+
selectedAttributes = {},
876+
params;
877+
878+
if (hashIndex !== -1) {
879+
params = $.parseQuery(window.location.href.substr(hashIndex + 1));
880+
881+
selectedAttributes = _.invert(_.mapObject(_.invert(params), function (attributeId) {
882+
var attribute = this.options.jsonConfig.attributes[attributeId];
883+
884+
return attribute ? attribute.code : attributeId;
885+
}.bind(this)));
886+
}
887+
888+
return selectedAttributes;
908889
}
909890
});
910891
});

dev/tests/functional/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"require": {
3-
"magento/mtf": "1.0.0-rc39",
3+
"magento/mtf": "1.0.0-rc40",
44
"php": "~5.5.0|~5.6.0|~7.0.0",
55
"phpunit/phpunit": "4.1.0",
66
"phpunit/phpunit-selenium": ">=1.2"

0 commit comments

Comments
 (0)