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
9961f9a5
Commit
9961f9a5
authored
Apr 14, 2023
by
liumengfei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'developer' into production
parents
af7069ef
f419995e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
339 additions
and
10 deletions
+339
-10
app/code/Joshine/InstagramFeed/Block/ApiAddress.php
+21
-3
app/code/Joshine/InstagramFeed/Block/MediaFeed.php
+161
-0
app/code/Joshine/InstagramFeed/Controller/Adminhtml/OAuth/Redirect.php
+113
-2
app/code/Joshine/InstagramFeed/Model/Cache/Type.php
+23
-0
app/code/Joshine/InstagramFeed/view/frontend/templates/mediafeed.phtml
+0
-0
app/code/Joshine/Review/etc/cache.xml
+7
-0
app/design/frontend/Joshine/breeze/Magento_Catalog/templates/product/list.phtml
+12
-3
app/design/frontend/Joshine/breeze/Magento_Checkout/templates/onepage.phtml
+1
-1
app/design/frontend/Joshine/breeze/web/css/_custom.less
+1
-1
No files found.
app/code/Joshine/InstagramFeed/Block/ApiAddress.php
View file @
9961f9a5
...
@@ -11,7 +11,12 @@ use Magento\Store\Model\ScopeInterface;
...
@@ -11,7 +11,12 @@ use Magento\Store\Model\ScopeInterface;
class
ApiAddress
extends
Template
class
ApiAddress
extends
Template
{
{
const
INSTAGRAM_API_BASE_URL
=
'https://api.instagram.com'
;
const
INSTAGRAM_API_BASE_URL
=
'https://api.instagram.com'
;
const
INSTAGRAM_AUTH_URL
=
'oauth/authorize'
;
const
INSTAGRAM_GRAPH_API_URL
=
"https://graph.instagram.com"
;
const
INSTAGRAM_AUTH_URL
=
'oauth/authorize'
;
const
INSTAGRAM_TOKEN_URL
=
'oauth/access_token'
;
const
REDIRECT_URL
=
'admin/joshine_instagram/oauth/redirect'
;
const
REDIRECT_URL
=
'admin/joshine_instagram/oauth/redirect'
;
...
@@ -36,6 +41,16 @@ class ApiAddress extends Template
...
@@ -36,6 +41,16 @@ class ApiAddress extends Template
);
);
}
}
public
function
getLongTokenUrl
()
{
return
self
::
INSTAGRAM_GRAPH_API_URL
.
"/access_token"
;
}
public
function
getTokenUrl
()
:
string
{
return
self
::
INSTAGRAM_API_BASE_URL
.
'/'
.
self
::
INSTAGRAM_TOKEN_URL
;
}
public
function
getAppSecret
()
public
function
getAppSecret
()
{
{
return
$this
->
_objectManager
->
get
(
ScopeConfigInterface
::
class
)
return
$this
->
_objectManager
->
get
(
ScopeConfigInterface
::
class
)
...
@@ -57,6 +72,8 @@ class ApiAddress extends Template
...
@@ -57,6 +72,8 @@ class ApiAddress extends Template
"?client_id=
{
$this
->
getAppid
()
}
&redirect_uri=
{
$this
->
redirectUri
()
}
&scope=user_profile,user_media&response_type=code"
;
"?client_id=
{
$this
->
getAppid
()
}
&redirect_uri=
{
$this
->
redirectUri
()
}
&scope=user_profile,user_media&response_type=code"
;
}
}
public
function
getMediaUrl
(
$token
,
$uid
)
:
string
{
return
self
::
INSTAGRAM_GRAPH_API_URL
.
"/v16.0/
{
$uid
}
/media?access_token=
{
$token
}
&fields=caption,id,is_shared_to_feed,media_type,media_url,permalink,thumbnail_url,timestamp,username"
;
}
}
}
\ No newline at end of file
app/code/Joshine/InstagramFeed/Block/MediaFeed.php
0 → 100644
View file @
9961f9a5
<?php
namespace
Joshine\InstagramFeed\Block
;
use
Joshine\InstagramFeed\Model\Cache\Type
;
use
Magento\Framework\App\Config\ScopeConfigInterface
;
use
Magento\Framework\View\Element\Template
;
use
Magento\Store\Model\ScopeInterface
;
use
Magento\Framework\App\Cache
;
use
phpDocumentor\Reflection\PseudoTypes\LiteralString
;
use
Magento\Framework\Exception\NoSuchEntityException
;
use
Magento\Framework\Serialize\Serializer\Json
;
class
MediaFeed
extends
Template
{
const
TYPE_IDENTIFIER
=
'instagram_feed'
;
const
CACHE_TAG
=
'INSTAGRAM_FEED'
;
const
CACHE_LIFETIME
=
60
*
60
;
protected
$request
;
protected
$_template
=
'Joshine_InstagramFeed::mediafeed.phtml'
;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private
$_objectManager
;
/**
* @var ApiAddress
*/
private
$apiAddress
;
private
$_curlClient
;
/**
* @var \Magento\Framework\Json\EncoderInterface
*/
private
$jsonEncoder
;
/**
* @var \Magento\Framework\Json\Decoder
*/
private
$jsonDecoder
;
/**
* @var string
*/
private
$id
;
private
$_json
;
public
function
__construct
(
Template\Context
$context
,
\Magento\Framework\ObjectManagerInterface
$objectManager
,
\Magento\Framework\App\Request\Http
$request
,
ApiAddress
$apiAddress
,
\Magento\Framework\HTTP\Client\Curl
$curl
,
\Magento\Framework\Json\EncoderInterface
$jsonEncoder
,
\Magento\Framework\Json\Decoder
$jsonDecoder
,
Json
$json
,
array
$data
=
[]
)
{
parent
::
__construct
(
$context
,
$data
);
$this
->
request
=
$request
;
$this
->
id
=
$this
->
getId
();
$this
->
_objectManager
=
$objectManager
;
$this
->
apiAddress
=
$apiAddress
;
$this
->
_curlClient
=
$curl
;
$this
->
jsonEncoder
=
$jsonEncoder
;
$this
->
jsonDecoder
=
$jsonDecoder
;
$this
->
_json
=
$json
;
}
public
function
getCurlClient
()
{
return
$this
->
_curlClient
;
}
public
function
getMediaByCache
()
{
if
(
$this
->
_cacheState
->
isEnabled
(
Type
::
TYPE_IDENTIFIER
))
{
if
(
$feed
=
$this
->
_cache
->
load
(
$this
->
id
))
{
return
$this
->
_json
->
unserialize
(
$feed
);
}
}
return
[];
}
public
function
getMediaByApi
()
{
$uid
=
$this
->
_objectManager
->
get
(
ScopeConfigInterface
::
class
)
->
getValue
(
'joshine_instagram_feed/general/user_id'
,
ScopeInterface
::
SCOPE_STORE
);
$token
=
$this
->
_objectManager
->
get
(
ScopeConfigInterface
::
class
)
->
getValue
(
'joshine_instagram_feed/general/access_token'
,
ScopeInterface
::
SCOPE_STORE
);
$url
=
$this
->
apiAddress
->
getMediaUrl
(
$token
,
$uid
);
$this
->
getCurlClient
()
->
get
(
$url
);
$this
->
getCurlClient
()
->
setOptions
([
CURLOPT_SSL_VERIFYHOST
=>
false
,
CURLOPT_SSL_VERIFYPEER
=>
false
]);
if
(
$this
->
getCurlClient
()
->
getStatus
()
!=
200
)
{
return
[];
}
return
$this
->
jsonDecoder
->
decode
(
$this
->
getCurlClient
()
->
getBody
());
}
public
function
cacheFeed
(
$feed
)
{
if
(
$this
->
_cacheState
->
isEnabled
(
Type
::
TYPE_IDENTIFIER
))
{
$this
->
save
(
$feed
,
$this
->
id
);
}
return
true
;
}
public
function
getId
()
{
try
{
return
base64_encode
(
$this
->
_storeManager
->
getStore
()
->
getCode
()
.
Type
::
TYPE_IDENTIFIER
);
}
catch
(
NoSuchEntityException
$e
)
{
return
base64_encode
(
date
(
'Y-m-d'
)
.
Type
::
TYPE_IDENTIFIER
);
}
}
public
function
load
(
$cacheId
)
{
if
(
$this
->
_cacheState
->
isEnabled
(
Type
::
TYPE_IDENTIFIER
))
{
return
$this
->
_cache
->
load
(
$cacheId
)
?:
false
;
}
return
false
;
}
public
function
save
(
$data
,
$cacheId
)
{
if
(
$this
->
_cacheState
->
isEnabled
(
Type
::
TYPE_IDENTIFIER
))
{
return
$this
->
_cache
->
save
(
$data
,
$cacheId
,
[
Type
::
CACHE_TAG
],
Type
::
CACHE_LIFETIME
);
}
return
false
;
}
public
function
getMedia
()
{
$cache
=
$this
->
getMediaByCache
();
if
(
!
empty
(
$cache
))
{
return
$cache
;
}
$feed
=
$this
->
getMediaByApi
();
if
(
isset
(
$feed
[
'data'
]))
{
$this
->
cacheFeed
(
$this
->
_json
->
serialize
(
$feed
));
}
return
$feed
;
}
}
\ No newline at end of file
app/code/Joshine/InstagramFeed/Controller/Adminhtml/OAuth/Redirect.php
View file @
9961f9a5
<?php
<?php
namespace
Joshine\InstagramFeed\Controller\Adminhtml\OAuth
;
namespace
Joshine\InstagramFeed\Controller\Adminhtml\OAuth
;
use
Joshine\InstagramFeed\Block\ApiAddress
;
use
\Magento\Backend\App\Action
;
use
\Magento\Backend\App\Action
;
use
Magento\Backend\App\Action\Context
;
use
Magento\Framework\App\Config\ScopeConfigInterface
;
use
Magento\Framework\HTTP\Client\Curl
;
use
Magento\Store\Model\ScopeInterface
;
class
Redirect
extends
Action
class
Redirect
extends
Action
{
{
protected
$_publicActions
=
[
'redirect'
];
protected
$_publicActions
=
[
'redirect'
];
protected
$_apiAddress
;
/**
* @var ApiAddress
*/
private
$_curlClient
;
/**
* @var \Magento\Framework\App\Config\Storage\WriterInterface
*/
private
$_configWriter
;
private
$_cacheTypeList
;
public
function
__construct
(
Context
$context
,
Curl
$curl
,
\Magento\Framework\App\Config\Storage\WriterInterface
$configWriter
,
ApiAddress
$apiAddress
,
\Magento\Framework\App\Cache\TypeListInterface
$cacheTypeList
)
{
$this
->
_curlClient
=
$curl
;
$this
->
_configWriter
=
$configWriter
;
$this
->
_apiAddress
=
$apiAddress
;
$this
->
_cacheTypeList
=
$cacheTypeList
;
parent
::
__construct
(
$context
);
}
public
function
getCurlClient
()
{
return
$this
->
_curlClient
;
}
public
function
execute
()
public
function
execute
()
{
{
echo
"1111"
;
$codeRaw
=
$this
->
getRequest
()
->
getParam
(
'code'
);
// TODO: Implement execute() method.
if
(
!
$codeRaw
)
{
return
"Error Code"
;
}
$code
=
rtrim
(
$codeRaw
,
"#_"
);
try
{
$oauthRes
=
$this
->
getToken
(
$code
);
if
(
!
isset
(
$oauthRes
[
'access_token'
]))
{
return
;
}
$longTokenRaw
=
$this
->
getLongToken
(
$oauthRes
[
"access_token"
]);
$longToken
=
json_decode
(
$longTokenRaw
,
true
);
if
(
!
isset
(
$longToken
[
'access_token'
]))
{
echo
$longTokenRaw
;
return
;
}
$userId
=
$oauthRes
[
'user_id'
];
$longLifeToken
=
$longToken
[
'access_token'
];
$this
->
_configWriter
->
save
(
"joshine_instagram_feed/general/user_id"
,
$userId
);
$this
->
_configWriter
->
save
(
"joshine_instagram_feed/general/access_token"
,
$longLifeToken
);
$this
->
_cacheTypeList
->
cleanType
(
\Magento\Framework\App\Cache\Type\Config
::
TYPE_IDENTIFIER
);
echo
"Success!"
;
return
;
}
catch
(
\Exception
$e
)
{
\Magento\Framework\App\ObjectManager
::
getInstance
()
->
get
(
'Psr\Log\LoggerInterface'
)
->
warning
(
$e
->
getMessage
());
}
echo
"Something error, try again"
;
}
private
function
getLongToken
(
$token
)
{
$url
=
$this
->
_apiAddress
->
getLongTokenUrl
()
.
"?grant_type=ig_exchange_token"
.
"&client_secret=
{
$this
->
_apiAddress
->
getAppSecret
()
}
"
.
"&access_token=
{
$token
}
"
;
$this
->
getCurlClient
()
->
get
(
$url
);
$this
->
getCurlClient
()
->
setOptions
([
CURLOPT_SSL_VERIFYHOST
=>
false
,
CURLOPT_SSL_VERIFYPEER
=>
false
]);
return
$this
->
getCurlClient
()
->
getBody
();
}
private
function
getToken
(
$code
)
{
$request
=
[
'code'
=>
$code
,
'client_secret'
=>
$this
->
_apiAddress
->
getAppSecret
(),
'redirect_uri'
=>
$this
->
_apiAddress
->
redirectUri
(),
'grant_type'
=>
'authorization_code'
,
'client_id'
=>
$this
->
_apiAddress
->
getAppid
(),
];
$this
->
getCurlClient
()
->
post
(
$this
->
_apiAddress
->
getTokenUrl
(),
$request
);
$this
->
getCurlClient
()
->
setOptions
([
CURLOPT_SSL_VERIFYHOST
=>
false
,
CURLOPT_SSL_VERIFYPEER
=>
false
]);
if
(
$this
->
getCurlClient
()
->
getStatus
()
!=
200
)
{
ob_clean
();
echo
$this
->
getCurlClient
()
->
getBody
();
return
[];
}
return
json_decode
(
$this
->
getCurlClient
()
->
getBody
(),
true
);
}
}
}
}
\ No newline at end of file
app/code/Joshine/InstagramFeed/Model/Cache/Type.php
0 → 100644
View file @
9961f9a5
<?php
namespace
Joshine\InstagramFeed\Model\Cache
;
use
Magento\Framework\App\Cache\Type\FrontendPool
;
use
Magento\Framework\Cache\Frontend\Decorator\TagScope
;
class
Type
extends
TagScope
{
const
TYPE_IDENTIFIER
=
'instagram_feed'
;
const
CACHE_TAG
=
'INSTAGRAM_FEED'
;
const
CACHE_LIFETIME
=
60
*
60
;
/**
* @param FrontendPool $cacheFrontendPool
*/
public
function
__construct
(
FrontendPool
$cacheFrontendPool
)
{
parent
::
__construct
(
$cacheFrontendPool
->
get
(
self
::
TYPE_IDENTIFIER
),
self
::
CACHE_TAG
);
}
}
app/code/Joshine/InstagramFeed/view/frontend/templates/mediafeed.phtml
0 → 100644
View file @
9961f9a5
This diff is collapsed.
Click to expand it.
app/code/Joshine/Review/etc/cache.xml
0 → 100644
View file @
9961f9a5
<?xml version="1.0"?>
<config
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"urn:magento:framework:Cache/etc/cache.xsd"
>
<type
name=
"instagram_feed"
translate=
"label,description"
instance=
"Joshine\InstagramFeed\Model\Cache\Type"
>
<label>
Instagram Feed
</label>
<description>
Instagram feed cache.
</description>
</type>
</config>
app/design/frontend/Joshine/breeze/Magento_Catalog/templates/product/list.phtml
View file @
9961f9a5
...
@@ -100,11 +100,20 @@ $_helper = $block->getData('outputHelper');
...
@@ -100,11 +100,20 @@ $_helper = $block->getData('outputHelper');
$baseImageUrl
=
$productImage
->
getImageUrl
();
$baseImageUrl
=
$productImage
->
getImageUrl
();
$allImage
=
$_product
->
getMediaGalleryImages
()
->
getItems
();
$allImage
=
$_product
->
getMediaGalleryImages
()
->
getItems
();
$hoverImg
=
''
;
$hoverImg
=
''
;
foreach
(
$allImage
as
$img
){
if
(
basename
(
$baseImageUrl
)
!=
basename
(
$img
->
getUrl
())){
$tm_id
=
0
;
$hoverImg
=
$imageHelper
->
init
(
$_product
,
'product_page_image_large'
)
->
setImageFile
(
$img
->
getFile
())
->
resize
(
$productImage
->
getWidth
(),
$productImage
->
getHeight
())
->
getUrl
();
$arr
=
[];
foreach
(
$allImage
as
$index
=>
$img
){
if
(
count
(
$arr
)
>
3
)
{
break
;
break
;
}
}
if
(
in_array
(
$img
->
getData
(
'position'
),[
0
,
1
,
2
]))
{
$arr
[]
=
$img
;
}
}
if
(
isset
(
$arr
[
1
]))
{
$hoverImg
=
$imageHelper
->
init
(
$_product
,
'product_page_image_large'
)
->
setImageFile
(
$arr
[
1
]
->
getFile
())
->
resize
(
$productImage
->
getWidth
(),
$productImage
->
getHeight
())
->
getUrl
();
}
}
if
(
$pos
!=
null
)
{
if
(
$pos
!=
null
)
{
...
...
app/design/frontend/Joshine/breeze/Magento_Checkout/templates/onepage.phtml
View file @
9961f9a5
...
@@ -984,7 +984,7 @@ $free_price = $_helper->currency(0, true, false);
...
@@ -984,7 +984,7 @@ $free_price = $_helper->currency(0, true, false);
padding
:
0.1rem
0.5rem
;
padding
:
0.1rem
0.5rem
;
}
}
.checkout-index-index
.table-totals
.grand.totals
td
{
.checkout-index-index
.table-totals
.grand.totals
td
{
padding
-bottom
:
0.45rem
;
padding
:
0.45rem
;
}
}
/********************************************address from end****************************************************/
/********************************************address from end****************************************************/
...
...
app/design/frontend/Joshine/breeze/web/css/_custom.less
View file @
9961f9a5
...
@@ -965,7 +965,7 @@ p.shopbycate-title {
...
@@ -965,7 +965,7 @@ p.shopbycate-title {
transition: all .3s;
transition: all .3s;
}
}
.checkout-cart-index #cart-totals table td,.checkout-cart-index #cart-totals table th {
.checkout-cart-index #cart-totals table td,.checkout-cart-index #cart-totals table th {
padding: 0.2rem 0.5rem;
padding: 0.2rem 0.5rem
0.2rem 0px
;
}
}
.catalog-product-view .recently-viewed .flash-sale-info .price-final_price .normal-price{
.catalog-product-view .recently-viewed .flash-sale-info .price-final_price .normal-price{
float:right;
float:right;
...
...
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