PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.21
ووسلام – همگام سازی ووکامرس و باسلام v1.10.21
1.10.21 1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 All 54 releases
← All changes | includes/Services/VendorSyncPolicy.php +32 -0 1.10.101.10.21 View file →
@@ -40,8 +40,13 @@
40 40 }
41 41
42 42 public function ensureScheduled(): void
43 43 {
44 + if ($this->isLocalEnvironment()) {
45 + self::unschedule();
46 + return;
47 + }
48 +
44 49 if (wp_next_scheduled(self::CRON_HOOK) !== false) return;
45 50
46 51 wp_schedule_event($this->now() + MINUTE_IN_SECONDS, 'daily', self::CRON_HOOK);
47 52 }
@@ -52,8 +57,12 @@
52 57 }
53 58
54 59 public function getState(bool $refreshIfDue = true): array
55 60 {
61 + if ($this->isLocalEnvironment()) {
62 + return $this->defaultState((int) Settings::getSettings(SettingsConfig::VENDOR_ID));
63 + }
64 +
56 65 if ($refreshIfDue) return $this->refreshIfDue();
57 66
58 67 return $this->getStoredState();
59 68 }
@@ -107,8 +116,13 @@
107 116 $variantFields = [
108 117 'id' => true,
109 118 'primary_price' => true,
110 119 'stock' => true,
120 + // Product PATCH identifies a variant by its properties. Keep
121 + // those properties as identity data even in the limited mode;
122 + // they are not mutable fields, and the API's variants schema
123 + // requires them when the single product endpoint is used.
124 + 'properties' => true,
111 125 ];
112 126
113 127 $restricted['variants'] = array_map(function ($variant) use ($variantFields) {
114 128 return is_array($variant) ? array_intersect_key($variant, $variantFields) : [];
@@ -167,8 +181,12 @@
167 181 $token = Settings::getSettings(SettingsConfig::TOKEN);
168 182 $state = $this->getStoredState();
169 183 $now = $this->now();
170 184
185 + if ($this->isLocalEnvironment()) {
186 + return $this->defaultState($vendorId);
187 + }
188 +
171 189 if (!$vendorId || !$token) {
172 190 $state = $this->defaultState($vendorId);
173 191 update_option(self::OPTION_NAME, $state, false);
174 192
@@ -197,8 +215,15 @@
197 215 $token = Settings::getSettings(SettingsConfig::TOKEN);
198 216 $now = $this->now();
199 217 $state = $this->getStoredState();
200 218
219 + if ($this->isLocalEnvironment()) {
220 + $state = $this->defaultState($vendorId);
221 + update_option(self::OPTION_NAME, $state, false);
222 +
223 + return $state;
224 + }
225 +
201 226 if (!$vendorId || !$token) {
202 227 $state = $this->defaultState($vendorId);
203 228 update_option(self::OPTION_NAME, $state, false);
204 229
@@ -226,8 +251,9 @@
226 251 }
227 252
228 253 public function renderAdminNotice(): void
229 254 {
255 + if ($this->isLocalEnvironment()) return;
230 256 if (!$this->isRelevantAdminScreen()) return;
231 257
232 258 $vendorSyncState = $this->getFrontendState();
233 259 if ($vendorSyncState['mode'] === self::MODE_ACTIVE) return;
@@ -361,8 +387,14 @@
361 387
362 388 private function now(): int
363 389 {
364 390 return (int) call_user_func($this->clock);
391 + }
392 +
393 + private function isLocalEnvironment(): bool
394 + {
395 + return function_exists('wp_get_environment_type')
396 + && wp_get_environment_type() === 'local';
365 397 }
366 398
367 399 private function isRelevantAdminScreen(): bool
368 400 {