Skip to content

Commit

Permalink
Merge pull request #308 from magento-goinc/pr-308
Browse files Browse the repository at this point in the history
[SWAT] Bug fixes
  • Loading branch information
Slabko,Michael(mslabko) committed Jan 20, 2016
2 parents df54675 + 4559c7e commit f93f18f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 54 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/view/adminhtml/web/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ define([
totalItems: 0,
rendered: 0,
template: mageTemplate('#row-template'),
isReadOnly: config.idReadOnly,
isReadOnly: config.isReadOnly,
add: function (data, render) {
var isNewOption = false,
element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Product view template
*
* @see \Magento\Catalog\Block\Product\View
* @see \Magento\Catalog\Block\Product\View\Description
*/
?>
<?php
Expand Down
83 changes: 32 additions & 51 deletions app/code/Magento/Swatches/view/frontend/web/js/SwatchRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,11 @@
define([
'jquery',
'underscore',
'jquery/ui'
'jquery/ui',
'jquery/jquery.parsequery'
], function ($, _) {
'use strict';

/**
* Parse params
* @param {String} query
* @returns {{}}
*/
function parseParams(query) {
var re = /([^&=]+)=?([^&]*)/g,
decodeRE = /\+/g, // Regex for replacing addition symbol with a space

/**
* Return decoded URI component
*
* @param {String} str
* @returns {String}
*/
decode = function (str) {
return decodeURIComponent(str.replace(decodeRE, ' '));
},
params = {},
e,
k,
v;

while ((e = re.exec(query)) != null) {

k = decode(e[1]);
v = decode(e[2]);

if (k.substring(k.length - 2) === '[]') {
k = k.substring(0, k.length - 2);
(params[k] || (params[k] = [])).push(v);
} else {
params[k] = v;
}
}

return params;
}

/**
* Render tooltips by attributes (only to up).
* Required element attributes:
Expand Down Expand Up @@ -341,7 +303,8 @@ define([
$widget._Rewind(container);

//Emulate click on all swatches from Request
$widget._EmulateSelected();
$widget._EmulateSelected($.parseQuery());
$widget._EmulateSelected($widget._getSelectedAttributes());
},

/**
Expand Down Expand Up @@ -747,7 +710,7 @@ define([
.find('.price-box.price-final_price').attr('data-product-id');
}

additional = parseParams(window.location.search.substring(1));
additional = $.parseQuery();

$widget._XhrKiller();
$widget._EnableProductMediaLoader($this);
Expand Down Expand Up @@ -893,18 +856,36 @@ define([

/**
* Emulate mouse click on all swatches that should be selected
*
* @param {Object} [selectedAttributes]
* @private
*/
_EmulateSelected: function () {
var $widget = this,
$this = $widget.element,
request = parseParams(window.location.search.substring(1));
_EmulateSelected: function (selectedAttributes) {
$.each(selectedAttributes, $.proxy(function (attributeCode, optionId) {
this.element.find('.' + this.options.classes.attributeClass +
'[attribute-code="' + attributeCode + '"] [option-id="' + optionId + '"]').trigger('click');
}, this));
},

$.each(request, function (key, value) {
$this.find('.' + $widget.options.classes.attributeClass +
'[attribute-code="' + key + '"] [option-id="' + value + '"]').trigger('click');
});
/**
* Get default options values settings with either URL query parameters
* @private
*/
_getSelectedAttributes: function () {
var hashIndex = window.location.href.indexOf('#'),
selectedAttributes = {},
params;

if (hashIndex !== -1) {
params = $.parseQuery(window.location.href.substr(hashIndex + 1));

selectedAttributes = _.invert(_.mapObject(_.invert(params), function (attributeId) {
var attribute = this.options.jsonConfig.attributes[attributeId];

return attribute ? attribute.code : attributeId;
}.bind(this)));
}

return selectedAttributes;
}
});
});
2 changes: 1 addition & 1 deletion dev/tests/functional/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"magento/mtf": "1.0.0-rc39",
"magento/mtf": "1.0.0-rc40",
"php": "~5.5.0|~5.6.0|~7.0.0",
"phpunit/phpunit": "4.1.0",
"phpunit/phpunit-selenium": ">=1.2"
Expand Down

0 comments on commit f93f18f

Please sign in to comment.