Skip to content

Commit d3642e8

Browse files
Merge forwardport of #11732 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/11732.patch (created by @p-bystritsky) based on commit(s): 1. 1683995 Fixed GitHub Issues in 2.3-develop branch: - #5015: Report error csv doesn't work when trying to import a csv file with semicolon delimiter (reported by @agoeurysky)
2 parents 008ef55 + c867b81 commit d3642e8

File tree

7 files changed

+72
-8
lines changed

7 files changed

+72
-8
lines changed

app/code/Magento/ImportExport/Helper/Report.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Magento\ImportExport\Helper;
88

99
use Magento\Framework\App\Filesystem\DirectoryList;
10-
use Magento\Framework\Stdlib\DateTime;
1110
use Magento\ImportExport\Model\Import;
1211

1312
/**
@@ -127,4 +126,14 @@ protected function getFilePath($filename)
127126
{
128127
return $this->varDirectory->getRelativePath(Import::IMPORT_HISTORY_DIR . $filename);
129128
}
129+
130+
/**
131+
* Get csv delimiter from request.
132+
*
133+
* @return string
134+
*/
135+
public function getDelimiter()
136+
{
137+
return $this->_request->getParam(Import::FIELD_FIELD_SEPARATOR, ',');
138+
}
130139
}

app/code/Magento/ImportExport/Model/Report/Csv.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ protected function createSourceCsvModel($sourceFile)
130130
return $this->sourceCsvFactory->create(
131131
[
132132
'file' => $sourceFile,
133-
'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR)
133+
'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR),
134+
'delimiter' => $this->reportHelper->getDelimiter(),
134135
]
135136
);
136137
}

app/code/Magento/ImportExport/Test/Unit/Helper/ReportTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,21 @@ class ReportTest extends \PHPUnit\Framework\TestCase
4444
*/
4545
protected $report;
4646

47+
/**
48+
* @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject
49+
*/
50+
private $requestMock;
51+
4752
/**
4853
* Set up
4954
*/
5055
protected function setUp()
5156
{
5257
$this->context = $this->createMock(\Magento\Framework\App\Helper\Context::class);
58+
$this->requestMock = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class)
59+
->disableOriginalConstructor()
60+
->getMock();
61+
$this->context->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
5362
$this->timezone = $this->createPartialMock(
5463
\Magento\Framework\Stdlib\DateTime\Timezone::class,
5564
['date', 'getConfigTimezone', 'diff', 'format']
@@ -159,4 +168,20 @@ public function testGetReportSize()
159168
$result = $this->report->getReportSize('file');
160169
$this->assertNull($result);
161170
}
171+
172+
/**
173+
* Test getDelimiter() take into consideration request param '_import_field_separator'.
174+
*/
175+
public function testGetDelimiter()
176+
{
177+
$testDelimiter = 'some delimiter';
178+
$this->requestMock->expects($this->once())
179+
->method('getParam')
180+
->with($this->identicalTo(\Magento\ImportExport\Model\Import::FIELD_FIELD_SEPARATOR))
181+
->willReturn($testDelimiter);
182+
$this->assertEquals(
183+
$testDelimiter,
184+
$this->report->getDelimiter()
185+
);
186+
}
162187
}

