Skip to content

Commit

Permalink
adding ability to override just the MICE extension URL in devo (#446)
Browse files Browse the repository at this point in the history
* adding ability to override just the MICE extension URL in devo

* changeback config

* adding a comment
  • Loading branch information
sol-loup committed Sep 22, 2023
1 parent d67d3b4 commit c1a47c7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
32 changes: 25 additions & 7 deletions app/code/Meta/BusinessExtension/Helper/GraphAPIAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
namespace Meta\BusinessExtension\Helper;

use CURLFile;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\BadResponseException;
Expand Down Expand Up @@ -83,6 +85,11 @@ class GraphAPIAdapter
*/
private $graphAPIConfig;

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* GraphAPIAdapter constructor.
*
Expand All @@ -91,13 +98,15 @@ class GraphAPIAdapter
* @param CurlFactory $curlFactory
* @param FileFactory $fileFactory
* @param GraphAPIConfig $graphAPIConfig
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
SystemConfig $systemConfig,
LoggerInterface $logger,
CurlFactory $curlFactory,
FileFactory $fileFactory,
GraphAPIConfig $graphAPIConfig
SystemConfig $systemConfig,
LoggerInterface $logger,
CurlFactory $curlFactory,
FileFactory $fileFactory,
GraphAPIConfig $graphAPIConfig,
ScopeConfigInterface $scopeConfig
) {
$this->logger = $logger;
$this->accessToken = $systemConfig->getAccessToken();
Expand All @@ -112,6 +121,7 @@ public function __construct(
$this->curlFactory = $curlFactory;
$this->fileFactory = $fileFactory;
$this->graphAPIConfig = $graphAPIConfig;
$this->scopeConfig = $scopeConfig;
}

/**
Expand Down Expand Up @@ -226,7 +236,7 @@ function ($a) {
private function callApiForFileTransfer($endpoint, $params, $filePath)
{
try {
$endpoint = "{$this->graphAPIConfig->getGraphBaseURL()}v{$this->graphAPIVersion}/".$endpoint;
$endpoint = "{$this->graphAPIConfig->getGraphBaseURL()}v{$this->graphAPIVersion}/" . $endpoint;
$curl = $this->curlFactory->create();
$fileBaseName = $this->fileFactory->create(['filename' => $filePath, 'module' => ''])->getName();

Expand Down Expand Up @@ -348,7 +358,15 @@ public function getCommerceExtensionIFrameURL($externalBusinessId, $accessToken
];
$response = $this->callApi('GET', 'fbe_business', $request);
$response = json_decode($response->getBody()->__toString(), true);
return $response['commerce_extension']['uri'];
$baseURLOverride = $this->scopeConfig->getValue(
'facebook/internal/extension_base_url',
ScopeInterface::SCOPE_STORE
);
$uri = $response['commerce_extension']['uri'];
if ($baseURLOverride) {
$uri = str_replace('https://www.commercepartnerhub.com/', $baseURLOverride, $uri);
}
return $uri;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions app/code/Meta/BusinessExtension/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
</debug>
<!-- Internal. Overrides default graph base URL
<internal>
<graph_base_url>
https://graph.facebook.com/
</graph_base_url>
</internal> -->
<graph_base_url>https://graph.facebook.com/</graph_base_url>
<extension_base_url>https://www.201331.od.commercepartnerhub.com/</extension_base_url>
</internal>-->
</facebook>
</default>
</config>

0 comments on commit c1a47c7

Please sign in to comment.