| @@ -2,8 +2,9 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace SyncBasalam\Migrations; |
| 4 | 4 | |
| 5 | 5 | use SyncBasalam\Admin\Settings\SettingsConfig; |
| 6 | +use SyncBasalam\Services\Products\ProductConnection; | |
| 6 | 7 | use SyncBasalam\Services\WebhookService; |
| 7 | 8 | use SyncBasalam\Utilities\ProductMetaKey; |
| 8 | 9 | |
| 9 | 10 | defined('ABSPATH') || exit; |
| @@ -390,8 +391,29 @@ | ||
| 390 | 391 | |
| 391 | 392 | update_option('sync_basalam_settings', $settings); |
| 392 | 393 | } |
| 393 | 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 | + | |
| 394 | 416 | public function createUploadedMediaTable() |
| 395 | 417 | { |
| 396 | 418 | require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
| 397 | 419 | |
| @@ -413,8 +435,17 @@ | ||
| 413 | 435 | |
| 414 | 436 | dbDelta($sql); |
| 415 | 437 | |
| 416 | 438 | $this->migrateLegacyUploadedPhotos($tableName); |
| 439 | + } | |
| 440 | + | |
| 441 | + /** | |
| 442 | + * اصلاح محصولاتی که به دلیل کپی شدن، به یک محصول باسلام اتصال مشترک دارند. | |
| 443 | + * قدیمیترین محصول (محصول اصلی) متصل میماند و اتصال نسخههای کپی حذف میشود. | |
| 444 | + */ | |
| 445 | + public function repairDuplicateProductConnections(): void | |
| 446 | + { | |
| 447 | + ProductConnection::repairDuplicateConnections(); | |
| 417 | 448 | } |
| 418 | 449 | |
| 419 | 450 | private function migrateLegacyUploadedPhotos(string $targetTable): void |
| 420 | 451 | { |