Skip to content

Commit 0af1f2d

Browse files
committed
Merge remote-tracking branch 'magento2/2.2-develop' into pr-regression-ece
2 parents 33277b0 + 88084c3 commit 0af1f2d

File tree

8 files changed

+85
-67
lines changed

8 files changed

+85
-67
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory as CustomOptionFactory;
99
use Magento\Catalog\Api\Data\ProductLinkInterfaceFactory as ProductLinkFactory;
1010
use Magento\Catalog\Api\ProductRepositoryInterface\Proxy as ProductRepository;
11+
use Magento\Catalog\Model\Product;
1112
use Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks;
1213
use Magento\Catalog\Model\Product\Link\Resolver as LinkResolver;
1314
use Magento\Framework\App\ObjectManager;
@@ -203,34 +204,7 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
203204
}
204205

205206
$product = $this->setProductLinks($product);
206-
207-
/**
208-
* Initialize product options
209-
*/
210-
if ($productOptions && !$product->getOptionsReadonly()) {
211-
// mark custom options that should to fall back to default value
212-
$options = $this->mergeProductOptions(
213-
$productOptions,
214-
$this->request->getPost('options_use_default')
215-
);
216-
$customOptions = [];
217-
foreach ($options as $customOptionData) {
218-
if (empty($customOptionData['is_delete'])) {
219-
if (empty($customOptionData['option_id'])) {
220-
$customOptionData['option_id'] = null;
221-
}
222-
if (isset($customOptionData['values'])) {
223-
$customOptionData['values'] = array_filter($customOptionData['values'], function ($valueData) {
224-
return empty($valueData['is_delete']);
225-
});
226-
}
227-
$customOption = $this->customOptionFactory->create(['data' => $customOptionData]);
228-
$customOption->setProductSku($product->getSku());
229-
$customOptions[] = $customOption;
230-
}
231-
}
232-
$product->setOptions($customOptions);
233-
}
207+
$product = $this->fillProductOptions($product, $productOptions);
234208

235209
$product->setCanSaveCustomOptions(
236210
!empty($productData['affect_product_custom_options']) && !$product->getOptionsReadonly()
@@ -427,4 +401,50 @@ private function filterWebsiteIds($websiteIds)
427401

428402
return $websiteIds;
429403
}
404+
405+
/**
406+
* Fills $product with options from $productOptions array
407+
*
408+
* @param Product $product
409+
* @param array $productOptions
410+
* @return Product
411+
*/
412+
private function fillProductOptions(Product $product, array $productOptions)
413+
{
414+
if ($product->getOptionsReadonly()) {
415+
return $product;
416+
}
417+
418+
if (empty($productOptions)) {
419+
return $product->setOptions([]);
420+
}
421+
422+
// mark custom options that should to fall back to default value
423+
$options = $this->mergeProductOptions(
424+
$productOptions,
425+
$this->request->getPost('options_use_default')
426+
);
427+
$customOptions = [];
428+
foreach ($options as $customOptionData) {
429+
if (!empty($customOptionData['is_delete'])) {
430+
continue;
431+
}
432+
433+
if (empty($customOptionData['option_id'])) {
434+
$customOptionData['option_id'] = null;
435+
}
436+
437+
if (isset($customOptionData['values'])) {
438+
$customOptionData['values'] = array_filter($customOptionData['values'], function ($valueData) {
439+
return empty($valueData['is_delete']);
440+
});
441+
}
442+
443+
$customOption = $this->customOptionFactory->create(['data' => $customOptionData]);
444+
$customOption->setProductSku($product->getSku());
445+
$customOptions[] = $customOption;
446+
}
447+
448+
return $product->setOptions($customOptions);
449+
}
430450
}

