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
abe3e0eb
Commit
abe3e0eb
authored
7 months ago
by
Christel Loftus
Browse files
Options
Downloads
Patches
Plain Diff
tracking payload data being displayed
parent
d5dc33c1
No related branches found
Branches containing commit
No related tags found
2 merge requests
!20
1.0.41
,
!15
Tracking page
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Block/TrackingBlock.php
+11
-12
11 additions, 12 deletions
Block/TrackingBlock.php
Controller/Tracking/Index.php
+10
-49
10 additions, 49 deletions
Controller/Tracking/Index.php
view/frontend/templates/tracking/index.phtml
+40
-34
40 additions, 34 deletions
view/frontend/templates/tracking/index.phtml
with
61 additions
and
95 deletions
Block/TrackingBlock.php
+
11
−
12
View file @
abe3e0eb
...
...
@@ -3,25 +3,24 @@
namespace
BobGroup\BobGo\Block
;
use
Magento\Framework\View\Element\Template
;
use
Magento\Framework\Registry
;
class
TrackingBlock
extends
\Magento\Framework\View\Element\Template
{
protected
$re
sponse
;
protected
$re
gistry
;
protected
function
_toHtml
()
{
$this
->
_logger
->
info
(
'Block HTML rendered: '
.
$this
->
getNameInLayout
());
return
parent
::
_toHtml
();
}
public
function
setResponse
(
array
$response
):
self
{
$this
->
_response
=
$response
;
return
$this
;
public
function
__construct
(
Template
\Context
$context
,
Registry
$registry
,
array
$data
=
[]
)
{
$this
->
registry
=
$registry
;
parent
::
__construct
(
$context
,
$data
);
}
public
function
getResponse
()
{
return
$this
->
re
sponse
;
return
$this
->
re
gistry
->
registry
(
'shipment_data'
)
;
}
}
This diff is collapsed.
Click to expand it.
Controller/Tracking/Index.php
+
10
−
49
View file @
abe3e0eb
<?php
namespace
BobGroup\BobGo\Controller\Tracking
;
use
Psr\Log\LoggerInterface
;
use
Magento\Framework\App\Action\Context
;
use
Magento\Framework\View\Result\PageFactory
;
use
BobGroup\BobGo\Model\Carrier\UData
;
use
Magento\Framework\Registry
;
use
Psr\Log\LoggerInterface
;
use
Magento\Framework\Controller\Result\JsonFactory
;
use
Magento\Framework\HTTP\Client\Curl
;
use
Magento\Store\Model\StoreManagerInterface
;
use
BobGroup\BobGo\Model\Carrier\UData
;
class
Index
extends
\Magento\Framework\App\Action\Action
{
...
...
@@ -15,6 +16,7 @@ class Index extends \Magento\Framework\App\Action\Action
protected
$jsonFactory
;
protected
$curl
;
protected
$logger
;
protected
$registry
;
protected
StoreManagerInterface
$storeManager
;
public
function
__construct
(
...
...
@@ -23,13 +25,15 @@ class Index extends \Magento\Framework\App\Action\Action
JsonFactory
$jsonFactory
,
LoggerInterface
$logger
,
StoreManagerInterface
$storeManager
,
Curl
$curl
Curl
$curl
,
Registry
$registry
// Add Registry
)
{
$this
->
resultPageFactory
=
$resultPageFactory
;
$this
->
jsonFactory
=
$jsonFactory
;
$this
->
logger
=
$logger
;
$this
->
storeManager
=
$storeManager
;
$this
->
curl
=
$curl
;
$this
->
registry
=
$registry
;
// Assign Registry
parent
::
__construct
(
$context
);
}
...
...
@@ -44,35 +48,13 @@ class Index extends \Magento\Framework\App\Action\Action
$this
->
logger
->
info
(
'Channel:'
,
[
$channel
]);
// if ($trackingReference) {
// $trackingUrl = sprintf(UData::TRACKING, $channel, $trackingReference);
//
// try {
// // Make the API call
// $this->curl->get($trackingUrl);
// $response = $this->curl->getBody();
//
// // Optionally, you can decode the response if it's JSON
// $response = json_decode($response, true);
//
// // Handle the response (e.g., display it on the page)
// $resultJson = $this->jsonFactory->create();
// return $resultJson->setData($response);
//
// } catch (\Exception $e) {
// $this->messageManager->addErrorMessage(__('Unable to track the order.'));
// }
// }
if
(
$trackingReference
)
{
$trackingUrl
=
sprintf
(
UData
::
TRACKING
,
$channel
,
$trackingReference
);
try
{
// Make the API call
$this
->
curl
->
get
(
$trackingUrl
);
$response
=
$this
->
curl
->
getBody
();
// Decode the response
$this
->
logger
->
info
(
'Response:'
,
[
$response
]);
$decodedResponse
=
json_decode
(
$response
,
true
);
...
...
@@ -81,31 +63,10 @@ class Index extends \Magento\Framework\App\Action\Action
if
(
is_array
(
$decodedResponse
)
&&
isset
(
$decodedResponse
[
0
]))
{
$shipmentData
=
$decodedResponse
[
0
];
// Set response in the block
// In your controller action or block:
$layout
=
$this
->
_view
->
getLayout
();
$this
->
logger
->
info
(
'Layout Handles: '
.
implode
(
', '
,
$layout
->
getUpdate
()
->
getHandles
()));
$blocks
=
$layout
->
getAllBlocks
();
$blockNames
=
[];
foreach
(
$blocks
as
$block
)
{
$blockNames
[]
=
$block
->
getNameInLayout
();
}
$this
->
logger
->
info
(
'Available Blocks:'
,
$blockNames
);
$block
=
$layout
->
getBlock
(
'bobgo.tracking.index'
);
$this
->
logger
->
info
(
'BobGo block:'
,
[
$block
]);
// Save data to the registry
$this
->
registry
->
register
(
'shipment_data'
,
$shipmentData
);
$this
->
logger
->
info
(
'Shipment data registered in the registry.'
);
if
(
$block
)
{
$block
->
setResponse
(
$shipmentData
);
$this
->
logger
->
info
(
'Block found and data set.'
);
}
else
{
$this
->
logger
->
info
(
'Block not found.'
);
}
}
else
{
$this
->
logger
->
info
(
'Unexpected response format.'
);
}
...
...
This diff is collapsed.
Click to expand it.
view/frontend/templates/tracking/index.phtml
+
40
−
34
View file @
abe3e0eb
...
...
@@ -39,38 +39,44 @@
</div>
</form>
<!-- -->
<?php
//if ($response = $block->getResponse()): ?>
<!--
<
div
class
=
"tracking-response"
>-->
<!--
<!--
Handle
and
display
the
API
response
-->-->
<!--
<
h2
>--><?
php
//echo __('Tracking Information'); ?><!--</h2>-->
<!--
<
p
>--><?
php
//echo __('Status: ' . $response['status']); ?><!--</p>-->
<!--
<!--
Add
more
fields
as
needed
from
the
response
-->-->
<!--
</
div
>-->
<!--
--><?
php
//endif; ?>
<?
php
//<!-- --><?php
// $shipmentData = $block->getResponse();
// if ($shipmentData && is_array($shipmentData)) {
// foreach ($shipmentData as $shipment) {
// echo '<div class="tracking-details">';
// echo '<h2>' . __('Shipping Details') . '</h2>';
// echo '<p>' . __('Shipment: ') . $shipment['shipment_tracking_reference'] . '</p>';
// echo '<p>' . __('Order: ') . ltrim($shipment['order_number'], '0') . '</p>';
// echo '<p>' . __('Courier: ') . $shipment['courier_name'] . '</p>';
//
// echo '<h2>' . __('Tracking Details') . '</h2>';
// echo '<p>' . __('Current Status: ') . $shipment['status_friendly'] . '</p>';
//
// echo '<footer>';
// echo '<p>' . __('For additional information, please contact BobGo (support@bobgo.co.za).') . '</p>';
// echo '<img src="' . $shipment['courier_logo'] . '" alt="Courier Logo" style="width: 100px;"/>';
// echo '</footer>';
// echo '</div>';
// }
// } else {
// echo '<p>No tracking data available.</p>';
// }
// ?>
<?php
$shipmentData
=
$this
->
getResponse
();
if
(
$shipmentData
&&
is_array
(
$shipmentData
))
{
echo
'<div class="tracking-details">'
;
echo
'<h2>'
.
__
(
'Shipping Details'
)
.
'</h2>'
;
// Ensure each accessed array key exists and contains an array where expected
if
(
isset
(
$shipmentData
[
'shipment_tracking_reference'
]))
{
echo
'<p>'
.
__
(
'Shipment: '
)
.
$shipmentData
[
'shipment_tracking_reference'
]
.
'</p>'
;
}
if
(
isset
(
$shipmentData
[
'order_number'
]))
{
echo
'<p>'
.
__
(
'Order: '
)
.
ltrim
(
$shipmentData
[
'order_number'
],
'0'
)
.
'</p>'
;
}
if
(
isset
(
$shipmentData
[
'courier_name'
]))
{
echo
'<p>'
.
__
(
'Courier: '
)
.
$shipmentData
[
'courier_name'
]
.
'</p>'
;
}
echo
'<h2>'
.
__
(
'Tracking Details'
)
.
'</h2>'
;
if
(
isset
(
$shipmentData
[
'status_friendly'
]))
{
echo
'<p>'
.
__
(
'Current Status: '
)
.
$shipmentData
[
'status_friendly'
]
.
'</p>'
;
}
if
(
isset
(
$shipmentData
[
'courier_logo'
]))
{
echo
'<footer>'
;
echo
'<p>'
.
__
(
'For additional information, please contact BobGo (support@bobgo.co.za).'
)
.
'</p>'
;
echo
'<img src="'
.
$shipmentData
[
'courier_logo'
]
.
'" alt="Courier Logo" style="width: 100px;"/>'
;
echo
'</footer>'
;
}
echo
'</div>'
;
}
else
{
echo
'<p>No tracking data available.</p>'
;
}
?>
</div>
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