Skip to content

Commit

Permalink
Merge pull request #4783 from EC-CUBE/fix-csv-char
Browse files Browse the repository at this point in the history
機種依存文字が文字化けする不具合を修正
  • Loading branch information
Kiyotaka Oku committed Dec 8, 2020
2 parents f422e12 + 6ed468a commit bf80d56
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/config/eccube/packages/eccube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ parameters:
eccube_csv_export_separator: ,
# 出力エンコーディング
eccube_csv_export_encoding: SJIS-win
# 入力エンコーディング
eccube_csv_import_encoding: ['UTF-8', 'SJIS-win', 'SJIS', 'EUC-JP', 'ASCII', 'JIS']
# 日付のフォーマット
eccube_csv_export_date_format: 'Y-m-d H:i:s'
# 複数データの区切り文字
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function getImportData(UploadedFile $formFile)
}
} else {
// アップロードされたファイルがUTF-8以外は文字コード変換を行う
$encode = StringUtil::characterEncoding($file);
$encode = StringUtil::characterEncoding($file, $this->eccubeConfig['eccube_csv_import_encoding']);
if (!empty($encode) && $encode != 'UTF-8') {
$file = mb_convert_encoding($file, 'UTF-8', $encode);
}
Expand Down
26 changes: 26 additions & 0 deletions tests/Eccube/Tests/Web/Admin/Product/CsvImportControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -964,4 +964,30 @@ public function testDeleteImage()
$this->assertTrue(file_exists($dir . $DuplicatedImage->getFileName()));
$this->assertFalse(file_exists($dir . $NotDuplicatedImage->getFileName()));
}

/**
* @see https://github.com/EC-CUBE/ec-cube/issues/4781
*/
public function testSjisWinCsvTest()
{
// CSV生成
$csv = $this->createCsvAsArray();
$csv[1][2] = 'テスト①'; // 商品名:機種依存文字で設定
$csv[1][3] = 'sjis-win-test';
$this->filepath = $this->createCsvFromArray($csv);

// sjis-winに変換
$content = file_get_contents($this->filepath);
$content = mb_convert_encoding($content, 'sjis-win', 'UTF-8');
file_put_contents($this->filepath, $content);

$this->scenario();

$Product = $this->productRepo->findOneBy(['note' => 'sjis-win-test']);

// 文字化けしないことを確認
$this->expected = 'テスト①';
$this->actual = $Product->getName();
$this->verify();
}
}

0 comments on commit bf80d56

Please sign in to comment.