Configuration vs Scopes/Stores
-
03-10-2020 - |
Question
I work on Magento 2.1
.
I have one website, store and store view. I understand that if in future client needs to add another language to store he will add just a store view. Am I correct?
Now, I have to save some values in core_config_data
. What is the best way to save them, to not disturb adding stores/store views/websites in future (especially store view is interesting for me) in future?
Now when I track saving values in adminhtml - they are saved in Default config
and in db in column scope
they get default
and in column scope_id
they get 0
. Is this correct policy to leave it like that?
I use method saveConfig
from \Magento\Framework\App\Config\ConfigResource\ConfigInterface
,
like this:
$this->config->saveConfig('path/to/field', 1, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $this->provideAdminStoreId());
Is that correct way?
Solution
you current way is best to adding the values for core config.
$this->config->saveConfig('path/to/field', 1, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $this->provideAdminStoreId());
yes it is correct way leave it like that.
it all depend on how you retrieve data. You have to add scope check in retrieving data.
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
$this->scopeConfig->getValue(
'path/to/field',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);