← All changes
|
includes/Actions/Controller/ProductActions/UpdateAllProducts.php
+21
-6
1.10.6
→
1.10.21
View file →
| @@ -1,10 +1,13 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace SyncBasalam\Actions\Controller\ProductActions; |
| 4 | 4 | |
| 5 | -use SyncBasalam\JobManager; | |
| 6 | -use SyncBasalam\Actions\Controller\ActionController; | |
| 5 | +use SyncBasalam\JobManager; | |
| 6 | +use SyncBasalam\Actions\Controller\ActionController; | |
| 7 | +use SyncBasalam\Admin\Settings\SettingsConfig; | |
| 8 | +use SyncBasalam\Admin\Settings\SettingsManager; | |
| 9 | +use SyncBasalam\Services\VendorSyncPolicy; | |
| 7 | 10 | |
| 8 | 11 | defined('ABSPATH') || exit; |
| 9 | 12 | |
| 10 | 13 | class UpdateAllProducts extends ActionController |
| @@ -11,12 +14,24 @@ | ||
| 11 | 14 | { |
| 12 | 15 | public function __invoke() |
| 13 | 16 | { |
| 14 | 17 | $updateType = isset($_POST['update_type']) ? sanitize_text_field(wp_unslash($_POST['update_type'])) : null; |
| 15 | - if (!$updateType) { | |
| 16 | - return wp_send_json_error(['message' => 'نوع بروزرسانی نامعتبر است.'], 400); | |
| 17 | - } | |
| 18 | - $jobManager = syncBasalamContainer()->get(JobManager::class); | |
| 18 | + if (!$updateType) { | |
| 19 | + return wp_send_json_error(['message' => 'نوع بروزرسانی نامعتبر است.'], 400); | |
| 20 | + } | |
| 21 | + | |
| 22 | + $vendorSyncPolicy = syncBasalamContainer()->get(VendorSyncPolicy::class); | |
| 23 | + if (!$vendorSyncPolicy->canUpdate()) { | |
| 24 | + return wp_send_json_error(['message' => $vendorSyncPolicy->getRestrictionMessage(false)], 409); | |
| 25 | + } | |
| 26 | + | |
| 27 | + if ($vendorSyncPolicy->shouldRestrictUpdateFields(false)) { | |
| 28 | + $updateType = 'quick'; | |
| 29 | + } elseif (!SettingsManager::isProductUpdateSelectionValid()) { | |
| 30 | + return wp_send_json_error(['message' => SettingsConfig::CUSTOM_PRODUCT_UPDATE_REQUIRED_MESSAGE], 422); | |
| 31 | + } | |
| 32 | + | |
| 33 | + $jobManager = syncBasalamContainer()->get(JobManager::class); | |
| 19 | 34 | |
| 20 | 35 | if ($updateType === 'full') { |
| 21 | 36 | $existingJob = $jobManager->getJob([ |
| 22 | 37 | 'job_type' => 'sync_basalam_update_all_products', |