Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgo-magento-extension
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgo-magento-extension
Commits
436e55f7
Commit
436e55f7
authored
8 months ago
by
Christel Loftus
Browse files
Options
Downloads
Patches
Plain Diff
cleanup
parent
62c32bf0
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!20
1.0.41
,
!15
Tracking page
This commit is part of merge request
!15
. Comments created here will be created in the context of that merge request.
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Block/TrackOrderLink.php
+6
-4
6 additions, 4 deletions
Block/TrackOrderLink.php
Controller/Tracking/Index.php
+5
-20
5 additions, 20 deletions
Controller/Tracking/Index.php
etc/frontend/di.xml
+0
-5
0 additions, 5 deletions
etc/frontend/di.xml
with
11 additions
and
29 deletions
Block/TrackOrderLink.php
+
6
−
4
Edit
View file @
436e55f7
...
...
@@ -12,11 +12,11 @@ class TrackOrderLink extends Current
public
function
__construct
(
\Magento\Framework\View\Element\Template\Context
$context
,
ScopeConfigInterface
$scopeConfig
,
\Magento\Framework\App\DefaultPathInterface
$defaultPath
,
// Add this dependency
\Magento\Framework\App\DefaultPathInterface
$defaultPath
,
array
$data
=
[]
)
{
$this
->
scopeConfig
=
$scopeConfig
;
parent
::
__construct
(
$context
,
$defaultPath
,
$data
);
// Pass it to the parent constructor
parent
::
__construct
(
$context
,
$defaultPath
,
$data
);
}
protected
function
_toHtml
()
...
...
@@ -27,11 +27,13 @@ class TrackOrderLink extends Current
\Magento\Store\Model\ScopeInterface
::
SCOPE_STORE
);
// Return an empty string if the feature is disabled
if
(
!
$isEnabled
)
{
return
''
;
// Return an empty string if the feature is disabled
return
''
;
}
return
parent
::
_toHtml
();
// Use the parent class's rendering method
// Use the parent class's rendering method
return
parent
::
_toHtml
();
}
}
...
...
This diff is collapsed.
Click to expand it.
Controller/Tracking/Index.php
+
5
−
20
Edit
View file @
436e55f7
...
...
@@ -32,7 +32,7 @@ class Index extends \Magento\Framework\App\Action\Action
RedirectFactory
$redirectFactory
,
StoreManagerInterface
$storeManager
,
Curl
$curl
,
Registry
$registry
// Add Registry
Registry
$registry
)
{
$this
->
resultPageFactory
=
$resultPageFactory
;
$this
->
jsonFactory
=
$jsonFactory
;
...
...
@@ -41,12 +41,13 @@ class Index extends \Magento\Framework\App\Action\Action
$this
->
redirectFactory
=
$redirectFactory
;
$this
->
storeManager
=
$storeManager
;
$this
->
curl
=
$curl
;
$this
->
registry
=
$registry
;
// Assign Registry
$this
->
registry
=
$registry
;
parent
::
__construct
(
$context
);
}
public
function
execute
()
{
// This is only an extra check after the TrackOrderLink block
// Check if the "Track My Order" feature is enabled
$isEnabled
=
$this
->
scopeConfig
->
isSetFlag
(
'carriers/bobgo/enable_track_order'
,
...
...
@@ -58,48 +59,32 @@ class Index extends \Magento\Framework\App\Action\Action
return
$this
->
redirectFactory
->
create
()
->
setPath
(
'noroute'
);
}
$this
->
logger
->
info
(
'Page Controller is executed.'
);
$trackingReference
=
$this
->
getRequest
()
->
getParam
(
'order_reference'
);
$this
->
logger
->
info
(
'Tracking reference:'
,
[
$trackingReference
]);
$channel
=
$this
->
getStoreUrl
();
$this
->
logger
->
info
(
'Channel:'
,
[
$channel
]);
if
(
$trackingReference
)
{
$trackingUrl
=
sprintf
(
UData
::
TRACKING
,
$channel
,
$trackingReference
);
try
{
$this
->
curl
->
get
(
$trackingUrl
);
$response
=
$this
->
curl
->
getBody
();
$this
->
logger
->
info
(
'Response:'
,
[
$response
]);
$decodedResponse
=
json_decode
(
$response
,
true
);
$this
->
logger
->
info
(
'Decoded Response:'
,
[
$decodedResponse
]);
if
(
is_array
(
$decodedResponse
)
&&
isset
(
$decodedResponse
[
0
]))
{
$shipmentData
=
$decodedResponse
[
0
];
// Save data to the registry
$this
->
registry
->
register
(
'shipment_data'
,
$shipmentData
);
$this
->
logger
->
info
(
'Shipment data registered in the registry.'
);
}
else
{
$this
->
logger
->
info
(
'Unexpected response format.'
);
}
}
catch
(
\Exception
$e
)
{
$this
->
logger
->
info
(
'Track error: '
.
$e
->
getMessage
());
$this
->
messageManager
->
addErrorMessage
(
__
(
'Unable to track the order.'
));
// Return early the response is not valid
return
$this
->
resultPageFactory
->
create
();
}
}
return
$this
->
resultPageFactory
->
create
();
}
private
function
getStoreUrl
():
string
{
$url
=
$this
->
storeManager
->
getStore
()
->
getBaseUrl
();
...
...
This diff is collapsed.
Click to expand it.
etc/frontend/di.xml
+
0
−
5
Edit
View file @
436e55f7
...
...
@@ -13,9 +13,4 @@
<argument
name=
"logger"
xsi:type=
"object"
>
Psr\Log\LoggerInterface
</argument>
</arguments>
</type>
<type
name=
"Magento\Framework\View\Layout"
>
<arguments>
<argument
name=
"debug"
xsi:type=
"boolean"
>
true
</argument>
</arguments>
</type>
</config>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment