Skip to content

Commit ab0ce55

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into API-Sprint-58-Bugs-and-Tests
2 parents f9c8746 + 6e7c85c commit ab0ce55

File tree

11 files changed

+670
-387
lines changed

11 files changed

+670
-387
lines changed

app/code/Magento/Catalog/Model/Product.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* @method string getUrlKey()
3030
* @method Product setUrlKey(string $urlKey)
3131
* @method Product setRequestPath(string $requestPath)
32+
* @method Product setWebsiteIds(array $ids)
3233
*
3334
* @SuppressWarnings(PHPMD.LongVariable)
3435
* @SuppressWarnings(PHPMD.ExcessivePublicCount)

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

Lines changed: 16 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/** @var $block \Magento\Eav\Block\Adminhtml\Attribute\Edit\Options\Options */
1010
?>
11-
<fieldset class="fieldset">
11+
<fieldset class="fieldset ignore-validate">
1212
<legend class="legend"><span><?php /* @escapeNotVerified */ echo __('Manage Options (values of your attribute)') ?></span></legend>
1313
<div id="manage-options-panel">
1414
<table class="admin__control-table">
@@ -67,110 +67,21 @@
6767
</td>
6868
</tr>
6969
</script>
70-
<script>
71-
require([
72-
'jquery',
73-
'mage/template',
74-
'jquery/ui',
75-
'prototype'
76-
], function(jQuery, mageTemplate){
77-
78-
var optionDefaultInputType = 'radio';
79-
80-
var attributeOption = {
81-
table: $('attribute-options-table'),
82-
itemCount: 0,
83-
totalItems: 0,
84-
isReadOnly: <?php echo (int)$block->getReadOnly(); ?>,
85-
add: function(data) {
86-
this.template = mageTemplate('#row-template');
87-
var isNewOption = false;
88-
if (typeof data.id == 'undefined') {
89-
data = {
90-
'id': 'option_' + this.itemCount,
91-
'sort_order': this.itemCount + 1
92-
};
93-
isNewOption = true;
94-
}
95-
if (!data.intype) {
96-
data.intype = optionDefaultInputType;
97-
}
98-
99-
Element.insert($$('[data-role=options-container]')[0], this.template({data: data}));
100-
if (isNewOption && !this.isReadOnly) {
101-
this.enableNewOptionDeleteButton(data.id);
102-
}
103-
this.itemCount++;
104-
this.totalItems++;
105-
this.updateItemsCountField();
106-
},
107-
remove: function(event) {
108-
var element = $(Event.findElement(event, 'tr')); // !!! Button already have table parent in safari
109-
// Safari workaround
110-
element.ancestors().each(function(parentItem) {
111-
if (parentItem.hasClassName('option-row')) {
112-
element = parentItem;
113-
throw $break;
114-
} else if (parentItem.hasClassName('box')) {
115-
throw $break;
116-
}
117-
});
118-
119-
if (element) {
120-
var elementFlags = element.getElementsByClassName('delete-flag');
121-
if (elementFlags[0]) {
122-
elementFlags[0].value = 1;
123-
}
124-
125-
element.addClassName('no-display');
126-
element.addClassName('template');
127-
element.hide();
128-
this.totalItems--;
129-
this.updateItemsCountField();
130-
}
131-
},
132-
updateItemsCountField: function() {
133-
$('option-count-check').value = this.totalItems > 0 ? '1' : '';
134-
},
135-
enableNewOptionDeleteButton: function(id) {
136-
$$('#delete_button_container_' + id + ' button').each(function(button) {
137-
button.enable();
138-
button.removeClassName('disabled');
139-
});
140-
},
141-
};
142-
143-
if ($('add_new_option_button')) {
144-
Event.observe('add_new_option_button', 'click', attributeOption.add.bind(attributeOption));
70+
<?php
71+
$values = [];
72+
foreach($block->getOptionValues() as $value) {
73+
array_push($values, $value->getData());
14574
}
146-
147-
$('manage-options-panel').on('click', '.delete-option', function(event, element) {
148-
attributeOption.remove(event);
149-
});
150-
151-
<?php foreach ($block->getOptionValues() as $_value): ?>
152-
attributeOption.add(<?php /* @escapeNotVerified */ echo $_value->toJson() ?>);
153-
<?php endforeach; ?>
154-
<?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()):?>
155-
jQuery(function($) {
156-
$('[data-role=options-container]').sortable({
157-
distance: 8,
158-
tolerance: "pointer",
159-
cancel: 'input, button',
160-
axis: 'y',
161-
update: function() {
162-
$('[data-role=options-container] [data-role=order]').each(function(index, element) {
163-
$(element).val(index + 1);
164-
});
75+
?>
76+
<script type="text/x-magento-init">
77+
{
78+
"*": {
79+
"Magento_Catalog/js/options": {
80+
"attributesData": <?php /* @escapeNotVerified */ echo json_encode($values); ?>,
81+
"isSortable": <?php echo (int)(!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()) ?>,
82+
"isReadOnly": <?php echo (int)$block->getReadOnly(); ?>
83+
}
16584
}
166-
});
167-
});
168-
<?php endif; ?>
169-
170-
window.attributeOption = attributeOption;
171-
window.optionDefaultInputType = optionDefaultInputType;
172-
//]]>
173-
174-
});
175-
</script>
85+
}
86+
</script>
17687
</fieldset>
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/* eslint-disable no-undef */
7+
// jscs:disable jsDoc
8+
9+
define([
10+
'jquery',
11+
'mage/template',
12+
'uiRegistry',
13+
'jquery/ui',
14+
'prototype'
15+
], function (jQuery, mageTemplate, rg) {
16+
'use strict';
17+
18+
return function (config) {
19+
var optionDefaultInputType = 'radio',
20+
attributeOption = {
21+
table: $('attribute-options-table'),
22+
itemCount: 0,
23+
totalItems: 0,
24+
rendered: 0,
25+
template: mageTemplate('#row-template'),
26+
isReadOnly: config.idReadOnly,
27+
add: function (data, render) {
28+
var isNewOption = false,
29+
element;
30+
31+
if (typeof data.id == 'undefined') {
32+
data = {
33+
'id': 'option_' + this.itemCount,
34+
'sort_order': this.itemCount + 1
35+
};
36+
isNewOption = true;
37+
}
38+
39+
if (!data.intype) {
40+
data.intype = optionDefaultInputType;
41+
}
42+
element = this.template({
43+
data: data
44+
});
45+
46+
if (isNewOption && !this.isReadOnly) {
47+
this.enableNewOptionDeleteButton(data.id);
48+
}
49+
this.itemCount++;
50+
this.totalItems++;
51+
this.elements += element;
52+
53+
if (render) {
54+
this.render();
55+
}
56+
},
57+
remove: function (event) {
58+
var element = $(Event.findElement(event, 'tr')),
59+
elementFlags; // !!! Button already have table parent in safari
60+
61+
// Safari workaround
62+
element.ancestors().each(function (parentItem) {
63+
if (parentItem.hasClassName('option-row')) {
64+
element = parentItem;
65+
throw $break;
66+
} else if (parentItem.hasClassName('box')) {
67+
throw $break;
68+
}
69+
});
70+
71+
if (element) {
72+
elementFlags = element.getElementsByClassName('delete-flag');
73+
74+
if (elementFlags[0]) {
75+
elementFlags[0].value = 1;
76+
}
77+
78+
element.addClassName('no-display');
79+
element.addClassName('template');
80+
element.hide();
81+
this.totalItems--;
82+
this.updateItemsCountField();
83+
}
84+
},
85+
updateItemsCountField: function () {
86+
$('option-count-check').value = this.totalItems > 0 ? '1' : '';
87+
},
88+
enableNewOptionDeleteButton: function (id) {
89+
$$('#delete_button_container_' + id + ' button').each(function (button) {
90+
button.enable();
91+
button.removeClassName('disabled');
92+
});
93+
},
94+
bindRemoveButtons: function () {
95+
jQuery('#swatch-visual-options-panel').on('click', '.delete-option', this.remove.bind(this));
96+
},
97+
render: function () {
98+
Element.insert($$('[data-role=options-container]')[0], this.elements);
99+
this.elements = '';
100+
},
101+
renderWithDelay: function (data, from, step, delay) {
102+
var arrayLength = data.length,
103+
len;
104+
105+
for (len = from + step; from < len && from < arrayLength; from++) {
106+
this.add(data[from]);
107+
}
108+
this.render();
109+
110+
if (from === arrayLength) {
111+
this.updateItemsCountField();
112+
this.rendered = 1;
113+
jQuery('body').trigger('processStop');
114+
115+
return true;
116+
}
117+
setTimeout(this.renderWithDelay.bind(this, data, from, step, delay), delay);
118+
},
119+
ignoreValidate: function () {
120+
var ignore = '.ignore-validate input, ' +
121+
'.ignore-validate select, ' +
122+
'.ignore-validate textarea';
123+
124+
jQuery('#edit_form').data('validator').settings.forceIgnore = ignore;
125+
}
126+
};
127+
128+
if ($('add_new_option_button')) {
129+
Event.observe('add_new_option_button', 'click', attributeOption.add.bind(attributeOption, {}, true));
130+
}
131+
132+
$('manage-options-panel').on('click', '.delete-option', function (event) {
133+
attributeOption.remove(event);
134+
});
135+
136+
jQuery('#manage-options-panel').on('render', function () {
137+
attributeOption.ignoreValidate();
138+
139+
if (attributeOption.rendered) {
140+
return false;
141+
}
142+
jQuery('body').trigger('processStart');
143+
attributeOption.renderWithDelay(config.attributesData, 0, 100, 300);
144+
attributeOption.bindRemoveButtons();
145+
});
146+
147+
if (config.isSortable) {
148+
jQuery(function ($) {
149+
$('[data-role=options-container]').sortable({
150+
distance: 8,
151+
tolerance: 'pointer',
152+
cancel: 'input, button',
153+
axis: 'y',
154+
update: function () {
155+
$('[data-role=options-container] [data-role=order]').each(function (index, element) {
156+
$(element).val(index + 1);
157+
});
158+
}
159+
});
160+
});
161+
}
162+
163+
window.attributeOption = attributeOption;
164+
window.optionDefaultInputType = optionDefaultInputType;
165+
166+
rg.set('manage-options-panel', attributeOption);
167+
};
168+
});

app/code/Magento/Quote/Model/QuoteManagement.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,9 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
467467
$this->eventManager->dispatch(
468468
'sales_model_service_quote_submit_failure',
469469
[
470-
'order' => $order,
471-
'quote' => $quote
470+
'order' => $order,
471+
'quote' => $quote,
472+
'exception' => $e
472473
]
473474
);
474475
throw $e;

app/code/Magento/Swatches/view/adminhtml/templates/catalog/product/attribute/js.phtml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
?>
1010
<script>
11-
require(["jquery", "collapsable", "prototype"], function(jQuery){
11+
require(["jquery", 'uiRegistry', "collapsable", "prototype"], function(jQuery, rg){
1212

1313
function toggleApplyVisibility(select) {
1414
if ($(select).value == 1) {
@@ -38,6 +38,9 @@ function checkOptionsPanelVisibility(){
3838

3939
if($('frontend_input') && ($('frontend_input').value=='select' || $('frontend_input').value=='multiselect')){
4040
panel.show();
41+
rg.get('manage-options-panel', function() {
42+
jQuery('#manage-options-panel').trigger('render');
43+
});
4144
}
4245
else {
4346
panel.hide();
@@ -48,6 +51,9 @@ function checkOptionsPanelVisibility(){
4851

4952
if($('frontend_input') && $('frontend_input').value=='swatch_visual') {
5053
panel.show();
54+
rg.get('swatch-visual-options-panel', function() {
55+
jQuery('#swatch-visual-options-panel').trigger('render');
56+
});
5157
}
5258
else {
5359
panel.hide();
@@ -58,6 +64,9 @@ function checkOptionsPanelVisibility(){
5864

5965
if($('frontend_input') && $('frontend_input').value=='swatch_text') {
6066
panel.show();
67+
rg.get('swatch-text-options-panel', function() {
68+
jQuery('#swatch-text-options-panel').trigger('render');
69+
});
6170
}
6271
else {
6372
panel.hide();

0 commit comments

Comments
 (0)