Commit d74d1377 by halweg

no message

parent b6b45de1
...@@ -310,37 +310,37 @@ class ReviewsImporter extends Command ...@@ -310,37 +310,37 @@ class ReviewsImporter extends Command
$firstLine = false; $firstLine = false;
continue; continue;
} }
$review['sku'] = $row[0]; $review['sku'] = $row[0];
$review['detail'] = $row[3]; $review['nickname'] = $row[1];
$review['nickname'] = $row[1]; $review['ratings'] = $row[2];
$review['date'] = $row[5]; $review['title'] = $row[3];
$review['image'] = $row[4]; $review['detail'] = $row[4];
$review['ratings'] = $row[2]; $review['image'] = $row[5];
$review['title'] = 'test'; $review['size_fits'] = $row[6];
if (empty(trim($review["sku"])) || empty(trim($review["detail"]) || empty(trim($review['nickname'])) || empty($review['date'])) $review['date'] = $row[7];
if (empty(trim($review["sku"]))
|| empty(trim($review["detail"])
|| empty(trim($review['nickname']))
|| empty($review['date'])
|| empty($review['title'])
)
) { ) {
throw new \Exception("表格数据有空: {$row["name"]}"); throw new \Exception("表格数据有空: {$row["name"]}");
} }
$data[] = $review;
if (!is_integer($review['size_fits'])) {
$review['size_fits'] = 3;
}
break; if (!is_integer($review['ratings'])) {
$review['ratings'] = 5;
}
$data[] = $review;
} }
fclose($csvData); fclose($csvData);
return $data; return $data;
} }
/**
* @return \Magento\Customer\Model\ResourceModel\Customer\Collection
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function getCollection()
{
$this->collection = $this->collectionFactory->create();
$this->collection->addAttributeToSelect(['entity_id', 'firstname', 'lastname', 'email']);
return $this->collection;
}
private function successWrapper($msg) private function successWrapper($msg)
{ {
return "<info>$msg</info>"; return "<info>$msg</info>";
...@@ -354,13 +354,14 @@ class ReviewsImporter extends Command ...@@ -354,13 +354,14 @@ class ReviewsImporter extends Command
private function checkHeader($header) private function checkHeader($header)
{ {
$field = [ $field = [
//'size_fits', 'size_fits',
'sku', 'sku',
'name', 'name',
'content', 'content',
'rating', 'rating',
'image', 'image',
'date' 'date',
'title'
]; ];
foreach ($field as $row) { foreach ($field as $row) {
if (!in_array($row, $header)) { if (!in_array($row, $header)) {
...@@ -375,12 +376,12 @@ class ReviewsImporter extends Command ...@@ -375,12 +376,12 @@ class ReviewsImporter extends Command
*/ */
private function getHeaders($line) private function getHeaders($line)
{ {
if (count($line) < 7 ) { if (count($line) < 8 ) {
throw new \Exception("csv格式不对!"); throw new \Exception("csv格式不对!");
} }
if ($line[0] != 'sku') { if ($line[0] != 'sku') {
throw new \Exception("第列应该是sku!"); throw new \Exception("第1列应该是sku!");
} }
if ($line[1] != 'name') { if ($line[1] != 'name') {
...@@ -391,15 +392,24 @@ class ReviewsImporter extends Command ...@@ -391,15 +392,24 @@ class ReviewsImporter extends Command
throw new \Exception('第3列应该是rating'); throw new \Exception('第3列应该是rating');
} }
if ($line[3] != 'content') { if ($line[3] != 'title') {
throw new \Exception('第4列应该是content'); throw new \Exception('第4列应该是rating');
}
if ($line[4] != 'content') {
throw new \Exception('第5列应该是content');
} }
if ($line[4] != 'image') { if ($line[5] != 'image') {
throw new \Exception('第列应该是image'); throw new \Exception('第6列应该是image');
} }
if ($line[5] != 'date') {
throw new \Exception('第二列应该是date'); if ($line[6] != 'size_fits') {
throw new \Exception('第7列应该是size_fits');
}
if ($line[7] != 'date') {
throw new \Exception('第8列应该是date');
} }
return $line; return $line;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment