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
60c9141a
Commit
60c9141a
authored
Apr 24, 2023
by
halweg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
d74d1377
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
20 deletions
+20
-20
app/code/Joshine/Script/Console/Command/ReviewsImporter.php
+20
-20
No files found.
app/code/Joshine/Script/Console/Command/ReviewsImporter.php
View file @
60c9141a
...
...
@@ -195,7 +195,7 @@ class ReviewsImporter extends Command
$objectManager
=
\Magento\Framework\App\ObjectManager
::
getInstance
();
$reviewFactory
=
$objectManager
->
get
(
"Magento\Review\Model\ReviewFactory"
);
$ratingFactory
=
$objectManager
->
get
(
"Magento\Review\Model\RatingFactory"
);
$productId
=
$objectManager
->
get
(
'Magento\Catalog\Model\Product'
)
->
getIdBySku
(
'202301-Black'
);
$productId
=
$objectManager
->
get
(
'Magento\Catalog\Model\Product'
)
->
getIdBySku
(
trim
(
$data
[
'sku'
])
);
if
(
$productId
)
{
$review
=
$reviewFactory
->
create
()
->
setData
(
$data
);
$review
->
unsetData
(
'review_id'
);
...
...
@@ -205,7 +205,7 @@ class ReviewsImporter extends Command
->
setStoreId
(
$this
->
storeId
)
->
setStores
([
$this
->
storeId
])
->
save
();
$this
->
storeImage
(
$data
[
'image'
],
$review
->
getId
());
$rating
=
[];
//前端实测
$rating
[
4
]
=
strval
(
$data
[
'ratings'
]
+
15
);
...
...
@@ -216,7 +216,8 @@ class ReviewsImporter extends Command
->
addOptionVote
(
$optionId
,
$productId
);
}
$review
->
aggregate
();
$this
->
storeImage
(
$data
[
'image'
],
$review
->
getId
());
}
else
{
$this
->
_output
->
writeln
(
$this
->
errorWrapper
(
"sku :
{
$data
[
'sku'
]
}
产品未找到"
));
}
}
...
...
@@ -234,23 +235,22 @@ class ReviewsImporter extends Command
public
function
copy
(
string
$imagePath
)
{
$from
=
$imagePath
;
$fileName
=
basename
(
$imagePath
);
if
(
$this
->
ioFile
->
fileExists
(
$from
))
{
$realPath
=
$this
->
filesystem
->
getDirectoryRead
(
DirectoryList
::
MEDIA
)
->
getAbsolutePath
(
ImageHelper
::
IMAGE_PATH
);
$counter
=
0
;
while
(
$this
->
ioFile
->
fileExists
(
$realPath
.
$
imagePath
))
{
$imagePathArray
=
explode
(
'.'
,
$
imagePath
);
while
(
$this
->
ioFile
->
fileExists
(
$realPath
.
$
fileName
))
{
$imagePathArray
=
explode
(
'.'
,
$
fileName
);
$imagePathArray
[
0
]
.=
$counter
++
;
$
imagePath
=
implode
(
'.'
,
$imagePathArray
);
$
fileName
=
implode
(
'.'
,
$imagePathArray
);
}
$this
->
ioFile
->
checkAndCreateFolder
(
$this
->
ioFile
->
dirname
(
$realPath
.
$imagePath
));
if
(
$this
->
ioFile
->
mv
(
$from
,
$realPath
.
$imagePath
))
{
return
$imagePath
;
$this
->
ioFile
->
checkAndCreateFolder
(
$this
->
ioFile
->
dirname
(
$realPath
.
$fileName
));
if
(
$this
->
ioFile
->
mv
(
$from
,
$realPath
.
$fileName
))
{
return
'/'
.
basename
(
$imagePath
);
}
}
...
...
@@ -310,14 +310,14 @@ class ReviewsImporter extends Command
$firstLine
=
false
;
continue
;
}
$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
]
;
$review
[
'sku'
]
=
trim
(
$row
[
0
])
;
$review
[
'nickname'
]
=
trim
(
$row
[
1
])
;
$review
[
'ratings'
]
=
trim
(
$row
[
2
])
;
$review
[
'title'
]
=
trim
(
$row
[
3
])
;
$review
[
'detail'
]
=
trim
(
$row
[
4
])
;
$review
[
'image'
]
=
trim
(
$row
[
5
])
;
$review
[
'size_fits'
]
=
trim
(
$row
[
6
])
;
$review
[
'date'
]
=
trim
(
$row
[
7
])
;
if
(
empty
(
trim
(
$review
[
"sku"
]))
||
empty
(
trim
(
$review
[
"detail"
])
||
empty
(
trim
(
$review
[
'nickname'
]))
...
...
@@ -420,7 +420,7 @@ class ReviewsImporter extends Command
{
$model
=
$this
->
imagesFactory
->
create
();
$model
->
setReviewId
(
$reviewId
);
$model
->
setPath
(
$result
[
'file'
]
);
$model
->
setPath
(
$result
);
if
(
$model
->
getImageId
())
{
$model
=
$this
->
getFullImage
(
$model
->
getImageId
())
->
addData
(
$model
->
getData
());
...
...
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