Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
joshine
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
joshine
Commits
d74d1377
Commit
d74d1377
authored
Apr 24, 2023
by
halweg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
b6b45de1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
31 deletions
+41
-31
app/code/Joshine/Script/Console/Command/ReviewsImporter.php
+41
-31
No files found.
app/code/Joshine/Script/Console/Command/ReviewsImporter.php
View file @
d74d1377
...
...
@@ -310,37 +310,37 @@ class ReviewsImporter extends Command
$firstLine
=
false
;
continue
;
}
$review
[
'sku'
]
=
$row
[
0
];
$review
[
'detail'
]
=
$row
[
3
];
$review
[
'nickname'
]
=
$row
[
1
];
$review
[
'date'
]
=
$row
[
5
];
$review
[
'image'
]
=
$row
[
4
];
$review
[
'ratings'
]
=
$row
[
2
];
$review
[
'title'
]
=
'test'
;
if
(
empty
(
trim
(
$review
[
"sku"
]))
||
empty
(
trim
(
$review
[
"detail"
])
||
empty
(
trim
(
$review
[
'nickname'
]))
||
empty
(
$review
[
'date'
]))
$review
[
'sku'
]
=
$row
[
0
];
$review
[
'nickname'
]
=
$row
[
1
];
$review
[
'ratings'
]
=
$row
[
2
];
$review
[
'title'
]
=
$row
[
3
];
$review
[
'detail'
]
=
$row
[
4
];
$review
[
'image'
]
=
$row
[
5
];
$review
[
'size_fits'
]
=
$row
[
6
];
$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"
]
}
"
);
}
$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
);
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
)
{
return
"<info>
$msg
</info>"
;
...
...
@@ -354,13 +354,14 @@ class ReviewsImporter extends Command
private
function
checkHeader
(
$header
)
{
$field
=
[
//
'size_fits',
'size_fits'
,
'sku'
,
'name'
,
'content'
,
'rating'
,
'image'
,
'date'
'date'
,
'title'
];
foreach
(
$field
as
$row
)
{
if
(
!
in_array
(
$row
,
$header
))
{
...
...
@@ -375,12 +376,12 @@ class ReviewsImporter extends Command
*/
private
function
getHeaders
(
$line
)
{
if
(
count
(
$line
)
<
7
)
{
if
(
count
(
$line
)
<
8
)
{
throw
new
\Exception
(
"csv格式不对!"
);
}
if
(
$line
[
0
]
!=
'sku'
)
{
throw
new
\Exception
(
"第
一
列应该是sku!"
);
throw
new
\Exception
(
"第
1
列应该是sku!"
);
}
if
(
$line
[
1
]
!=
'name'
)
{
...
...
@@ -391,15 +392,24 @@ class ReviewsImporter extends Command
throw
new
\Exception
(
'第3列应该是rating'
);
}
if
(
$line
[
3
]
!=
'content'
)
{
throw
new
\Exception
(
'第4列应该是content'
);
if
(
$line
[
3
]
!=
'title'
)
{
throw
new
\Exception
(
'第4列应该是rating'
);
}
if
(
$line
[
4
]
!=
'content'
)
{
throw
new
\Exception
(
'第5列应该是content'
);
}
if
(
$line
[
4
]
!=
'image'
)
{
throw
new
\Exception
(
'第
二
列应该是image'
);
if
(
$line
[
5
]
!=
'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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment