Skip to content

Commit

Permalink
Merged PR 55236: Allow product notifications to be configured differe…
Browse files Browse the repository at this point in the history
…ntly in child scopes

## What's being changed

We have removed conditions from the backend model for the product notification config model, and we have added the `account_id` to the system config.

## Why it's being changed

The product notification `account_id` value was not being updated for multi-scopes due to the set condition being too strict. If a product notification was set at default level, this could not be overridden at website or store view level (because `getStoredAccountId` returned the inherited value from the default parent).

We have also allowed the value to be set manually via the CLI using the config set command for completion.

## How to review / test this change

- Run the following command: `bin/magento config:set "connector_api_credentials/api/account_id" 1234567890`
- Navigate to Configuration > Automation > Product Notifications
- Disable the feature
- Re-enable the feature and ensure the value in the config table matches your scoped account. You can run `bin/magento config:show "connector_api_credentials/api/account_id"` to confirm from the CLI.

Related work items: #257022
  • Loading branch information
pvpcookie committed Jun 21, 2024
1 parent 3e38d3d commit 7710129
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
41 changes: 18 additions & 23 deletions Model/Adminhtml/Backend/BackInStockEnabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,38 +78,33 @@ public function afterSave()
{
$websiteId = $this->helper->getWebsiteForSelectedScopeInAdmin()->getId();
if ($this->isValueChanged() && $this->helper->isEnabled($websiteId)) {
if ($this->getValue() && !$this->getStoredAccountId()) {
$client = $this->helper->getWebsiteApiClient(
$websiteId
);

$accountId = $this->account->getAccountId(
$client->getAccountInfo($websiteId)
);

$this->configWriter->save(
Config::PATH_FOR_ACCOUNT_ID,
$accountId,
$this->getScope(),
$this->getScopeId()
);
}
$this->configWriter->save(
Config::PATH_FOR_ACCOUNT_ID,
$this->fetchAccountId($websiteId),
$this->getScope(),
$this->getScopeId()
);
}

return parent::afterSave();
}

/**
* Get account id.
* Fetch account id.
*
* @param int $websiteId
*
* @return string|null
* @return string
* @throws \Exception
*/
private function getStoredAccountId(): ?string
private function fetchAccountId(int $websiteId)
{
return $this->scopeConfig->getValue(
Config::PATH_FOR_ACCOUNT_ID,
$this->getScope(),
$this->getScopeId()
$client = $this->helper->getWebsiteApiClient(
$websiteId
);

return $this->account->getAccountId(
$client->getAccountInfo($websiteId)
);
}
}
3 changes: 3 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<field id="endpoint_subdomain" translate="label" sortOrder="4" showInDefault="0" showInStore="0" showInWebsite="0">
<label>API Endpoint Subdomain</label>
</field>
<field id="account_id" translate="label" sortOrder="4" showInDefault="0" showInStore="0" showInWebsite="0">
<label>API account ID</label>
</field>
<field id="integration_setup" translate="comment label" type="button" sortOrder="4" showInStore="0"
showInWebsite="1" showInDefault="1">
<label></label>
Expand Down

0 comments on commit 7710129

Please sign in to comment.