UpdateManager.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. class Laybuy_Plugin_UpdateManager
  3. {
  4. public $pluginVersion;
  5. public $pluginDbVersion;
  6. public function setPluginVersion($pluginVersion)
  7. {
  8. $this->pluginVersion = $pluginVersion;
  9. return $this;
  10. }
  11. public function setPluginDbVersion($pluginDbVersion)
  12. {
  13. $this->pluginDbVersion = $pluginDbVersion;
  14. return $this;
  15. }
  16. public function update()
  17. {
  18. // update to 5.0.6
  19. if ($this->pluginDbVersion && version_compare($this->pluginDbVersion, '5.0.6', '<')) {
  20. $this->update_5_0_6();
  21. }
  22. // update to 5.0.11
  23. if (!$this->pluginDbVersion || version_compare($this->pluginDbVersion, '5.0.11', '<')) {
  24. $this->update_5_0_11();
  25. }
  26. // update to 5.0.13
  27. if ($this->pluginDbVersion && version_compare($this->pluginDbVersion, '5.0.13', '<')) {
  28. $this->update_5_0_13();
  29. }
  30. // update to 5.1.0
  31. if ($this->pluginDbVersion && version_compare($this->pluginDbVersion, '5.1.0', '<')) {
  32. $this->update_5_1_0();
  33. }
  34. // update to 5.1.5
  35. if ($this->pluginDbVersion && version_compare($this->pluginDbVersion, '5.1.5', '<')) {
  36. $this->update_5_1_5();
  37. }
  38. // update to 5.1.11
  39. if ($this->pluginDbVersion && version_compare($this->pluginDbVersion, '5.1.11', '<')) {
  40. $this->update_5_1_11();
  41. }
  42. // update to 5.2.4
  43. if ($this->pluginDbVersion && version_compare($this->pluginDbVersion, '5.2.4', '<')) {
  44. $this->update_5_2_4();
  45. }
  46. // update to 5.2.5
  47. if ($this->pluginDbVersion && version_compare($this->pluginDbVersion, '5.2.5', '<')) {
  48. $this->update_5_2_5();
  49. }
  50. // update to 5.2.6
  51. if ($this->pluginDbVersion && version_compare($this->pluginDbVersion, '5.2.6', '<')) {
  52. $this->update_5_2_6();
  53. }
  54. // update to 5.2.8
  55. if ($this->pluginDbVersion && version_compare($this->pluginDbVersion, '5.2.8', '<')) {
  56. $this->update_5_2_8();
  57. }
  58. // update to 5.2.9
  59. if ($this->pluginDbVersion && version_compare($this->pluginDbVersion, '5.2.9', '<')) {
  60. $this->update_5_2_9();
  61. }
  62. // update to 5.3.8
  63. if ($this->pluginDbVersion && version_compare($this->pluginDbVersion, '5.3.8', '<')) {
  64. $this->update_5_3_8();
  65. }
  66. $this->fixCurrentPluginVersion();
  67. }
  68. public function update_5_0_11()
  69. {
  70. $settings = (array) get_option( 'woocommerce_laybuy_settings', true );
  71. if (empty($settings['product_pages_info_text'])) {
  72. $settings['product_pages_info_text'] = 'or 6 weekly interest-free payments from <strong>[AMOUNT]</strong> with <a href="#" id="laybuy-what-is-modal">[laybuy_logo] <span style="font-size: 12px"><u>what\'s this?</u></span></a>';
  73. }
  74. if (empty($settings['category_pages_info_text'])) {
  75. $settings['category_pages_info_text'] = 'or 6 weekly interest-free payments from <strong>[AMOUNT]</strong> with <span id="laybuy-what-is-modal" class="laybuy-cat-page" style="width:50px"> [laybuy_logo]</span>';
  76. }
  77. if (empty($settings['cart_page_info_text'])) {
  78. $settings['cart_page_info_text'] = '<tr><td colspan="2" style="font-size: 14px">or 6 weekly interest-free payments from <strong>[AMOUNT]</strong> with [laybuy_logo link=https://www.laybuy.com]<span id="laybuy-what-is-modal"><u style="font-size: 11px">what\'s this?</u></span></td></tr>';
  79. }
  80. if (empty($settings['checkout_page_info_text'])) {
  81. $settings['checkout_page_info_text'] = '<div class="laybuy-checkout-content "><p class="title"> Pay it in 6 weekly, interest-free payments from <strong>[AMOUNT]</strong></p><div class="laybuy-checkout-img"><img class="left-column" src="https://integration-assets.laybuy.com/woocommerce_laybuy_icons/laybuy_pay.jpg"><img src="https://integration-assets.laybuy.com/woocommerce_laybuy_icons/laybuy_schedule.jpg"><img class="left-column second-row" src="https://integration-assets.laybuy.com/woocommerce_laybuy_icons/laybuy_complete.jpg"><img class="second-row" src="https://integration-assets.laybuy.com/woocommerce_laybuy_icons/laybuy_done.jpg"></div></div><div style="clear:both" />';
  82. }
  83. update_option('woocommerce_laybuy_settings', $settings);
  84. }
  85. public function update_5_0_6()
  86. {
  87. $settings = (array) get_option( 'woocommerce_laybuy_settings', true );
  88. $settings['sandbox_global_merchant_id'] = '';
  89. $settings['sandbox_global_api_key'] = '';
  90. $settings['production_global_merchant_id'] = '';
  91. $settings['production_global_api_key'] = '';
  92. $settings['global'] = 'yes';
  93. $settings['currency'] = [];
  94. $currencies = ['NZD', 'AUD', 'GBP', 'USD'];
  95. $activeCurrencies = [];
  96. $apiProductionKeys = [];
  97. $apiSandboxKeys = [];
  98. foreach ($currencies as $currency) {
  99. if (
  100. !empty($settings["production_{$currency}_api_key"]) ||
  101. !empty($settings["sandbox_{$currency}_api_key"])
  102. ) {
  103. $activeCurrencies[] = $currency;
  104. }
  105. if (!empty($settings["production_{$currency}_api_key"])) {
  106. $apiProductionKeys[$settings["production_{$currency}_merchant_id"]] = $settings["production_{$currency}_api_key"];
  107. }
  108. if (!empty($settings["sandbox_{$currency}_api_key"])) {
  109. $apiSandboxKeys[$settings["sandbox_{$currency}_merchant_id"]] = $settings["sandbox_{$currency}_api_key"];
  110. }
  111. }
  112. if (count(array_unique($apiProductionKeys)) == 1) {
  113. $settings['production_global_merchant_id'] = key($apiProductionKeys);
  114. $settings['production_global_api_key'] = $apiProductionKeys[key($apiProductionKeys)];
  115. }
  116. if (count(array_unique($apiSandboxKeys)) == 1) {
  117. $settings['sandbox_global_merchant_id'] = key($apiSandboxKeys);
  118. $settings['sandbox_global_api_key'] = $apiSandboxKeys[key($apiSandboxKeys)];
  119. }
  120. if (
  121. count(array_unique($apiProductionKeys)) > 1 ||
  122. count(array_unique($apiSandboxKeys)) > 1
  123. ) {
  124. $settings['global'] = 'no';
  125. }
  126. $settings['currency'] = $activeCurrencies;
  127. update_option('woocommerce_laybuy_settings', $settings);
  128. }
  129. public function update_5_0_13()
  130. {
  131. $settings = (array) get_option( 'woocommerce_laybuy_settings', true );
  132. $settings['cart_page_info_text'] = '<tr><td colspan="2" style="font-size: 14px">or 6 weekly interest-free payments from <strong>[AMOUNT]</strong> with [laybuy_logo link=https://www.laybuy.com]<span id="laybuy-what-is-modal"><u style="font-size: 11px">what\'s this?</u></span></td></tr>';
  133. update_option('woocommerce_laybuy_settings', $settings);
  134. }
  135. public function update_5_1_0()
  136. {
  137. $settings = (array) get_option( 'woocommerce_laybuy_settings', true );
  138. $settings['laybuy_compatibility_mode'] = 'no';
  139. update_option('woocommerce_laybuy_settings', $settings);
  140. }
  141. public function update_5_1_5()
  142. {
  143. $settings = (array) get_option( 'woocommerce_laybuy_settings', true );
  144. $settings['NZD_pay_limit_min'] = 0.06;
  145. $settings['NZD_pay_limit_max'] = 1500;
  146. $settings['AUD_pay_limit_min'] = 0.06;
  147. $settings['AUD_pay_limit_max'] = 1200;
  148. $settings['GBP_pay_limit_min'] = 0.06;
  149. $settings['GBP_pay_limit_max'] = 720;
  150. update_option('woocommerce_laybuy_settings', $settings);
  151. }
  152. public function update_5_1_11()
  153. {
  154. $settings = (array) get_option( 'woocommerce_laybuy_settings', true );
  155. $settings['product_price_breakdown_hook_priority'] = 11;
  156. update_option('woocommerce_laybuy_settings', $settings);
  157. }
  158. public function update_5_2_4()
  159. {
  160. $settings = (array) get_option( 'woocommerce_laybuy_settings', true );
  161. $settings['laybuy_geolocate_ip'] = 'no';
  162. $settings['laybuy_logo_theme'] = 'white';
  163. update_option('woocommerce_laybuy_settings', $settings);
  164. }
  165. public function update_5_2_5()
  166. {
  167. $settings = (array) get_option( 'woocommerce_laybuy_settings', true );
  168. $settings['sandbox_USD_merchant_id'] = '';
  169. $settings['sandbox_USD_api_key'] = '';
  170. $settings['production_USD_merchant_id'] = '';
  171. $settings['production_USD_api_key'] = '';
  172. $settings['USD_pay_limit_min'] = 0.06;
  173. $settings['USD_pay_limit_max'] = 1200;
  174. update_option('woocommerce_laybuy_settings', $settings);
  175. }
  176. public function update_5_2_6()
  177. {
  178. $settings = (array) get_option( 'woocommerce_laybuy_settings', true );
  179. $product_types = [];
  180. foreach (wc_get_product_types() as $value => $label) {
  181. $product_types[] = $value;
  182. }
  183. $settings['product_types'] = $product_types;
  184. update_option('woocommerce_laybuy_settings', $settings);
  185. }
  186. public function update_5_2_8()
  187. {
  188. $settings = (array) get_option( 'woocommerce_laybuy_settings', true );
  189. $settings['laybuy_price_breakdown_out_of_stock'] = 'no';
  190. update_option('woocommerce_laybuy_settings', $settings);
  191. }
  192. public function update_5_2_9()
  193. {
  194. $settings = (array) get_option( 'woocommerce_laybuy_settings', true );
  195. $settings['laybuy_billing_phone_field'] = 'billing_phone';
  196. update_option('woocommerce_laybuy_settings', $settings);
  197. }
  198. public function update_5_3_8()
  199. {
  200. $settings = (array) get_option( 'woocommerce_laybuy_settings', true );
  201. $settings['product_pages_info_text'] = 'or 6 weekly interest-free payments from <strong>[AMOUNT]</strong> with [laybuy_logo]';
  202. $settings['category_pages_info_text'] = 'or 6 weekly interest-free payments from <strong>[AMOUNT]</strong> with [laybuy_logo]';
  203. $settings['cart_page_info_text'] = '<tr><td colspan="2" style="font-size: 14px">or 6 weekly interest-free payments from <strong>[AMOUNT]</strong> with [laybuy_logo link=https://www.laybuy.com]</td></tr>';
  204. $settings['checkout_page_info_text'] = '<div class="laybuy-checkout-content "><p class="title"> Pay it in 6 weekly, interest-free payments from <strong>[AMOUNT]</strong></p><div class="laybuy-checkout-img"><img class="left-column" src="https://integration-assets.laybuy.com/woocommerce_laybuy_icons/laybuy_pay.jpg"><img src="https://integration-assets.laybuy.com/woocommerce_laybuy_icons/laybuy_schedule.jpg"><img class="left-column second-row" src="https://integration-assets.laybuy.com/woocommerce_laybuy_icons/laybuy_complete.jpg"><img class="second-row" src="https://integration-assets.laybuy.com/woocommerce_laybuy_icons/laybuy_done.jpg"></div></div><div style="clear:both" />';
  205. update_option('woocommerce_laybuy_settings', $settings);
  206. }
  207. public function fixCurrentPluginVersion()
  208. {
  209. if (version_compare($this->pluginDbVersion, $this->pluginVersion, '<')) {
  210. update_option('wc_laybuy_version', $this->pluginVersion);
  211. }
  212. }
  213. }