Skip to content

Commit ffe26b0

Browse files
author
Korshenko, Oleksii(okorshenko)
committed
Merge pull request #598 from magento-tango/MAGETWO-52578
[Tango] Bug Fixes
2 parents 392644b + aaa2142 commit ffe26b0

File tree

17 files changed

+588
-47
lines changed

17 files changed

+588
-47
lines changed

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public function initializeFromData(\Magento\Catalog\Model\Product $product, arra
163163
} else {
164164
$productOptions = [];
165165
}
166+
166167
$product->addData($productData);
167168

168169
if ($wasLockedMedia) {
@@ -307,20 +308,28 @@ protected function normalize(array $productData)
307308
public function mergeProductOptions($productOptions, $overwriteOptions)
308309
{
309310
if (!is_array($productOptions)) {
310-
$productOptions = [];
311+
return [];
311312
}
312-
if (is_array($overwriteOptions)) {
313-
$options = array_replace_recursive($productOptions, $overwriteOptions);
314-
array_walk_recursive($options, function (&$item) {
315-
if ($item === "") {
316-
$item = null;
313+
314+
if (!is_array($overwriteOptions)) {
315+
return $productOptions;
316+
}
317+
318+
foreach ($productOptions as $index => $option) {
319+
$optionId = $option['option_id'];
320+
321+
if (!isset($overwriteOptions[$optionId])) {
322+
continue;
323+
}
324+
325+
foreach ($overwriteOptions[$optionId] as $fieldName => $overwrite) {
326+
if ($overwrite && isset($option[$fieldName]) && isset($option['default_' . $fieldName])) {
327+
$productOptions[$index][$fieldName] = $option['default_' . $fieldName];
317328
}
318-
});
319-
} else {
320-
$options = $productOptions;
329+
}
321330
}
322331

323-
return $options;
332+
return $productOptions;
324333
}
325334

326335
/**

app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -326,25 +326,72 @@ public function testInitialize()
326326
public function mergeProductOptionsDataProvider()
327327
{
328328
return [
329-
[
329+
'options are not array, empty array is returned' => [
330330
null,
331331
[],
332332
[],
333333
],
334-
[
335-
['key' => 'val'],
334+
'replacement is not array, original options are returned' => [
335+
['val'],
336336
null,
337-
['key' => 'val'],
337+
['val'],
338338
],
339-
[
340-
['key' => ['key' => 'val']],
341-
['key' => ['key' => 'val2', 'key2' => 'val2']],
342-
['key' => ['key' => 'val2', 'key2' => 'val2']],
339+
'ids do not match, no replacement occurs' => [
340+
[
341+
[
342+
'option_id' => '3',
343+
'key1' => 'val1',
344+
'default_key1' => 'val2'
345+
]
346+
],
347+
[4 => ['key1' => '1']],
348+
[
349+
[
350+
'option_id' => '3',
351+
'key1' => 'val1',
352+
'default_key1' => 'val2'
353+
]
354+
]
343355
],
344-
[
345-
['key' => ['key' => 'val', 'another_key' => 'another_value']],
346-
['key' => ['key' => 'val2', 'key2' => 'val2']],
347-
['key' => ['key' => 'val2', 'another_key' => 'another_value', 'key2' => 'val2',]],
356+
'key2 is replaced, key1 is not (checkbox is not checked)' => [
357+
[
358+
[
359+
'option_id' => '5',
360+
'key1' => 'val1',
361+
'key2' => 'val2',
362+
'default_key1' => 'val3',
363+
'default_key2' => 'val4'
364+
]
365+
],
366+
[5 => ['key1' => '0', 'key2' => '1']],
367+
[
368+
[
369+
'option_id' => '5',
370+
'key1' => 'val1',
371+
'key2' => 'val4',
372+
'default_key1' => 'val3',
373+
'default_key2' => 'val4'
374+
]
375+
]
376+
],
377+
'key1 is replaced, key2 has no default value' => [
378+
[
379+
[
380+
'option_id' => '7',
381+
'key1' => 'val1',
382+
'key2' => 'val2',
383+
'default_key1' => 'val3'
384+
]
385+
],
386+
[7 => ['key1' => '1', 'key2' => '1']],
387+
[
388+
[
389+
'option_id' => '7',
390+
'key1' => 'val3',
391+
'key2' => 'val2',
392+
'default_key1' => 'val3'
393+
]
394+
],
348395
],
349396
];
350397
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/AbstractModifier.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,15 @@ protected function getGroupCodeByField(array $meta, $field)
193193

194194
return false;
195195
}
196+
197+
/**
198+
* Format number to have only two decimals after delimiter
199+
*
200+
* @param mixed $value
201+
* @return string
202+
*/
203+
protected function formatFloat($value)
204+
{
205+
return $value !== null ? number_format((float)$value, 2, '.', '') : '';
206+
}
196207
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ public function modifyData(array $data)
156156

157157
/** @var \Magento\Catalog\Model\Product\Option $option */
158158
foreach ($productOptions as $index => $option) {
159-
$options[$index] = $this->formatFloat(static::FIELD_PRICE_NAME, $option->getData());
159+
$options[$index] = $this->formatFloatByPath(static::FIELD_PRICE_NAME, $option->getData());
160160
$values = $option->getValues() ?: [];
161161

162162
/** @var \Magento\Catalog\Model\Product\Option $value */
163163
foreach ($values as $value) {
164-
$options[$index][static::GRID_TYPE_SELECT_NAME][] = $this->formatFloat(
164+
$options[$index][static::GRID_TYPE_SELECT_NAME][] = $this->formatFloatByPath(
165165
static::FIELD_PRICE_NAME,
166166
$value->getData()
167167
);
@@ -188,12 +188,12 @@ public function modifyData(array $data)
188188
* @param array $data
189189
* @return array
190190
*/
191-
protected function formatFloat($path, array $data)
191+
protected function formatFloatByPath($path, array $data)
192192
{
193193
$value = $this->arrayManager->get($path, $data);
194194

195195
if (is_numeric($value)) {
196-
$data = $this->arrayManager->replace($path, $data, number_format($value, 2, '.', ''));
196+
$data = $this->arrayManager->replace($path, $data, $this->formatFloat($value));
197197
}
198198

199199
return $data;
@@ -497,7 +497,7 @@ protected function getImportOptionsModalConfig()
497497
*/
498498
protected function getCommonContainerConfig($sortOrder)
499499
{
500-
return [
500+
$commonContainer = [
501501
'arguments' => [
502502
'data' => [
503503
'config' => [
@@ -522,6 +522,9 @@ protected function getCommonContainerConfig($sortOrder)
522522
'label' => __('Option Title'),
523523
'component' => 'Magento_Catalog/component/static-type-input',
524524
'valueUpdate' => 'input',
525+
'imports' => [
526+
'optionId' => '${ $.provider }:${ $.parentScope }.option_id'
527+
]
525528
],
526529
],
527530
],
@@ -531,6 +534,19 @@ protected function getCommonContainerConfig($sortOrder)
531534
static::FIELD_IS_REQUIRE_NAME => $this->getIsRequireFieldConfig(40)
532535
]
533536
];
537+
538+
if ($this->locator->getProduct()->getStoreId()) {
539+
$useDefaultConfig = [
540+
'service' => [
541+
'template' => 'Magento_Catalog/form/element/helper/custom-option-service',
542+
]
543+
];
544+
$titlePath = $this->arrayManager->findPath(static::FIELD_TITLE_NAME, $commonContainer, null)
545+
. static::META_CONFIG_PATH;
546+
$commonContainer = $this->arrayManager->merge($titlePath, $commonContainer, $useDefaultConfig);
547+
}
548+
549+
return $commonContainer;
534550
}
535551

536552
/**

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ public function modifyData(array $data)
354354
foreach ($attributes as $attribute) {
355355
if (null !== ($attributeValue = $this->setupAttributeData($attribute))) {
356356
if ($attribute->getFrontendInput() === 'price' && is_scalar($attributeValue)) {
357-
$attributeValue = number_format((float)$attributeValue, 2);
357+
$attributeValue = $this->formatFloat($attributeValue);
358358
}
359359
$data[$productId][self::DATA_SOURCE_DEFAULT][$attribute->getAttributeCode()] = $attributeValue;
360360
}

app/code/Magento/Catalog/view/adminhtml/web/component/static-type-input.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ define([
4848
this.parentOption(function (component) {
4949
component.set('label', value ? value : component.get('headerLabel'));
5050
});
51+
52+
return this._super();
5153
}
5254
});
5355
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!--
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<div class="admin__field-service">
8+
<input type="checkbox"
9+
class="admin__control-checkbox"
10+
attr="
11+
id: $data.uid + '_default',
12+
name: 'options_use_default[' + $data.optionId + '][' + $data.index + ']',
13+
'data-form-part': $data.ns
14+
"
15+
ko-checked="isUseDefault">
16+
<label translate="'Use Default Value'" attr="for: $data.uid + '_default'" class="admin__field-label"></label>
17+
</div>

app/code/Magento/CatalogInventory/Test/Unit/Ui/DataProvider/Product/Form/Modifier/AdvancedInventoryTest.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
*/
66
namespace Magento\CatalogInventory\Test\Unit\Ui\DataProvider\Product\Form\Modifier;
77

8+
use Magento\Store\Model\Store;
89
use Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier\AbstractModifierTest;
910
use Magento\CatalogInventory\Api\StockRegistryInterface;
1011
use Magento\CatalogInventory\Api\Data\StockItemInterface;
11-
use Magento\Store\Model\Store;
12+
use Magento\CatalogInventory\Api\StockConfigurationInterface;
1213
use Magento\CatalogInventory\Ui\DataProvider\Product\Form\Modifier\AdvancedInventory;
1314

1415
/**
@@ -31,6 +32,11 @@ class AdvancedInventoryTest extends AbstractModifierTest
3132
*/
3233
protected $storeMock;
3334

35+
/**
36+
* @var StockConfigurationInterface|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
protected $stockConfigurationMock;
39+
3440
protected function setUp()
3541
{
3642
parent::setUp();
@@ -43,6 +49,9 @@ protected function setUp()
4349
$this->stockItemMock = $this->getMockBuilder(StockItemInterface::class)
4450
->setMethods(['getData'])
4551
->getMockForAbstractClass();
52+
$this->stockConfigurationMock = $this->getMockBuilder(StockConfigurationInterface::class)
53+
->disableOriginalConstructor()
54+
->getMockForAbstractClass();
4655

4756
$this->stockRegistryMock->expects($this->any())
4857
->method('getStockItem')
@@ -59,7 +68,9 @@ protected function createModel()
5968
{
6069
return $this->objectManager->getObject(AdvancedInventory::class, [
6170
'locator' => $this->locatorMock,
62-
'stockRegistry' => $this->stockRegistryMock
71+
'stockRegistry' => $this->stockRegistryMock,
72+
'stockConfiguration' => $this->stockConfigurationMock,
73+
'arrayManager' => $this->arrayManagerMock,
6374
]);
6475
}
6576

@@ -73,9 +84,10 @@ public function testModifyData()
7384
$modelId = 1;
7485
$someData = 1;
7586

76-
$this->productMock->expects($this->any())
77-
->method('getId')
78-
->willReturn($modelId);
87+
$this->productMock->expects($this->any())->method('getId')->willReturn($modelId);
88+
89+
$this->stockConfigurationMock->expects($this->any())->method('getDefaultConfigValue')->willReturn("a:0:{}");
90+
7991
$this->stockItemMock->expects($this->once())->method('getData')->willReturn(['someData']);
8092
$this->stockItemMock->expects($this->once())->method('getManageStock')->willReturn($someData);
8193
$this->stockItemMock->expects($this->once())->method('getQty')->willReturn($someData);
@@ -90,6 +102,11 @@ public function testModifyData()
90102
$this->stockItemMock->expects($this->once())->method('getQtyIncrements')->willReturn($someData);
91103
$this->stockItemMock->expects($this->once())->method('getIsInStock')->willReturn($someData);
92104

105+
$this->arrayManagerMock->expects($this->once())
106+
->method('set')
107+
->with('1/product/stock_data/min_qty_allowed_in_shopping_cart')
108+
->willReturnArgument(1);
109+
93110
$this->assertArrayHasKey($modelId, $this->getModel()->modifyData([]));
94111
}
95112
}

app/code/Magento/CatalogInventory/Ui/Component/Product/Form/Element/UseConfigSettings.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ public function prepare()
2626
&& isset($config['valueFromConfig'])
2727
&& $config['valueFromConfig'] instanceof ValueSourceInterface
2828
) {
29-
$config['valueFromConfig'] = $config['valueFromConfig']->getValue($config['keyInConfiguration']);
29+
$keyInConfiguration = $config['valueFromConfig']->getValue($config['keyInConfiguration']);
30+
if (!empty($config['unserialized']) && strpos($keyInConfiguration, 'a:') === 0) {
31+
$config['valueFromConfig'] = unserialize($keyInConfiguration);
32+
} else {
33+
$config['valueFromConfig'] = $keyInConfiguration;
34+
}
3035
}
3136
$this->setData('config', (array)$config);
3237

0 commit comments

Comments
 (0)