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
6504a7e5
Commit
6504a7e5
authored
9 months ago
by
Christel Loftus
Browse files
Options
Downloads
Patches
Plain Diff
Testing the rates endpoint on extension enabled
parent
7180655e
Branches
Branches containing commit
Tags
1.0.14
Tags containing commit
1 merge request
!6
Rates at checkout
Pipeline
#65018
passed
9 months ago
Stage: tagged_release
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Observer/ConfigChangeObserver.php
+116
-0
116 additions, 0 deletions
Observer/ConfigChangeObserver.php
etc/adminhtml/events.xml
+6
-0
6 additions, 0 deletions
etc/adminhtml/events.xml
etc/di.xml
+6
-0
6 additions, 0 deletions
etc/di.xml
with
128 additions
and
0 deletions
Observer/ConfigChangeObserver.php
0 → 100644
+
116
−
0
View file @
6504a7e5
<?php
namespace
BobGroup\BobGo\Observer
;
use
Magento\Framework\Event\Observer
;
use
Magento\Framework\Event\ObserverInterface
;
use
Magento\Framework\App\Config\ScopeConfigInterface
;
use
Magento\Framework\HTTP\Client\Curl
;
class
ConfigChangeObserver
implements
ObserverInterface
{
protected
$scopeConfig
;
protected
$curl
;
public
function
__construct
(
ScopeConfigInterface
$scopeConfig
,
Curl
$curl
)
{
$this
->
scopeConfig
=
$scopeConfig
;
$this
->
curl
=
$curl
;
}
public
function
execute
(
Observer
$observer
)
{
$sectionId
=
$observer
->
getEvent
()
->
getSection
();
// Ensure we're working with the 'carriers' section
if
(
$sectionId
===
'carriers'
)
{
$isEnabled
=
$this
->
scopeConfig
->
getValue
(
'carriers/bobgo/active'
,
\Magento\Store\Model\ScopeInterface
::
SCOPE_STORE
);
// Check if the extension is enabled
if
(
$isEnabled
)
{
$url
=
'https://api.dev.bobgo.co.za/rates-at-checkout/magento'
;
// Prepare the payload
$payload
=
json_encode
([
"identifier"
=>
"woodemo3.bobgo.co.za"
,
"rate"
=>
[
"origin"
=>
[
"country"
=>
"ZA"
,
"postal_code"
=>
"0181"
,
"province"
=>
"GP"
,
"city"
=>
"Pretoria"
,
"name"
=>
null
,
"address1"
=>
"125 Dallas Avenue"
,
"address2"
=>
"Newlands"
,
"address3"
=>
null
,
"phone"
=>
""
,
"fax"
=>
""
,
"email"
=>
null
,
"address_type"
=>
null
,
"company_name"
=>
""
],
"destination"
=>
[
"country"
=>
"ZA"
,
"postal_code"
=>
"0181"
,
"province"
=>
"GP"
,
"city"
=>
"Pretoria"
,
"name"
=>
null
,
"address1"
=>
null
,
"address2"
=>
""
,
"address3"
=>
null
,
"phone"
=>
""
,
"fax"
=>
""
,
"email"
=>
null
,
"address_type"
=>
null
,
"company_name"
=>
""
,
"shipping_suburb"
=>
"Elarduspark"
],
"currency"
=>
"ZAR"
,
"locale"
=>
"en"
,
"items"
=>
[
[
"name"
=>
"Colours With Variants - Has dimensions - Red"
,
"sku"
=>
"sku-1"
,
"quantity"
=>
2
,
"price"
=>
500
,
"vendor"
=>
""
,
"requires_shipping"
=>
true
,
"taxable"
=>
true
,
"fulfillment_service"
=>
"manual"
,
"properties"
=>
null
,
"product_id"
=>
160824
,
"grams"
=>
2000
,
"height"
=>
20
,
"length"
=>
43
,
"width"
=>
63
,
"variant_id"
=>
160826
,
"shipping_class"
=>
"colours"
,
"shipping_class_id"
=>
41
]
]
]
]);
// Set headers
$this
->
curl
->
addHeader
(
"Accept"
,
"*/*"
);
$this
->
curl
->
addHeader
(
"Accept-Encoding"
,
"deflate, gzip, br"
);
$this
->
curl
->
addHeader
(
"Content-Type"
,
"application/json; charset=utf-8"
);
$this
->
curl
->
addHeader
(
"Host"
,
"api.dev.bobgo.co.za"
);
$this
->
curl
->
addHeader
(
"User-Agent"
,
"Magento/2.x"
);
// Send the request
$this
->
curl
->
post
(
$url
,
$payload
);
// Check response status
if
(
$this
->
curl
->
getStatus
()
==
200
)
{
$response
=
$this
->
curl
->
getBody
();
// Log response or take further actions
}
else
{
// Handle error response
}
}
}
}
}
This diff is collapsed.
Click to expand it.
etc/adminhtml/events.xml
0 → 100644
+
6
−
0
View file @
6504a7e5
<?xml version="1.0"?>
<config
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"urn:magento:framework:Event/etc/events.xsd"
>
<event
name=
"admin_system_config_changed_section_carriers"
>
<observer
name=
"bobgo_config_change_observer"
instance=
"BobGroup\BobGo\Observer\ConfigChangeObserver"
/>
</event>
</config>
This diff is collapsed.
Click to expand it.
etc/di.xml
+
6
−
0
View file @
6504a7e5
...
...
@@ -8,4 +8,10 @@
</argument>
</arguments>
</type>
<type
name=
"BobGroup\BobGo\Observer\ConfigChangeObserver"
>
<arguments>
<argument
name=
"curl"
xsi:type=
"object"
>
Magento\Framework\HTTP\Client\Curl
</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