diff --git a/src/Model/Config.php b/src/Model/Config.php index b2dc09b..cb84ba6 100644 --- a/src/Model/Config.php +++ b/src/Model/Config.php @@ -7,16 +7,13 @@ namespace Elgentos\Rumvision\Model; +use Elgentos\Rumvision\Api\ConfigurationInterface; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; -class Config +class Config implements ConfigurationInterface { - private const CONFIG_RUMVISION_ENALBED = 'elgentos_rumvision/general/enabled'; - private const CONFIG_RUMVISION_TRACKING_ID = 'elgentos_rumvision/general/tracking_id'; - private const CONFIG_RUMVISION_HOST_NAME = 'elgentos_rumvision/general/hostname'; - /** * @param ScopeConfigInterface $config * @param StoreManagerInterface $storeManager @@ -26,23 +23,26 @@ public function __construct( private StoreManagerInterface $storeManager, ) {} - public function isEnabled() :bool + public function isEnabled(int $storeId = null): bool { - return (bool)$this->config->getValue(self::CONFIG_RUMVISION_ENALBED, ScopeInterface::SCOPE_STORE, $this->getStoreId()); + return (bool)$this->config->getValue(self::CONFIG_RUMVISION_ENALBED, ScopeInterface::SCOPE_STORE, $this->getStoreId($storeId)); } - public function getTrackingId() :string + public function getTrackingId(int $storeId = null): string { - return $this->config->getValue(self::CONFIG_RUMVISION_TRACKING_ID, ScopeInterface::SCOPE_STORE, $this->getStoreId()); + return (string)$this->config->getValue(self::CONFIG_RUMVISION_ENALBED, ScopeInterface::SCOPE_STORE, $this->getStoreId($storeId)); } - public function getHostName() :string + public function getHostName(int $storeId = null): string { - return $this->config->getValue(self::CONFIG_RUMVISION_HOST_NAME, ScopeInterface::SCOPE_STORE, $this->getStoreId()); + return (string)$this->config->getValue(self::CONFIG_RUMVISION_ENALBED, ScopeInterface::SCOPE_STORE, $this->getStoreId($storeId)); } - public function getStoreId() :int + public function getStoreId(int $storeId = null) :int { - return (int)$this->storeManager->getStore()->getId(); + return (int)$this->storeManager + ->getStore($storeId) + ->getId(); } + } diff --git a/src/ViewModel/Rumvision.php b/src/ViewModel/Rumvision.php index 70fa789..0df2ccf 100644 --- a/src/ViewModel/Rumvision.php +++ b/src/ViewModel/Rumvision.php @@ -6,29 +6,34 @@ namespace Elgentos\Rumvision\ViewModel; -use Elgentos\Rumvision\Model\Config; +use Elgentos\Rumvision\Api\ConfigurationInterface; use Magento\Framework\View\Element\Block\ArgumentInterface; class Rumvision implements ArgumentInterface { public function __construct( - private Config $config - ) - {} + private ConfigurationInterface $configuration + ) {} - public function shouldIncludeScript(): ?bool + public function shouldIncludeScript(): bool { - return (bool)$this->config->isEnabled() - && (bool)$this->config->getTrackingId(); + $isEnabled = $this->configuration + ->isEnabled(); + $trackingId = $this->configuration + ->getTrackingId(); + + return $isEnabled && $trackingId; } public function getTrackingId() :string { - return $this->config->getTrackingId(); + return $this->configuration + ->getTrackingId(); } public function getHostName() :string { - return $this->config->getHostName(); + return $this->configuration + ->getHostName(); } }