Skip to content

Commit f79d673

Browse files
author
Andrii Lugovyi
committed
Merge remote-tracking branch 'goinc/MAGETWO-43891' into prepared-pull-request
2 parents d87bf86 + a1ab4d2 commit f79d673

File tree

20 files changed

+382
-367
lines changed

20 files changed

+382
-367
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
/*jshint browser:true jquery:true expr:true*/
6+
define([
7+
'jquery',
8+
'Magento_Catalog/catalog/type-events',
9+
'Magento_Catalog/js/product/weight-handler'
10+
], function($, productType, weight){
11+
"use strict";
12+
13+
return {
14+
'Magento_Bundle/js/bundle-type-handler': function(data) {
15+
this.bindAll();
16+
this._initType();
17+
},
18+
bindAll: function () {
19+
$(document).on('changeTypeProduct', this._initType.bind(this));
20+
},
21+
_initType: function () {
22+
if (productType.type.real == 'bundle'
23+
&& productType.type.current != 'bundle' && !weight.isLocked()) {
24+
weight.switchWeight();
25+
}
26+
}
27+
};
28+
});

app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -301,25 +301,6 @@ public function getAttributesAllowedForAutogeneration()
301301
return $this->_productHelper->getAttributesAllowedForAutogeneration();
302302
}
303303

304-
/**
305-
* Get data for JS (product type transition)
306-
*
307-
* @return string
308-
*/
309-
public function getTypeSwitcherData()
310-
{
311-
return $this->jsonEncoder->encode(
312-
[
313-
'tab_id' => 'product_info_tabs_downloadable_items',
314-
'weight_switcher' => '[data-role=weight-switcher]',
315-
'product_has_weight_flag' => \Magento\Catalog\Model\Product\Edit\WeightResolver::HAS_WEIGHT,
316-
'weight_id' => 'weight',
317-
'current_type' => $this->getProduct()->getTypeId(),
318-
'attributes' => $this->_getAttributes(),
319-
]
320-
);
321-
}
322-
323304
/**
324305
* Get formed array with attribute codes and Apply To property
325306
*

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit.phtml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@
6161
<script>
6262
require([
6363
"jquery",
64-
"Magento_Catalog/catalog/type-switcher",
64+
"Magento_Catalog/catalog/type-events",
6565
"underscore",
6666
"mage/mage",
6767
"mage/backend/tabs",
6868
"domReady!"
6969
], function($, TypeSwitcher){
7070
var $form = $('[data-form=edit-product]');
71-
$form.data('typeSwitcher', new TypeSwitcher(<?php /* @escapeNotVerified */ echo $block->getTypeSwitcherData();?>).bindAll());
71+
$form.data('typeSwitcher', TypeSwitcher.init());
7272

7373
var scriptTagManager = (function($) {
7474
var hiddenPrefix = 'hidden',
@@ -407,3 +407,11 @@ require([
407407
});
408408
});
409409
</script>
410+
<script type="text/x-magento-init">
411+
{
412+
"*": {
413+
"Magento_Catalog/js/product/weight-handler": {},
414+
"Magento_Catalog/catalog/apply-to-type-switcher": {}
415+
}
416+
}
417+
</script>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
"jquery",
7+
'Magento_Catalog/js/product/weight-handler',
8+
'Magento_Catalog/catalog/type-events'
9+
], function($, weight, productType) {
10+
11+
return {
12+
/**
13+
* Bind event
14+
*/
15+
bindAll: function () {
16+
$('[data-form=edit-product] [data-role=tabs]').on(
17+
'contentUpdated',
18+
this._switchToTypeByApplyAttr.bind(this)
19+
);
20+
21+
$("#product_info_tabs").on(
22+
"beforePanelsMove tabscreate tabsactivate",
23+
this._switchToTypeByApplyAttr.bind(this)
24+
);
25+
26+
$(document).on('changeTypeProduct', this._switchToTypeByApplyAttr.bind(this));
27+
},
28+
29+
'Magento_Catalog/catalog/apply-to-type-switcher': function () {
30+
this.bindAll();
31+
this._switchToTypeByApplyAttr();
32+
},
33+
34+
/**
35+
* Show/hide elements based on type
36+
*
37+
* @private
38+
*/
39+
_switchToTypeByApplyAttr: function() {
40+
$('[data-apply-to]:not(.removed)').each(function(index, element) {
41+
var attrContainer = $(element),
42+
applyTo = attrContainer.data('applyTo') || [];
43+
var $inputs = attrContainer.find('select, input, textarea');
44+
if (applyTo.length === 0 || $.inArray(productType.type.current, applyTo) !== -1) {
45+
attrContainer.removeClass('not-applicable-attribute');
46+
$inputs.removeClass('ignore-validate');
47+
} else {
48+
attrContainer.addClass('not-applicable-attribute');
49+
$inputs.addClass('ignore-validate');
50+
}
51+
});
52+
}
53+
};
54+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'jquery',
7+
'Magento_Catalog/js/product/weight-handler'
8+
], function($, weight) {
9+
10+
return {
11+
$type: $('#product_type_id'),
12+
init: function () {
13+
//todo: need refactoring
14+
if (weight.productHasWeight()) {
15+
this.type = {
16+
virtual: 'virtual',
17+
real: this.$type.val() //simple, configurable
18+
};
19+
} else {
20+
this.type = {
21+
virtual: this.$type.val(), //downloadable, virtual, grouped, bundle
22+
real: 'simple'
23+
};
24+
}
25+
this.type.current = this.$type.val();
26+
27+
this.bindAll();
28+
},
29+
bindAll: function () {
30+
$(document).on('setTypeProduct', function (event, type) {
31+
this.setType(type);
32+
}.bind(this));
33+
34+
//direct change type input
35+
this.$type.on('change', function() {
36+
this.type.current = this.$type.val();
37+
this._notifyType();
38+
}.bind(this));
39+
},
40+
setType: function (type) {
41+
return this.$type.val(type || this.type.real).trigger('change');
42+
},
43+
_notifyType: function () {
44+
$(document).trigger('changeTypeProduct', this.type);
45+
}
46+
};
47+
});

app/code/Magento/Catalog/view/adminhtml/web/catalog/type-switcher.js

Lines changed: 0 additions & 151 deletions
This file was deleted.

app/code/Magento/Catalog/view/adminhtml/web/js/product-gallery.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ define([
373373
selectedClass = 'selected';
374374
parent.toggleClass(selectedClass, $(this).prop('checked'));
375375
});
376-
dialogElement.on('change', '[data-role=type-selector]', $.proxy(this._changeType, this));
376+
dialogElement.on('change', '[data-role=type-selector]', $.proxy(this._notifyType, this));
377377
dialogElement.on('change', '[data-role=visibility-trigger]', $.proxy(function(e) {
378378
this._changeVisibility(e, imageData);
379379
}, this));
@@ -401,7 +401,7 @@ define([
401401
* @param event
402402
* @private
403403
*/
404-
_changeType: function (event) {
404+
_notifyType: function (event) {
405405
var $checkbox = $(event.currentTarget);
406406
var $imageContainer = $checkbox.closest('[data-role=dialog]').data('imageContainer');
407407
this.element.trigger('setImageType', {

0 commit comments

Comments
 (0)