Skip to content

Commit c20c8e9

Browse files
authored
Merge pull request #145 from magento-tango/MAGETWO-54836
[Tango] Contribution of bug fixes #2
2 parents eb98eac + 861bced commit c20c8e9

File tree

40 files changed

+1296
-149
lines changed

40 files changed

+1296
-149
lines changed

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

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,21 +315,43 @@ public function mergeProductOptions($productOptions, $overwriteOptions)
315315
return $productOptions;
316316
}
317317

318-
foreach ($productOptions as $index => $option) {
318+
foreach ($productOptions as $optionIndex => $option) {
319319
$optionId = $option['option_id'];
320+
$option = $this->overwriteValue($optionId, $option, $overwriteOptions);
320321

321-
if (!isset($overwriteOptions[$optionId])) {
322-
continue;
322+
if (isset($option['values']) && isset($overwriteOptions[$optionId]['values'])) {
323+
foreach ($option['values'] as $valueIndex => $value) {
324+
$valueId = $value['option_type_id'];
325+
$value = $this->overwriteValue($valueId, $value, $overwriteOptions[$optionId]['values']);
326+
$option['values'][$valueIndex] = $value;
327+
}
323328
}
324329

330+
$productOptions[$optionIndex] = $option;
331+
}
332+
333+
return $productOptions;
334+
}
335+
336+
/**
337+
* Overwrite values of fields to default, if there are option id and field name in array overwriteOptions
338+
*
339+
* @param int $optionId
340+
* @param array $option
341+
* @param array $overwriteOptions
342+
* @return array
343+
*/
344+
private function overwriteValue($optionId, $option, $overwriteOptions)
345+
{
346+
if (isset($overwriteOptions[$optionId])) {
325347
foreach ($overwriteOptions[$optionId] as $fieldName => $overwrite) {
326348
if ($overwrite && isset($option[$fieldName]) && isset($option['default_' . $fieldName])) {
327-
$productOptions[$index][$fieldName] = $option['default_' . $fieldName];
349+
$option[$fieldName] = $option['default_' . $fieldName];
328350
}
329351
}
330352
}
331353

332-
return $productOptions;
354+
return $option;
333355
}
334356

335357
/**

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

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ public function testInitialize()
306306
* Data provider for testMergeProductOptions
307307
*
308308
* @return array
309+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
309310
*/
310311
public function mergeProductOptionsDataProvider()
311312
{
@@ -325,15 +326,34 @@ public function mergeProductOptionsDataProvider()
325326
[
326327
'option_id' => '3',
327328
'key1' => 'val1',
328-
'default_key1' => 'val2'
329+
'default_key1' => 'val2',
330+
'values' => [
331+
[
332+
'option_type_id' => '2',
333+
'key1' => 'val1',
334+
'default_key1' => 'val2'
335+
]
336+
]
337+
]
338+
],
339+
[
340+
4 => [
341+
'key1' => '1',
342+
'values' => [3 => ['key1' => 1]]
329343
]
330344
],
331-
[4 => ['key1' => '1']],
332345
[
333346
[
334347
'option_id' => '3',
335348
'key1' => 'val1',
336-
'default_key1' => 'val2'
349+
'default_key1' => 'val2',
350+
'values' => [
351+
[
352+
'option_type_id' => '2',
353+
'key1' => 'val1',
354+
'default_key1' => 'val2'
355+
]
356+
]
337357
]
338358
]
339359
],
@@ -344,17 +364,41 @@ public function mergeProductOptionsDataProvider()
344364
'key1' => 'val1',
345365
'key2' => 'val2',
346366
'default_key1' => 'val3',
347-
'default_key2' => 'val4'
367+
'default_key2' => 'val4',
368+
'values' => [
369+
[
370+
'option_type_id' => '2',
371+
'key1' => 'val1',
372+
'key2' => 'val2',
373+
'default_key1' => 'val11',
374+
'default_key2' => 'val22'
375+
]
376+
]
377+
]
378+
],
379+
[
380+
5 => [
381+
'key1' => '0',
382+
'key2' => '1',
383+
'values' => [2 => ['key1' => 1]]
348384
]
349385
],
350-
[5 => ['key1' => '0', 'key2' => '1']],
351386
[
352387
[
353388
'option_id' => '5',
354389
'key1' => 'val1',
355390
'key2' => 'val4',
356391
'default_key1' => 'val3',
357-
'default_key2' => 'val4'
392+
'default_key2' => 'val4',
393+
'values' => [
394+
[
395+
'option_type_id' => '2',
396+
'key1' => 'val11',
397+
'key2' => 'val2',
398+
'default_key1' => 'val11',
399+
'default_key2' => 'val22'
400+
]
401+
]
358402
]
359403
]
360404
],
@@ -364,16 +408,38 @@ public function mergeProductOptionsDataProvider()
364408
'option_id' => '7',
365409
'key1' => 'val1',
366410
'key2' => 'val2',
367-
'default_key1' => 'val3'
411+
'default_key1' => 'val3',
412+
'values' => [
413+
[
414+
'option_type_id' => '2',
415+
'key1' => 'val1',
416+
'key2' => 'val2',
417+
'default_key1' => 'val11'
418+
]
419+
]
420+
]
421+
],
422+
[
423+
7 => [
424+
'key1' => '1',
425+
'key2' => '1',
426+
'values' => [2 => ['key1' => 1, 'key2' => 1]]
368427
]
369428
],
370-
[7 => ['key1' => '1', 'key2' => '1']],
371429
[
372430
[
373431
'option_id' => '7',
374432
'key1' => 'val3',
375433
'key2' => 'val2',
376-
'default_key1' => 'val3'
434+
'default_key1' => 'val3',
435+
'values' => [
436+
[
437+
'option_type_id' => '2',
438+
'key1' => 'val11',
439+
'key2' => 'val2',
440+
'default_key1' => 'val11'
441+
]
442+
]
377443
]
378444
],
379445
],

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,22 @@ protected function getStaticTypeContainerConfig($sortOrder)
597597
*/
598598
protected function getSelectTypeGridConfig($sortOrder)
599599
{
600+
$options = [
601+
'arguments' => [
602+
'data' => [
603+
'config' => [
604+
'imports' => [
605+
'optionId' => '${ $.provider }:${ $.parentScope }.option_id',
606+
'optionTypeId' => '${ $.provider }:${ $.parentScope }.option_type_id',
607+
],
608+
'service' => [
609+
'template' => 'Magento_Catalog/form/element/helper/custom-option-type-service',
610+
],
611+
],
612+
],
613+
],
614+
];
615+
600616
return [
601617
'arguments' => [
602618
'data' => [
@@ -626,7 +642,10 @@ protected function getSelectTypeGridConfig($sortOrder)
626642
],
627643
],
628644
'children' => [
629-
static::FIELD_TITLE_NAME => $this->getTitleFieldConfig(10),
645+
static::FIELD_TITLE_NAME => $this->getTitleFieldConfig(
646+
10,
647+
$this->locator->getProduct()->getStoreId() ? $options : []
648+
),
630649
static::FIELD_PRICE_NAME => $this->getPriceFieldConfig(20),
631650
static::FIELD_PRICE_TYPE_NAME => $this->getPriceTypeFieldConfig(30, ['fit' => true]),
632651
static::FIELD_SKU_NAME => $this->getSkuFieldConfig(40),
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 + '][values][' + $data.optionTypeId + '][' + $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/CatalogWidget/Block/Product/Widget/Conditions.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@ public function __construct(
8181
*/
8282
protected function _construct()
8383
{
84+
$widgetParameters = [];
8485
$widget = $this->registry->registry('current_widget_instance');
8586
if ($widget) {
8687
$widgetParameters = $widget->getWidgetParameters();
87-
if (isset($widgetParameters['conditions'])) {
88-
$this->rule->loadPost($widgetParameters);
89-
}
88+
} elseif($widgetOptions = $this->getLayout()->getBlock('wysiwyg_widget.options')) {
89+
$widgetParameters = $widgetOptions->getWidgetValues();
90+
}
91+
92+
if (isset($widgetParameters['conditions'])) {
93+
$this->rule->loadPost($widgetParameters);
9094
}
9195
}
9296

0 commit comments

Comments
 (0)