app/code/Magento/ImportExport/Test/Unit/Model/Report/CsvTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ class CsvTest extends \PHPUnit\Framework\TestCase
4545
protected function setUp()
4646
{
4747
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
48+
$testDelimiter = 'some_delimiter';
4849

4950
$this->reportHelperMock = $this->createMock(\Magento\ImportExport\Helper\Report::class);
51+
$this->reportHelperMock->expects($this->any())->method('getDelimiter')->willReturn($testDelimiter);
5052

5153
$this->outputCsvFactoryMock = $this->createPartialMock(
5254
\Magento\ImportExport\Model\Export\Adapter\CsvFactory::class,
@@ -65,7 +67,17 @@ protected function setUp()
6567
[23 => 'first error'],
6668
[27 => 'second error']
6769
);
68-
$this->sourceCsvFactoryMock->expects($this->any())->method('create')->willReturn($this->sourceCsvMock);
70+
$this->sourceCsvFactoryMock
71+
->expects($this->any())
72+
->method('create')
73+
->with(
74+
[
75+
'file' => 'some_file_name',
76+
'directory' => null,
77+
'delimiter' => $testDelimiter
78+
]
79+
)
80+
->willReturn($this->sourceCsvMock);
6981

7082
$this->filesystemMock = $this->createMock(\Magento\Framework\Filesystem::class);
7183

dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/ValidateTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ class ValidateTest extends \Magento\TestFramework\TestCase\AbstractBackendContro
1818
* @dataProvider validationDataProvider
1919
* @param string $fileName
2020
* @param string $message
21+
* @param string $delimiter
2122
* @backupGlobals enabled
2223
* @magentoDbIsolation enabled
2324
*/
24-
public function testValidationReturn($fileName, $message)
25+
public function testValidationReturn($fileName, $message, $delimiter)
2526
{
2627
$validationStrategy = ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_STOP_ON_ERROR;
2728

@@ -36,7 +37,7 @@ public function testValidationReturn($fileName, $message)
3637
$this->getRequest()->setPostValue('behavior', 'append');
3738
$this->getRequest()->setPostValue(Import::FIELD_NAME_VALIDATION_STRATEGY, $validationStrategy);
3839
$this->getRequest()->setPostValue(Import::FIELD_NAME_ALLOWED_ERROR_COUNT, 0);
39-
$this->getRequest()->setPostValue('_import_field_separator', ',');
40+
$this->getRequest()->setPostValue('_import_field_separator', $delimiter);
4041

4142
/** @var \Magento\TestFramework\App\Filesystem $filesystem */
4243
$filesystem = $this->_objectManager->get(\Magento\Framework\Filesystem::class);
@@ -83,12 +84,24 @@ public function validationDataProvider()
8384
return [
8485
[
8586
'file_name' => 'catalog_product.csv',
86-
'message' => 'File is valid'
87+
'message' => 'File is valid',
88+
'delimiter' => ',',
8789
],
8890
[
8991
'file_name' => 'test.txt',
90-
'message' => '\'txt\' file extension is not supported'
91-
]
92+
'message' => '\'txt\' file extension is not supported',
93+
'delimiter' => ',',
94+
],
95+
[
96+
'file_name' => 'incorrect_catalog_product_comma.csv',
97+
'message' => 'Download full report',
98+
'delimiter' => ',',
99+
],
100+
[
101+
'file_name' => 'incorrect_catalog_product_semicolon.csv',
102+
'message' => 'Download full report',
103+
'delimiter' => ';',
104+
],
92105
];
93106
}
94107
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku,store_view_code,attribute_set_code,product_type,categories,product_websites,name,description,short_description,weight,product_online,tax_class_name,visibility,price,special_price,special_price_from_date,special_price_to_date,url_key,meta_title,meta_keywords,meta_description,base_image,base_image_label,small_image,small_image_label,thumbnail_image,thumbnail_image_label,swatch_image,swatch_image_label,created_at,updated_at,new_from_date,new_to_date,display_product_options_in,map_price,msrp_price,map_enabled,gift_message_available,custom_design,custom_design_from,custom_design_to,custom_layout_update,page_layout,product_options_container,msrp_display_actual_price_type,country_of_manufacture,additional_attributes,qty,out_of_stock_qty,use_config_min_qty,is_qty_decimal,allow_backorders,use_config_backorders,min_cart_qty,use_config_min_sale_qty,max_cart_qty,use_config_max_sale_qty,is_in_stock,notify_on_stock_below,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,related_skus,related_position,crosssell_skus,crosssell_position,upsell_skus,upsell_position,additional_images,additional_image_labels,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,bundle_shipment_type,configurable_variations,configurable_variation_labels,associated_skus
2+
Simple,,Default,simple,"Default Category/New",base,Simple,,,,1,"Taxable Goods","Catalo g, Search",100.0000,,,,simple,Simple,Simple,"Simple ",,,,,,,,,"10/25/17, 8:21 AM","10/25/17, 8:21 AM",,,"Block after Info Column",,,,"Use config",,,,,,,,,,100.0000,0.0000,1,0,0,1,1.0000,1,10000.0000,1,1,1.0000,1,1,1,1,1.0000,1,0,0,0,,,,,,,,,,,,,,,,,,,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sku;store_view_code;attribute_set_code;product_type;categories;product_websites;name;description;short_description;weight;product_online;tax_class_name;visibility;price;special_price;special_price_from_date;special_price_to_date;url_key;meta_title;meta_keywords;meta_description;base_image;base_image_label;small_image;small_image_label;thumbnail_image;thumbnail_image_label;swatch_image;swatch_image_label;created_at;updated_at;new_from_date;new_to_date;display_product_options_in;map_price;msrp_price;map_enabled;gift_message_available;custom_design;custom_design_from;custom_design_to;custom_layout_update;page_layout;product_options_container;msrp_display_actual_price_type;country_of_manufacture;additional_attributes;qty;out_of_stock_qty;use_config_min_qty;is_qty_decimal;allow_backorders;use_config_backorders;min_cart_qty;use_config_min_sale_qty;max_cart_qty;use_config_max_sale_qty;is_in_stock;notify_on_stock_below;use_config_notify_stock_qty;manage_stock;use_config_manage_stock;use_config_qty_increments;qty_increments;use_config_enable_qty_inc;enable_qty_increments;is_decimal_divided;website_id;related_skus;related_position;crosssell_skus;crosssell_position;upsell_skus;upsell_position;additional_images;additional_image_labels;hide_from_product_page;custom_options;bundle_price_type;bundle_sku_type;bundle_price_view;bundle_weight_type;bundle_values;bundle_shipment_type;configurable_variations;configurable_variation_labels;associated_skus
2+
Simple;;Default;simple;"Default Category/New";base;Simple;;;;1;"Taxable Goods";"Catalo g, Search";100.0000;;;;simple;Simple;Simple;"Simple ";;;;;;;;;"10/25/17, 8,21 AM";"10/25/17, 8,21 AM";;;"Block after Info Column";;;;"Use config";;;;;;;;;;100.0000;0.0000;1;0;0;1;1.0000;1;10000.0000;1;1;1.0000;1;1;1;1;1.0000;1;0;0;0;;;;;;;;;;;;;;;;;;;

0 commit comments

Comments
 (0)