diff --git a/Setup/InstallData.php b/Setup/InstallData.php new file mode 100644 index 00000000..086940f1 --- /dev/null +++ b/Setup/InstallData.php @@ -0,0 +1,79 @@ +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); + } + + } + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 3e0aefeb..d4807160 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -232,7 +232,7 @@ your Extend merchant dashboard - 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 reference documentation. ]]> @@ -312,7 +312,7 @@ your Extend merchant dashboard - 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 reference documentation. ]]>