Skip to content

Commit

Permalink
added install step
Browse files Browse the repository at this point in the history
remove the previous apikey upon installation to force the use of the new Oauth Token
  • Loading branch information
jm-extend committed Sep 4, 2024
1 parent 2f523e0 commit 62840b3
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 2 deletions.
79 changes: 79 additions & 0 deletions Setup/InstallData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
namespace Extend\Warranty\Setup;

use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\StoreManagerInterface;

use Magento\Config\Model\ResourceModel\Config as ConfigResource;


class InstallData implements InstallDataInterface
{
//protected $configWriter;
protected $scopeConfig;
protected $storeManager;
/**
* Config Resource Model
*
* @var ConfigResource
*/
private $configResource;


public const WARRANTY_AUTHENTICATION_CLIENT_ID_XML_PATH = 'warranty/authentication/client_id';
public const WARRANTY_AUTHENTICATION_SANDBOX_CLIENT_ID_XML_PATH = 'warranty/authentication/sandbox_client_id';
public const WARRANTY_AUTHENTICATION_CLIENT_SECRET_XML_PATH = 'warranty/authentication/client_secret';
public const WARRANTY_AUTHENTICATION_SANDBOX_CLIENT_SECRET_XML_PATH = 'warranty/authentication/sandbox_client_secret';
public const WARRANTY_AUTHENTICATION_API_KEY_XML_PATH = 'warranty/authentication/api_key';
public const WARRANTY_AUTHENTICATION_SANDBOX_API_KEY_XML_PATH = 'warranty/authentication/sandbox_api_key';


public function __construct(
ScopeConfigInterface $scopeConfig,
StoreManagerInterface $storeManager,
ConfigResource $configResource,
) {
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
$this->configResource = $configResource;
}

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
// Get all store views
$stores = $this->storeManager->getStores();

foreach ($stores as $store) {
$storeId = $store->getId();

// Fetch the values for each store view
$clientId = $this->scopeConfig->getValue(self::WARRANTY_AUTHENTICATION_CLIENT_ID_XML_PATH,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId);
$clientSecret = $this->scopeConfig->getValue(self::WARRANTY_AUTHENTICATION_CLIENT_SECRET_XML_PATH,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId);
$apiKey = $this->scopeConfig->getValue(self::WARRANTY_AUTHENTICATION_API_KEY_XML_PATH,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId);
$sandboxClientId = $this->scopeConfig->getValue(self::WARRANTY_AUTHENTICATION_SANDBOX_CLIENT_ID_XML_PATH,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId);
$sandboxClientSecret = $this->scopeConfig->getValue(self::WARRANTY_AUTHENTICATION_SANDBOX_CLIENT_SECRET_XML_PATH,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId);
$sandboxApiKey = $this->scopeConfig->getValue(self::WARRANTY_AUTHENTICATION_SANDBOX_API_KEY_XML_PATH,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId);

// Check the conditions and delete the config if necessary
if (empty($clientId) && empty($clientSecret) && !empty($apiKey)) {
$this->configResource->deleteConfig(self::WARRANTY_AUTHENTICATION_API_KEY_XML_PATH,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId);
}

if (empty($sandboxClientId) && empty($sandboxClientSecret) && !empty($sandboxApiKey)) {
$this->configResource->deleteConfig(self::WARRANTY_AUTHENTICATION_SANDBOX_API_KEY_XML_PATH,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $storeId);
}

}
}
}
4 changes: 2 additions & 2 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
<![CDATA[
Unique identifier for your store on the Extend platform.
Go to <a href="https://merchants.extend.com">your Extend merchant dashboard</a>
to find your Client ID and then paste or type it here.
to find your Client ID and then paste or type it here. View the <a href="https://docs.extend.com/reference/authentication">reference documentation</a>.
]]>
</comment>
<depends>
Expand Down Expand Up @@ -312,7 +312,7 @@
<![CDATA[
Unique identifier for your store on the Extend platform.
Go to <a href="https://demo.merchants.extend.com">your Extend merchant dashboard</a>
to find your Client ID and then paste or type it here.
to find your Client ID and then paste or type it below. View the <a href="https://docs.extend.com/reference/authentication">reference documentation</a>.
]]>
</comment>
<depends>
Expand Down

0 comments on commit 62840b3

Please sign in to comment.