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
00e9b58a
Commit
00e9b58a
authored
Mar 15, 2023
by
halweg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix : 修复获取真实ip bug
parent
aeb545dc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
2 deletions
+33
-2
app/code/Joshine/Review/Block/Review/Product/View/ListView.php
+12
-1
app/code/Joshine/Review/Controller/Ajax/Helpful.php
+2
-1
app/code/Joshine/Review/Helper/BlockHelper.php
+19
-0
No files found.
app/code/Joshine/Review/Block/Review/Product/View/ListView.php
View file @
00e9b58a
<?php
namespace
Joshine\Review\Block\Review\Product\View
;
use
Joshine\Review\Helper\BlockHelper
;
use
Magento\Catalog\Api\ProductRepositoryInterface
;
use
Magento\Framework\DataObjectFactory
;
use
Magento\Review\Model\ResourceModel\Review\Collection
as
ReviewCollection
;
...
...
@@ -31,6 +32,8 @@ class ListView extends \Magento\Review\Block\Product\View\ListView
private
$vote
;
private
$realRemoteIp
;
private
$formKey
;
/**
...
...
@@ -203,7 +206,7 @@ class ListView extends \Magento\Review\Block\Product\View\ListView
{
return
$this
->
voteRepository
->
getVotesCount
(
$reviewId
,
$this
->
remoteAddress
->
getRemoteAddress
()
$this
->
getRemoteIp
()
);
}
public
function
isPlusVoted
(
$reviewId
)
...
...
@@ -213,4 +216,12 @@ class ListView extends \Magento\Review\Block\Product\View\ListView
return
$voted
[
'plus'
]
>
0
;
}
public
function
getRemoteIp
()
{
if
(
is_null
(
$this
->
realRemoteIp
))
{
$this
->
realRemoteIp
=
BlockHelper
::
getRealIp
();
}
return
$this
->
realRemoteIp
;
}
}
app/code/Joshine/Review/Controller/Ajax/Helpful.php
View file @
00e9b58a
...
...
@@ -4,6 +4,7 @@ namespace Joshine\Review\Controller\Ajax;
use
Magento\Framework\App\Action\Context
;
use
Magento\Framework\Exception\LocalizedException
;
use
Magento\Framework\Controller\Result\JsonFactory
;
use
Joshine\Review\Helper\BlockHelper
;
class
Helpful
extends
\Magento\Framework\App\Action\Action
{
...
...
@@ -80,7 +81,7 @@ class Helpful extends \Magento\Framework\App\Action\Action
$type
=
$this
->
getRequest
()
->
getParam
(
'type'
);
$reviewId
=
(
int
)
$this
->
getRequest
()
->
getParam
(
'review'
);
if
(
$reviewId
>
0
&&
in_array
(
$type
,
[
'plus'
,
'minus'
,
'update'
]))
{
$ip
=
$this
->
remoteAddress
->
getRemoteAddress
();
$ip
=
BlockHelper
::
getRealIp
();
if
(
$type
!=
'update'
)
{
$type
=
(
$type
==
'plus'
)
?
'1'
:
'0'
;
...
...
app/code/Joshine/Review/Helper/BlockHelper.php
View file @
00e9b58a
...
...
@@ -99,4 +99,23 @@ class BlockHelper implements \Magento\Framework\Data\CollectionDataSourceInterfa
return
$default
;
}
static
function
getRealIp
()
{
if
(
!
empty
(
$_SERVER
[
'HTTP_X_FORWARDED_FOR'
])){
$ips
=
$_SERVER
[
'HTTP_X_FORWARDED_FOR'
];
}
elseif
(
!
empty
(
$_SERVER
[
'HTTP_CLIENT_IP'
])){
$ips
=
$_SERVER
[
'HTTP_CLIENT_IP'
];
}
else
{
$ips
=
$_SERVER
[
'REMOTE_ADDR'
];
}
if
(
strpos
(
$ips
,
','
)
!==
false
)
{
$ipList
=
explode
(
','
,
$ips
);
}
else
{
$ipList
=
[
$ips
];
}
$remoteAddress
=
trim
(
reset
(
$ipList
));
return
$remoteAddress
??
''
;
}
}
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