Skip to content

Commit 16f40c1

Browse files
Indrani SonawaneIndrani Sonawane
authored andcommitted
Merge remote-tracking branch '38926/fix-for-issue-38805' into augcommpr
2 parents 58a435b + a4eab4c commit 16f40c1

File tree

2 files changed

+132
-2
lines changed

2 files changed

+132
-2
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product/Option.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
147147
'radio' => true,
148148
'checkbox' => true,
149149
'multiple' => true,
150-
'file' => ['sku', 'file_extension', 'image_size_x', 'image_size_y'],
150+
'file' => ['price', 'sku', 'file_extension', 'image_size_x', 'image_size_y'],
151151
];
152152

153153
/**
@@ -2093,10 +2093,26 @@ protected function _parseCustomOptions($rowData)
20932093
$k = 0;
20942094
$name = '';
20952095
foreach ($optionValues as $optionValue) {
2096+
$separator = preg_quote($this->_productEntity->getMultipleValueSeparator(), '/');
2097+
$pattern = '/(?:^|' . $separator . ')file_extension=([a-zA-Z' . $separator . ']+)(?:' . $separator . '|$)/';
2098+
2099+
if (preg_match($pattern, $optionValue, $matches)) {
2100+
$fileExtNameAndValue = $matches[0];
2101+
$fileExtNameAndValue = ltrim($fileExtNameAndValue, $separator);
2102+
$optionValue = str_replace($fileExtNameAndValue, '', $optionValue);
2103+
$fileExtNameAndValue = rtrim($fileExtNameAndValue, $separator);
2104+
$optionValue = rtrim($optionValue, $separator);
2105+
}
2106+
20962107
$optionValueParams = explode($this->_productEntity->getMultipleValueSeparator(), $optionValue);
2108+
2109+
if (isset($fileExtNameAndValue)) {
2110+
$optionValueParams[] = $fileExtNameAndValue;
2111+
}
2112+
20972113
foreach ($optionValueParams as $nameAndValue) {
20982114
$nameAndValue = explode('=', $nameAndValue);
2099-
$value = isset($nameAndValue[1]) ? $nameAndValue[1] : '';
2115+
$value = $nameAndValue[1] ?? '';
21002116
$value = trim($value);
21012117
$fieldName = isset($nameAndValue[0]) ? trim($nameAndValue[0]) : '';
21022118
if ($value && ($fieldName === 'name')) {

app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/Product/Type/OptionTest.php

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,120 @@ public static function validateRowStoreViewCodeFieldDataProvider(): array
924924
];
925925
}
926926

927+
/**
928+
* Test parsing different option's type with _parseCustomOptions() method.
929+
*
930+
* @param array $rowData
931+
* @param array $responseData
932+
*
933+
* @return void
934+
* @dataProvider validateParseCustomOptionsDataProvider
935+
* @throws \ReflectionException
936+
*/
937+
public function testValidateParseCustomOptions(array $rowData, array $responseData): void
938+
{
939+
$reflection = new \ReflectionClass(Option::class);
940+
$reflectionMethod = $reflection->getMethod('_parseCustomOptions');
941+
$result = $reflectionMethod->invoke($this->model, $rowData);
942+
$this->assertEquals($responseData, $result);
943+
}
944+
945+
/**
946+
* Data provider for testValidateParseCustomOptions.
947+
*
948+
* @return array
949+
*/
950+
public static function validateParseCustomOptionsDataProvider(): array
951+
{
952+
return [
953+
'file_type' => [
954+
'$rowData' => [
955+
'custom_options' => 'name=Test Field Title,type=file,required=1,'
956+
. 'sku=1-text,price=12,file_extension=png,jpeg,jpg,gif,image_size_x=1024,'
957+
. 'image_size_y=1024,price_type=fixed'
958+
],
959+
'$responseData' => [
960+
'custom_options' => [
961+
'Test Field Title' => [
962+
[
963+
'name' => 'Test Field Title',
964+
'type' => 'file',
965+
'required' => '1',
966+
'sku' => '1-text',
967+
'price' => '12',
968+
'file_extension' => 'png,jpeg,jpg,gif',
969+
'image_size_x' => '1024',
970+
'image_size_y' => '1024',
971+
'price_type' => 'fixed'
972+
]
973+
]
974+
]
975+
]
976+
],
977+
'drop_down' => [
978+
'$rowData' => [
979+
'custom_options' => 'name=Test Field Title,type=drop_down,required=0,'
980+
. 'sku=1-text,price=10,price_type=fixed'
981+
],
982+
'$responseData' => [
983+
'custom_options' => [
984+
'Test Field Title' => [
985+
[
986+
'name' => 'Test Field Title',
987+
'type' => 'drop_down',
988+
'required' => '0',
989+
'sku' => '1-text',
990+
'price' => '10',
991+
'price_type' => 'fixed'
992+
]
993+
]
994+
]
995+
]
996+
],
997+
'area' => [
998+
'$rowData' => [
999+
'custom_options' => 'name=Test Field Title,type=area,required=1,'
1000+
. 'sku=1-text,price=20,max_characters=150,price_type=fixed'
1001+
],
1002+
'$responseData' => [
1003+
'custom_options' => [
1004+
'Test Field Title' => [
1005+
[
1006+
'name' => 'Test Field Title',
1007+
'type' => 'area',
1008+
'required' => '1',
1009+
'sku' => '1-text',
1010+
'price' => '20',
1011+
'max_characters' => '150',
1012+
'price_type' => 'fixed'
1013+
]
1014+
]
1015+
]
1016+
]
1017+
],
1018+
'date_time' => [
1019+
'$rowData' => [
1020+
'custom_options' => 'name=Test Field Title,type=date_time,required=0,'
1021+
. 'sku=1-text,price=30,price_type=fixed'
1022+
],
1023+
'$responseData' => [
1024+
'custom_options' => [
1025+
'Test Field Title' => [
1026+
[
1027+
'name' => 'Test Field Title',
1028+
'type' => 'date_time',
1029+
'required' => '0',
1030+
'sku' => '1-text',
1031+
'price' => '30',
1032+
'price_type' => 'fixed'
1033+
]
1034+
]
1035+
]
1036+
]
1037+
]
1038+
];
1039+
}
1040+
9271041
/**
9281042
* Data provider of row data and errors.
9291043
*

0 commit comments

Comments
 (0)