Skip to content

Commit 7a9a105

Browse files
author
Oleksii Korshenko
committed
Merge remote-tracking branch 'goinc/prepared-pull-request' into magento2
2 parents 6c380aa + 8bd17ea commit 7a9a105

File tree

37 files changed

+912
-447
lines changed

37 files changed

+912
-447
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
15+
/**
16+
* Constructor component
17+
*/
18+
'Magento_Bundle/js/bundle-type-handler': function () {
19+
this.bindAll();
20+
this._initType();
21+
},
22+
23+
/**
24+
* Bind all
25+
*/
26+
bindAll: function () {
27+
$(document).on('changeTypeProduct', this._initType.bind(this));
28+
},
29+
30+
/**
31+
* Init type
32+
* @private
33+
*/
34+
_initType: function () {
35+
if (
36+
productType.type.real === 'bundle' &&
37+
productType.type.current !== 'bundle' &&
38+
!weight.isLocked()
39+
) {
40+
weight.switchWeight();
41+
}
42+
}
43+
};
44+
});

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: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
'use strict';
11+
12+
return {
13+
14+
/**
15+
* Bind event
16+
*/
17+
bindAll: function () {
18+
$('[data-form=edit-product] [data-role=tabs]').on(
19+
'contentUpdated',
20+
this._switchToTypeByApplyAttr.bind(this)
21+
);
22+
23+
$('#product_info_tabs').on(
24+
'beforePanelsMove tabscreate tabsactivate',
25+
this._switchToTypeByApplyAttr.bind(this)
26+
);
27+
28+
$(document).on('changeTypeProduct', this._switchToTypeByApplyAttr.bind(this));
29+
},
30+
31+
/**
32+
* Constructor component
33+
*/
34+
'Magento_Catalog/catalog/apply-to-type-switcher': function () {
35+
this.bindAll();
36+
this._switchToTypeByApplyAttr();
37+
},
38+
39+
/**
40+
* Show/hide elements based on type
41+
*
42+
* @private
43+
*/
44+
_switchToTypeByApplyAttr: function () {
45+
$('[data-apply-to]:not(.removed)').each(function (index, element) {
46+
var attrContainer = $(element),
47+
applyTo = attrContainer.data('applyTo') || [],
48+
$inputs = attrContainer.find('select, input, textarea');
49+
50+
if (applyTo.length === 0 || $.inArray(productType.type.current, applyTo) !== -1) {
51+
attrContainer.removeClass('not-applicable-attribute');
52+
$inputs.removeClass('ignore-validate');
53+
} else {
54+
attrContainer.addClass('not-applicable-attribute');
55+
$inputs.addClass('ignore-validate');
56+
}
57+
});
58+
}
59+
};
60+
});
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
'use strict';
10+
11+
return {
12+
$type: $('#product_type_id'),
13+
14+
/**
15+
* Init
16+
*/
17+
init: function () {
18+
19+
if (weight.productHasWeight()) {
20+
this.type = {
21+
virtual: 'virtual',
22+
real: this.$type.val() //simple, configurable
23+
};
24+
} else {
25+
this.type = {
26+
virtual: this.$type.val(), //downloadable, virtual, grouped, bundle
27+
real: 'simple'
28+
};
29+
}
30+
this.type.current = this.$type.val();
31+
32+
this.bindAll();
33+
},
34+
35+
/**
36+
* Bind all
37+
*/
38+
bindAll: function () {
39+
$(document).on('setTypeProduct', function (event, type) {
40+
this.setType(type);
41+
}.bind(this));
42+
43+
//direct change type input
44+
this.$type.on('change', function () {
45+
this.type.current = this.$type.val();
46+
this._notifyType();
47+
}.bind(this));
48+
},
49+
50+
/**
51+
* Set type
52+
* @param {String} type - type product (downloadable, simple, virtual ...)
53+
* @returns {*}
54+
*/
55+
setType: function (type) {
56+
return this.$type.val(type || this.type.real).trigger('change');
57+
},
58+
59+
/**
60+
* Notify type
61+
* @private
62+
*/
63+
_notifyType: function () {
64+
$(document).trigger('changeTypeProduct', this.type);
65+
}
66+
};
67+
});

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)