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
d40f977b
Commit
d40f977b
authored
6 months ago
by
Christel Loftus
Browse files
Options
Downloads
Patches
Plain Diff
change shipping description
parent
b77abc38
No related branches found
Branches containing commit
No related tags found
1 merge request
!14
Start webhook implementation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Observer/ModifyShippingDescription.php
+70
-0
70 additions, 0 deletions
Observer/ModifyShippingDescription.php
etc/events.xml
+5
-0
5 additions, 0 deletions
etc/events.xml
with
75 additions
and
0 deletions
Observer/ModifyShippingDescription.php
0 → 100644
+
70
−
0
View file @
d40f977b
<?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
;
}
}
This diff is collapsed.
Click to expand it.
etc/events.xml
+
5
−
0
View file @
d40f977b
...
...
@@ -3,4 +3,9 @@
<event
name=
"sales_order_save_after"
>
<observer
name=
"order_create_webhook"
instance=
"BobGroup\BobGo\Observer\OrderCreateWebhook"
/>
</event>
<!-- app/code/Vendor/Module/etc/events.xml -->
<event
name=
"sales_order_place_before"
>
<observer
name=
"modify_shipping_description"
instance=
"BobGroup\BobGo\Observer\ModifyShippingDescription"
/>
</event>
</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