123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <?php
- namespace MarketplaceRepository;
- class SettingsRepository
- implements \Core\App\Repository\Marketplace\SettingsInterface
- {
- const VERSION_PLATFORM_CODE = 'SHOPIFY';
- const VERSION_FILE = 'https://facturis-online.ro/plugins/latest_versions.txt';
- const VERSION_SEPARATOR = ", ";
- public $settings;
- public $shop;
- public $db;
- public function __construct($db, $shop = '')
- {
- $this->conn = $db->getConnection();
- $this->db = $db;
-
- $this->setShop($shop);
- $settings = $db->getSettings($this->shop);
-
- $settingsFactory = new \Core\App\Factory\SettingsFactory();
- $this->settings = $settingsFactory->createSettings(
- isset($settings['fsync_auth_apikey']) ? $settings['fsync_auth_apikey'] : '',
- isset($settings['fsync_auth_username']) ? $settings['fsync_auth_username'] : '',
- isset($settings['fsync_auth_password']) ? $settings['fsync_auth_password'] : '',
- isset($settings['fsync_auth_fiscalcode']) ? $settings['fsync_auth_fiscalcode'] : '',
- isset($settings['fsync_option_autosyncstock']) ? $settings['fsync_option_autosyncstock'] : '',
- isset($settings['fsync_option_autosyncorder']) ? $settings['fsync_option_autosyncorder'] : '',
- isset($settings['fsync_option_filterstock']) ? $settings['fsync_option_filterstock'] : '',
- isset($settings['fsync_option_syncordersas']) ? $settings['fsync_option_syncordersas'] : '',
- isset($settings['fsync_option_proformaserie']) ? $settings['fsync_option_proformaserie'] : '',
- isset($settings['fsync_option_daysago']) ? $settings['fsync_option_daysago'] : '',
- isset($settings['fsync_option_locations']) ? $settings['fsync_option_locations'] : null,
- isset($settings['fsync_option_withdiscount']) ? $settings['fsync_option_withdiscount'] : ''
- );
- }
- public function getAuthApiKey()
- {
- return $this->settings->getAuthApiKey();
- }
- public function getAuthUsername()
- {
- return $this->settings->getAuthUsername();
- }
- public function getAuthPassword()
- {
- return $this->settings->getAuthPassword();
- }
- public function getAuthFiscalCode()
- {
- return $this->settings->getAuthFiscalCode();
- }
- public function getOptionAutoStockSync()
- {
- return $this->settings->getOptionAutoStockSync();
- }
- public function getOptionAutoOrderSync()
- {
- return $this->settings->getOptionAutoOrderSync();
- }
- public function getOptionStockFilter()
- {
- return $this->settings->getOptionStockFilter();
- }
- public function getOptionOrderOrProforma()
- {
- return $this->settings->getOptionOrderOrProforma();
- }
- public function getOptionProformaSerie()
- {
- return $this->settings->getOptionProformaSerie();
- }
- public function getOptionOrderedDaysAgo()
- {
- return $this->settings->getOptionOrderedDaysAgo();
- }
- public function getOptionLocations()
- {
- return $this->settings->getOptionLocations();
- }
- public function getCustomFieldBank()
- {
- return $this->settings->getCustomFieldBank();
- }
- public function getCustomFieldAccount()
- {
- return $this->settings->getCustomFieldAccount();
- }
- public function getCustomFieldCompany()
- {
- return $this->settings->getCustomFieldCompany();
- }
- public function getCustomFieldFiscalCode()
- {
- return $this->settings->getCustomFieldFiscalCode();
- }
- public function getCustomFieldRegNumber()
- {
- return $this->settings->getCustomFieldRegNumber();
- }
- public function getSyncDataTypes()
- {
- return $this->settings->getSyncDataTypes();
- }
- public function getSyncOptions()
- {
- return array(
- 'fsync_option_autosyncstock' => $this->settings->getOptionAutoStockSync(),
- 'fsync_option_autosyncorder' => $this->settings->getOptionAutoOrderSync(),
- 'fsync_option_filterstock' => $this->settings->getOptionStockFilter(),
- 'fsync_option_syncordersas' => $this->settings->getOptionOrderOrProforma(),
- 'fsync_option_proformaserie' => $this->settings->getOptionProformaSerie(),
- 'fsync_option_daysago' => $this->settings->getOptionOrderedDaysAgo(),
- 'fsync_option_locations' => $this->settings->getOptionLocations(),
- 'fsync_option_withdiscount' => $this->settings->getOptionWithDiscount()
- );
- }
- public function getSyncAuth()
- {
- return array(
- 'fsync_auth_apikey' => $this->settings->getAuthApiKey(),
- 'fsync_auth_username' => $this->settings->getAuthUsername(),
- 'fsync_auth_password' => $this->settings->getAuthPassword(),
- 'fsync_auth_fiscalcode' => $this->settings->getAuthFiscalCode()
- );
- }
- public function getToken()
- {
- return $this->db->getToken($this->shop);
- }
- public function getShop()
- {
- if(!empty($this->shop))
- {
- return str_replace(SHOPIFY_DOMAIN, '', $this->shop);
- }
- else
- {
- throw new \Exception('A shop name is required for the script to run');
- }
- }
- public function getVersionLink()
- {
- return VERSION_LINK;
- }
-
- public function getVersion()
- {
- return VERSION;
- }
- public function setShop($shop = '')
- {
- $this->shop = '';
- if(!empty($shop))
- {
- $this->shop = $shop;
- }
- else
- {
- if(isset($_GET['shop']))
- {
- $this->shop = $_GET['shop'];
- }
- }
- }
- public function getSyncOrdersAs()
- {
- return array(
- \Core\App\Factory\SettingsFactory::SELECT_ORDER,
- \Core\App\Factory\SettingsFactory::SELECT_PROFORMA
- );
- }
- public function getAutoSyncOptions()
- {
- return array(
- \Core\App\Factory\SettingsFactory::AUTO_SYNC_ENABLED,
- \Core\App\Factory\SettingsFactory::AUTO_SYNC_DISABLED
- );
- }
- public function getOptionWithDiscount()
- {
- return $this->settings->getOptionWithDiscount();
- }
- public function getEnabledDisabledOptions()
- {
- return array(
- \Core\App\Factory\SettingsFactory::SYNC_ENABLED,
- \Core\App\Factory\SettingsFactory::SYNC_DISABLED
- );
- }
- public function checkLatestVersion($language)
- {
- $errorMessage = '<h4><span class="alert danger alert-box">' . $language->get('version_check_error') . '</span></h4>';
- $versionFile = @fopen(self::VERSION_FILE, "r") or die($errorMessage);
- while(!feof($versionFile)) {
- $versionRow = explode(self::VERSION_SEPARATOR, fgets($versionFile));
- if($versionRow[0] == self::VERSION_PLATFORM_CODE && isset($versionRow[1]))
- {
- if(trim($this->getVersion()) == trim($versionRow[1]))
- {
- $successMessage = '<small style="color: #74B807 !important">' . $language->get('version_check_success') . '</small>';
- }
- else
- {
- $successMessage = '<small style="color: red !important">' . $language->get('version_check_new') . ': <b>' . $versionRow[1] . '</b>';
- if(isset($versionRow[2]) && !empty($versionRow[2]))
- {
- $successMessage .= ' ' . $language->get('version_check_link_1') . '</small> <u><a style="color: red !important" target="_blank" href="' . $versionRow[2] . '">';
- $successMessage .= $language->get('version_check_link_2');
- $successMessage .= '</a></u>';
- }
- }
- echo $successMessage;
- exit;
- }
- }
- echo '';
- fclose($versionFile);
- }
- }
|