| @@ -391,8 +391,29 @@ | ||
| 391 | 391 | |
| 392 | 392 | update_option('sync_basalam_settings', $settings); |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | + /** | |
| 396 | + * Variant price/stock used to follow the product price/stock checkboxes of the custom sync mode. | |
| 397 | + * Copy the old values so variable products keep syncing after the new checkboxes are introduced. | |
| 398 | + */ | |
| 399 | + public function backfillVariantSyncFields() | |
| 400 | + { | |
| 401 | + $settings = get_option('sync_basalam_settings', []); | |
| 402 | + if (!is_array($settings)) return; | |
| 403 | + | |
| 404 | + // The new keys may already have been filled with their "0" default by a settings read. | |
| 405 | + if (empty($settings[SettingsConfig::SYNC_PRODUCT_FIELD_VARIANT_PRICE])) { | |
| 406 | + $settings[SettingsConfig::SYNC_PRODUCT_FIELD_VARIANT_PRICE] = $settings[SettingsConfig::SYNC_PRODUCT_FIELD_PRICE] ?? 0; | |
| 407 | + } | |
| 408 | + | |
| 409 | + if (empty($settings[SettingsConfig::SYNC_PRODUCT_FIELD_VARIANT_STOCK])) { | |
| 410 | + $settings[SettingsConfig::SYNC_PRODUCT_FIELD_VARIANT_STOCK] = $settings[SettingsConfig::SYNC_PRODUCT_FIELD_STOCK] ?? 0; | |
| 411 | + } | |
| 412 | + | |
| 413 | + update_option('sync_basalam_settings', $settings); | |
| 414 | + } | |
| 415 | + | |
| 395 | 416 | public function createUploadedMediaTable() |
| 396 | 417 | { |
| 397 | 418 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 398 | 419 | |