storeRepository = $storeRepository; $this->configInterface = $configInterface; $this->logo = $logo; } /** * @param null $scopeCode * @return bool */ public function isEnabled($scopeCode = null) { return $this->scopeConfig->isSetFlag( self::ACTIVE_CAMPAIGN_GENERAL_STATUS, ScopeInterface::SCOPE_STORES, $scopeCode ); } /** * @param null $scopeCode * @return mixed */ public function getApiUrl($scopeCode = null) { return $this->scopeConfig->getValue( self::ACTIVE_CAMPAIGN_GENERAL_API_URL, ScopeInterface::SCOPE_STORES, $scopeCode ); } /** * @param null $scopeCode * @return mixed */ public function getApiKey($scopeCode = null) { return $this->scopeConfig->getValue( self::ACTIVE_CAMPAIGN_GENERAL_API_KEY, ScopeInterface::SCOPE_STORES, $scopeCode ); } /** * @param null $scopeCode * @return mixed */ public function getConnectionId($scopeCode = null) { return $this->scopeConfig->getValue( self::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, ScopeInterface::SCOPE_STORES, $scopeCode ); } /** * @param null $scopeCode * @return string */ public function getStoreLogo($scopeCode = null) { $folderName = \Magento\Config\Model\Config\Backend\Image\Logo::UPLOAD_DIR; $storeLogoPath = $this->scopeConfig->getValue( 'design/header/logo_src', \Magento\Store\Model\ScopeInterface::SCOPE_STORES, $scopeCode ); $path = $folderName . '/' . $storeLogoPath; $logoUrl = $this->_urlBuilder->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]) . $path; if ($storeLogoPath !== null) { $url = $logoUrl; } else { $url = $this->logo->getLogoSrc(); } return $url; } /** * Converts to cents the price amount * * @param float|null $price * @return int */ public function priceToCents($price = 0.0) { return (int) (round($price, 2) * 100); } /** * @param $allConnections * @return bool * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function checkConnections($allConnections) { if ($allConnections['success']) { $activeConnectionIds = []; foreach ($allConnections['data']['connections'] as $connection) { $store = $this->storeRepository->get($connection['externalid']); $connectionId = $this->getConnectionId($store->getId()); $activeConnectionIds[] = $connection['id']; if ($connectionId != $connection['id']) { $this->saveConfig( self::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, $connection['id'], $store->getId() ); } } $stores = $this->storeRepository->getList(); foreach ($stores as $store) { if ($store->getId()) { $connectionId = $this->getConnectionId($store->getId()); if (($connectionId) && (!in_array($connectionId, $activeConnectionIds))) { $this->configInterface->deleteConfig( self::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, ScopeInterface::SCOPE_STORES, $store->getId() ); } } } return true; } return false; } /** * @param $path * @param $value * @param $scopeId */ public function saveConfig($path, $value, $scopeId) { $scope = ($scopeId) ? ScopeInterface::SCOPE_STORES : ScopeConfigInterface::SCOPE_TYPE_DEFAULT; $this->configInterface->saveConfig($path, $value, $scope, $scopeId); } }