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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgo-magento-extension
Merge requests
!14
Start webhook implementation
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
Start webhook implementation
magento_webhooks
into
dev
Overview
3
Commits
32
Pipelines
0
Changes
9
Merged
Christel Loftus
requested to merge
magento_webhooks
into
dev
10 months ago
Overview
3
Commits
32
Pipelines
0
Changes
2
0
0
Merge request reports
Compare
version 11
version 15
e841e5b6
8 months ago
version 14
b0265f41
9 months ago
version 13
57d26adc
9 months ago
version 12
d40f977b
9 months ago
version 11
b77abc38
9 months ago
version 10
dbcb4eb7
9 months ago
version 9
366c40ca
10 months ago
version 8
bb9b08a1
10 months ago
version 7
2c7e23cd
10 months ago
version 6
9d91f05a
10 months ago
version 5
716ecb04
10 months ago
version 4
10570227
10 months ago
version 3
4b9bbb9f
10 months ago
version 2
6d003aac
10 months ago
version 1
dd64a2de
10 months ago
dev (base)
and
version 12
latest version
62241942
32 commits,
8 months ago
version 15
e841e5b6
15 commits,
8 months ago
version 14
b0265f41
14 commits,
9 months ago
version 13
57d26adc
13 commits,
9 months ago
version 12
d40f977b
12 commits,
9 months ago
version 11
b77abc38
11 commits,
9 months ago
version 10
dbcb4eb7
10 commits,
9 months ago
version 9
366c40ca
9 commits,
10 months ago
version 8
bb9b08a1
8 commits,
10 months ago
version 7
2c7e23cd
7 commits,
10 months ago
version 6
9d91f05a
6 commits,
10 months ago
version 5
716ecb04
5 commits,
10 months ago
version 4
10570227
4 commits,
10 months ago
version 3
4b9bbb9f
3 commits,
10 months ago
version 2
6d003aac
2 commits,
10 months ago
version 1
dd64a2de
1 commit,
10 months ago
Show latest version
2 files
+
75
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Observer/ModifyShippingDescription.php
0 → 100644
+
70
−
0
View file @ d40f977b
Edit in single-file editor
Open in Web IDE
<?php
namespace
BobGroup\BobGo\Observer
;
use
Magento\Framework\Event\ObserverInterface
;
use
Magento\Framework\Event\Observer
;
use
Psr\Log\LoggerInterface
;
class
ModifyShippingDescription
implements
ObserverInterface
{
public
const
CODE
=
'bobgo'
;
protected
$logger
;
public
function
__construct
(
LoggerInterface
$logger
)
{
$this
->
logger
=
$logger
;
}
public
function
execute
(
Observer
$observer
)
{
// Get the order object from the event
$order
=
$observer
->
getEvent
()
->
getOrder
();
// Get the current shipping description
$shippingDescription
=
$order
->
getShippingDescription
();
// Log the original shipping description
$this
->
logger
->
info
(
'Original Shipping Description: '
.
$shippingDescription
);
// Get the shipping method used in the order (e.g., bobgo_10303_39_1)
$shippingMethod
=
$order
->
getShippingMethod
();
// Get the method title from the shipping description (which might already include the title)
$methodTitle
=
$this
->
extractMethodTitle
(
$shippingDescription
);
// Log the method title for debugging
$this
->
logger
->
info
(
'Extracted Method Title: '
.
$methodTitle
);
// Set the new dynamic shipping description based only on MethodTitle
$newDescription
=
$methodTitle
;
// Update the shipping description in the order
$order
->
setShippingDescription
(
$newDescription
);
// Optionally log the new shipping description
$this
->
logger
->
info
(
'Updated Shipping Description: '
.
$newDescription
);
}
/**
* Helper function to extract the method title from the original shipping description
*
* @param string $shippingDescription
* @return string
*/
private
function
extractMethodTitle
(
$shippingDescription
)
{
// Find the position of the last dash in the string
$lastDashPosition
=
strrpos
(
$shippingDescription
,
' - '
);
// If a dash is found, extract the part after the last dash
if
(
$lastDashPosition
!==
false
)
{
return
trim
(
substr
(
$shippingDescription
,
$lastDashPosition
+
3
));
// +3 to skip the ' - ' part
}
// If no dash is found, return the full description (fallback)
return
$shippingDescription
;
}
}
Loading