app/code/Magento/Catalog/view/adminhtml/web/js/components/dynamic-rows-import-custom-options.js

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,6 @@ define([
1010
], function (DynamicRows, _, utils) {
1111
'use strict';
1212

13-
var maxId = 0,
14-
15-
/**
16-
* Stores max option_id value of the options from recordData once on initialization
17-
* @param {Array} data - array with records data
18-
*/
19-
initMaxId = function (data) {
20-
if (data && data.length) {
21-
maxId = ~~_.max(data, function (record) {
22-
return ~~record['option_id'];
23-
})['option_id'];
24-
}
25-
};
26-
2713
return DynamicRows.extend({
2814
defaults: {
2915
mappingSettings: {
@@ -38,18 +24,11 @@ define([
3824
identificationDRProperty: 'option_id'
3925
},
4026

41-
/** @inheritdoc */
42-
initialize: function () {
43-
this._super();
44-
initMaxId(this.recordData());
45-
46-
return this;
47-
},
48-
4927
/** @inheritdoc */
5028
processingInsertData: function (data) {
5129
var options = [],
52-
currentOption;
30+
currentOption,
31+
generalContext = this;
5332

5433
if (!data) {
5534
return;
@@ -70,10 +49,7 @@ define([
7049
}
7150

7251
if (currentOption.values.length > 0) {
73-
_.each(currentOption.values, function (optionValue) {
74-
delete optionValue['option_id'];
75-
delete optionValue['option_type_id'];
76-
});
52+
generalContext.removeOptionsIds(currentOption.values);
7753
}
7854
options.push(currentOption);
7955
});
@@ -91,17 +67,20 @@ define([
9167
},
9268

9369
/**
94-
* Set empty array to dataProvider
70+
* Removes option_id and option_type_id from every option
71+
*
72+
* @param {Array} options
9573
*/
96-
clearDataProvider: function () {
97-
this.source.set(this.dataProvider, []);
74+
removeOptionsIds: function (options) {
75+
_.each(options, function (optionValue) {
76+
delete optionValue['option_id'];
77+
delete optionValue['option_type_id'];
78+
});
9879
},
9980

10081
/** @inheritdoc */
10182
processingAddChild: function (ctx, index, prop) {
102-
if (ctx && !_.isNumber(ctx['option_id'])) {
103-
ctx['option_id'] = ++maxId;
104-
} else if (!ctx) {
83+
if (!ctx) {
10584
this.showSpinner(true);
10685
this.addChild(ctx, index, prop);
10786

@@ -111,6 +90,13 @@ define([
11190
this._super(ctx, index, prop);
11291
},
11392

93+
/**
94+
* Set empty array to dataProvider
95+
*/
96+
clearDataProvider: function () {
97+
this.source.set(this.dataProvider, []);
98+
},
99+
114100
/**
115101
* Mutes parent method
116102
*/

app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_new.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
<referenceContainer name="content">
1414
<block class="Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create" name="sales_creditmemo_create">
1515
<block class="Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Form" name="form" template="Magento_Sales::order/creditmemo/create/form.phtml">
16-
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml"/>
16+
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml">
17+
<container name="extra_customer_info"/>
18+
</block>
1719
<block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
1820
<block class="Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create\Items" name="order_items" template="Magento_Sales::order/creditmemo/create/items.phtml">
1921
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" as="default" template="Magento_Sales::order/creditmemo/create/items/renderer/default.phtml"/>

app/code/Magento/Sales/view/adminhtml/layout/sales_order_creditmemo_view.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
<referenceContainer name="content">
1313
<block class="Magento\Sales\Block\Adminhtml\Order\Creditmemo\View" name="sales_creditmemo_view">
1414
<block class="Magento\Sales\Block\Adminhtml\Order\Creditmemo\View\Form" name="form" template="Magento_Sales::order/creditmemo/view/form.phtml">
15-
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml"/>
15+
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml">
16+
<container name="extra_customer_info"/>
17+
</block>
1618
<block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
1719
<block class="Magento\Sales\Block\Adminhtml\Order\Creditmemo\View\Items" name="creditmemo_items" template="Magento_Sales::order/creditmemo/view/items.phtml">
1820
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" as="default" template="Magento_Sales::order/creditmemo/view/items/renderer/default.phtml"/>

app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_new.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
<referenceContainer name="content">
1717
<block class="Magento\Sales\Block\Adminhtml\Order\Invoice\Create" name="sales_invoice_create">
1818
<block class="Magento\Sales\Block\Adminhtml\Order\Invoice\Create\Form" name="form" template="Magento_Sales::order/invoice/create/form.phtml">
19-
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml"/>
19+
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml">
20+
<container name="extra_customer_info"/>
21+
</block>
2022
<block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
2123
<block class="Magento\Sales\Block\Adminhtml\Order\Invoice\Create\Items" name="order_items" template="Magento_Sales::order/invoice/create/items.phtml">
2224
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" as="default" template="Magento_Sales::order/invoice/create/items/renderer/default.phtml"/>

app/code/Magento/Sales/view/adminhtml/layout/sales_order_invoice_view.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
<referenceContainer name="content">
1414
<block class="Magento\Sales\Block\Adminhtml\Order\Invoice\View" name="sales_invoice_view">
1515
<block class="Magento\Sales\Block\Adminhtml\Order\Invoice\View\Form" name="form" template="Magento_Sales::order/invoice/view/form.phtml">
16-
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml"/>
16+
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml">
17+
<container name="extra_customer_info"/>
18+
</block>
1719
<block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
1820
<block class="Magento\Sales\Block\Adminhtml\Order\Invoice\View\Items" name="invoice_items" template="Magento_Sales::order/invoice/view/items.phtml">
1921
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" as="default" template="Magento_Sales::order/invoice/view/items/renderer/default.phtml"/>

app/code/Magento/Shipping/view/adminhtml/layout/adminhtml_order_shipment_new.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<referenceContainer name="content">
1212
<block class="Magento\Shipping\Block\Adminhtml\Create" name="sales_shipment_create">
1313
<block class="Magento\Shipping\Block\Adminhtml\Create\Form" name="form" template="Magento_Shipping::create/form.phtml">
14-
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml"/>
14+
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml">
15+
<container name="extra_customer_info"/>
16+
</block>
1517
<block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
1618
<block class="Magento\Shipping\Block\Adminhtml\Create\Items" name="order_items" template="Magento_Shipping::create/items.phtml">
1719
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" name="default" as="default" template="Magento_Shipping::create/items/renderer/default.phtml"/>

app/code/Magento/Shipping/view/adminhtml/layout/adminhtml_order_shipment_view.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<referenceContainer name="content">
1212
<block class="Magento\Shipping\Block\Adminhtml\View" name="sales_shipment_view">
1313
<block class="Magento\Shipping\Block\Adminhtml\View\Form" name="form" template="Magento_Shipping::view/form.phtml">
14-
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml"/>
14+
<block class="Magento\Sales\Block\Adminhtml\Order\View\Info" name="order_info" template="Magento_Sales::order/view/info.phtml">
15+
<container name="extra_customer_info"/>
16+
</block>
1517
<block class="Magento\Sales\Block\Adminhtml\Order\Payment" name="order_payment"/>
1618
<block class="Magento\Shipping\Block\Adminhtml\View\Items" name="shipment_items" template="Magento_Shipping::view/items.phtml">
1719
<block class="Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer" name="default" as="default" template="Magento_Shipping::view/items/renderer/default.phtml"/>

0 commit comments

Comments
 (0)