| @@ -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 | { |