SettingsRepository.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <?php
  2. namespace MarketplaceRepository;
  3. class SettingsRepository
  4. implements \Core\App\Repository\Marketplace\SettingsInterface
  5. {
  6. const VERSION_PLATFORM_CODE = 'SHOPIFY';
  7. const VERSION_FILE = 'https://facturis-online.ro/plugins/latest_versions.txt';
  8. const VERSION_SEPARATOR = ", ";
  9. public $settings;
  10. public $shop;
  11. public $db;
  12. public function __construct($db, $shop = '')
  13. {
  14. $this->conn = $db->getConnection();
  15. $this->db = $db;
  16. $this->setShop($shop);
  17. $settings = $db->getSettings($this->shop);
  18. $settingsFactory = new \Core\App\Factory\SettingsFactory();
  19. $this->settings = $settingsFactory->createSettings(
  20. isset($settings['fsync_auth_apikey']) ? $settings['fsync_auth_apikey'] : '',
  21. isset($settings['fsync_auth_username']) ? $settings['fsync_auth_username'] : '',
  22. isset($settings['fsync_auth_password']) ? $settings['fsync_auth_password'] : '',
  23. isset($settings['fsync_auth_fiscalcode']) ? $settings['fsync_auth_fiscalcode'] : '',
  24. isset($settings['fsync_option_autosyncstock']) ? $settings['fsync_option_autosyncstock'] : '',
  25. isset($settings['fsync_option_autosyncorder']) ? $settings['fsync_option_autosyncorder'] : '',
  26. isset($settings['fsync_option_pdls']) ? $settings['fsync_option_pdls'] : '',
  27. isset($settings['fsync_option_filterstock']) ? $settings['fsync_option_filterstock'] : '',
  28. isset($settings['fsync_option_syncordersas']) ? $settings['fsync_option_syncordersas'] : '',
  29. isset($settings['fsync_option_proformaserie']) ? $settings['fsync_option_proformaserie'] : '',
  30. isset($settings['fsync_option_avizeserie']) ? $settings['fsync_option_avizeserie'] : '',
  31. isset($settings['fsync_option_expfacturaserie']) ? $settings['fsync_option_expfacturaserie'] : '',
  32. isset($settings['fsync_option_daysago']) ? $settings['fsync_option_daysago'] : '',
  33. isset($settings['fsync_option_locations']) ? $settings['fsync_option_locations'] : null,
  34. isset($settings['fsync_option_withdiscount']) ? $settings['fsync_option_withdiscount'] : ''
  35. );
  36. }
  37. public function getAuthApiKey()
  38. {
  39. return $this->settings->getAuthApiKey();
  40. }
  41. public function getAuthUsername()
  42. {
  43. return $this->settings->getAuthUsername();
  44. }
  45. public function getAuthPassword()
  46. {
  47. return $this->settings->getAuthPassword();
  48. }
  49. public function getAuthFiscalCode()
  50. {
  51. return $this->settings->getAuthFiscalCode();
  52. }
  53. public function getOptionAutoStockSync()
  54. {
  55. return $this->settings->getOptionAutoStockSync();
  56. }
  57. public function getOptionAutoOrderSync()
  58. {
  59. return $this->settings->getOptionAutoOrderSync();
  60. }
  61. public function getOptionStockFilter()
  62. {
  63. return $this->settings->getOptionStockFilter();
  64. }
  65. public function getOptionOrderOrProforma()
  66. {
  67. return $this->settings->getOptionOrderOrProforma();
  68. }
  69. public function getOptionProformaSerie()
  70. {
  71. return $this->settings->getOptionProformaSerie();
  72. }
  73. public function getOptionAvizeSerie()
  74. {
  75. return $this->settings->getOptionAvizeSerie();
  76. }
  77. public function getOptionExpfacturaSerie()
  78. {
  79. return $this->settings->getOptionExpfacturaSerie();
  80. }
  81. public function getOptionProformaSerie2()
  82. {
  83. return $this->settings->getOptionProformaSerie2();
  84. }
  85. public function getOptionAvizeSerie2()
  86. {
  87. return $this->settings->getOptionAvizeSerie2();
  88. }
  89. public function getOptionExpfacturaSerie2()
  90. {
  91. return $this->settings->getOptionExpfacturaSerie2();
  92. }
  93. public function getOptionInvoiceSerie()
  94. {
  95. return $this->settings->getOptionInvoiceSerie();
  96. }
  97. public function getOptionOrderedDaysAgo()
  98. {
  99. return $this->settings->getOptionOrderedDaysAgo();
  100. }
  101. public function getOptionLocations()
  102. {
  103. return $this->settings->getOptionLocations();
  104. }
  105. public function getCustomFieldBank()
  106. {
  107. return $this->settings->getCustomFieldBank();
  108. }
  109. public function getCustomFieldAccount()
  110. {
  111. return $this->settings->getCustomFieldAccount();
  112. }
  113. public function getCustomFieldCompany()
  114. {
  115. return $this->settings->getCustomFieldCompany();
  116. }
  117. public function getCustomFieldFiscalCode()
  118. {
  119. return $this->settings->getCustomFieldFiscalCode();
  120. }
  121. public function getCustomFieldRegNumber()
  122. {
  123. return $this->settings->getCustomFieldRegNumber();
  124. }
  125. public function getSyncDataTypes()
  126. {
  127. return $this->settings->getSyncDataTypes();
  128. }
  129. public function getSyncOptions()
  130. {
  131. return array(
  132. 'fsync_option_autosyncstock' => $this->settings->getOptionAutoStockSync(),
  133. 'fsync_option_autosyncorder' => $this->settings->getOptionAutoOrderSync(),
  134. 'fsync_option_filterstock' => $this->settings->getOptionStockFilter(),
  135. 'fsync_option_syncordersas' => $this->settings->getOptionOrderOrProforma(),
  136. 'fsync_option_proformaserie' => $this->settings->getOptionProformaSerie(),
  137. 'fsync_option_avizeserie' => $this->settings->getOptionAvizeSerie(),
  138. 'fsync_option_expfacturaserie' => $this->settings->getOptionExpfacturaSerie(),
  139. 'fsync_option_pdls' => $this->settings->getOptionPdls(),
  140. 'fsync_option_daysago' => $this->settings->getOptionOrderedDaysAgo(),
  141. 'fsync_option_locations' => $this->settings->getOptionLocations(),
  142. 'fsync_option_withdiscount' => $this->settings->getOptionWithDiscount()
  143. );
  144. }
  145. public function getSyncAuth()
  146. {
  147. return array(
  148. 'fsync_auth_apikey' => $this->settings->getAuthApiKey(),
  149. 'fsync_auth_username' => $this->settings->getAuthUsername(),
  150. 'fsync_auth_password' => $this->settings->getAuthPassword(),
  151. 'fsync_auth_fiscalcode' => $this->settings->getAuthFiscalCode()
  152. );
  153. }
  154. public function getToken()
  155. {
  156. return $this->db->getToken($this->shop);
  157. }
  158. public function getShop()
  159. {
  160. if(!empty($this->shop))
  161. {
  162. return str_replace(SHOPIFY_DOMAIN, '', $this->shop);
  163. }
  164. else
  165. {
  166. throw new \Exception('A shop name is required for the script to run');
  167. }
  168. }
  169. public function getVersionLink()
  170. {
  171. return VERSION_LINK;
  172. }
  173. public function getVersion()
  174. {
  175. return VERSION;
  176. }
  177. public function setShop($shop = '')
  178. {
  179. $this->shop = '';
  180. if(!empty($shop))
  181. {
  182. $this->shop = $shop;
  183. }
  184. else
  185. {
  186. if(isset($_GET['shop']))
  187. {
  188. $this->shop = $_GET['shop'];
  189. }
  190. }
  191. }
  192. public function getSyncOrdersAs()
  193. {
  194. return array(
  195. \Core\App\Factory\SettingsFactory::SELECT_ORDER,
  196. \Core\App\Factory\SettingsFactory::SELECT_PROFORMA,
  197. \Core\App\Factory\SettingsFactory::SELECT_EXPFACTURA,
  198. \Core\App\Factory\SettingsFactory::SELECT_AVIZE
  199. );
  200. }
  201. public function getAutoSyncOptions()
  202. {
  203. return array(
  204. \Core\App\Factory\SettingsFactory::AUTO_SYNC_ENABLED,
  205. \Core\App\Factory\SettingsFactory::AUTO_SYNC_DISABLED
  206. );
  207. }
  208. public function getOptionWithDiscount()
  209. {
  210. return $this->settings->getOptionWithDiscount();
  211. }
  212. public function getEnabledDisabledOptions()
  213. {
  214. return array(
  215. \Core\App\Factory\SettingsFactory::SYNC_ENABLED,
  216. \Core\App\Factory\SettingsFactory::SYNC_DISABLED
  217. );
  218. }
  219. public function checkLatestVersion($language)
  220. {
  221. $errorMessage = '<h4><span class="alert danger alert-box">' . $language->get('version_check_error') . '</span></h4>';
  222. $versionFile = @fopen(self::VERSION_FILE, "r") or die($errorMessage);
  223. while(!feof($versionFile)) {
  224. $versionRow = explode(self::VERSION_SEPARATOR, fgets($versionFile));
  225. if($versionRow[0] == self::VERSION_PLATFORM_CODE && isset($versionRow[1]))
  226. {
  227. if(trim($this->getVersion()) == trim($versionRow[1]))
  228. {
  229. $successMessage = '<small style="color: #74B807 !important">' . $language->get('version_check_success') . '</small>';
  230. }
  231. else
  232. {
  233. $successMessage = '<small style="color: red !important">' . $language->get('version_check_new') . ': <b>' . $versionRow[1] . '</b>';
  234. if(isset($versionRow[2]) && !empty($versionRow[2]))
  235. {
  236. $successMessage .= ' ' . $language->get('version_check_link_1') . '</small> <u><a style="color: red !important" target="_blank" href="' . $versionRow[2] . '">';
  237. $successMessage .= $language->get('version_check_link_2');
  238. $successMessage .= '</a></u>';
  239. }
  240. }
  241. echo $successMessage;
  242. exit;
  243. }
  244. }
  245. echo '';
  246. fclose($versionFile);
  247. }
  248. }