← All changes
|
includes/Admin/Product/Services/ProductSyncService.php
+21
-7
1.10.8
→
1.10.21
View file →
| @@ -4,8 +4,9 @@ | ||
| 4 | 4 | |
| 5 | 5 | use SyncBasalam\JobManager; |
| 6 | 6 | use SyncBasalam\Admin\Settings\SettingsManager; |
| 7 | 7 | use SyncBasalam\Utilities\ProductMetaKey; |
| 8 | +use SyncBasalam\Services\VendorSyncPolicy; | |
| 8 | 9 | |
| 9 | 10 | defined('ABSPATH') || exit; |
| 10 | 11 | |
| 11 | 12 | class ProductSyncService |
| @@ -21,11 +22,20 @@ | ||
| 21 | 22 | { |
| 22 | 23 | $this->jobManager = $jobManager ?: syncBasalamContainer()->get(JobManager::class); |
| 23 | 24 | } |
| 24 | 25 | |
| 25 | - public function enqueueBulkCreate(bool $includeOutOfStock = false, int $postsPerPage = 100): array | |
| 26 | - { | |
| 27 | - $existingJob = $this->jobManager->getJob([ | |
| 26 | + public function enqueueBulkCreate(bool $includeOutOfStock = false, int $postsPerPage = 100): array | |
| 27 | + { | |
| 28 | + $vendorSyncPolicy = syncBasalamContainer()->get(VendorSyncPolicy::class); | |
| 29 | + if (!$vendorSyncPolicy->canCreate()) { | |
| 30 | + return [ | |
| 31 | + 'success' => false, | |
| 32 | + 'message' => $vendorSyncPolicy->getRestrictionMessage(false), | |
| 33 | + 'status_code' => 409, | |
| 34 | + ]; | |
| 35 | + } | |
| 36 | + | |
| 37 | + $existingJob = $this->jobManager->getJob([ | |
| 28 | 38 | 'job_type' => self::JOB_TYPE_CREATE_ALL, |
| 29 | 39 | 'status' => 'pending', |
| 30 | 40 | ]); |
| 31 | 41 | |
| @@ -54,11 +64,13 @@ | ||
| 54 | 64 | 'status_code' => 200, |
| 55 | 65 | ]; |
| 56 | 66 | } |
| 57 | 67 | |
| 58 | - public function enqueueSelectedForCreate(array $productIds): void | |
| 59 | - { | |
| 60 | - foreach ($productIds as $productId) { | |
| 68 | + public function enqueueSelectedForCreate(array $productIds): void | |
| 69 | + { | |
| 70 | + if (!syncBasalamContainer()->get(VendorSyncPolicy::class)->canCreate()) return; | |
| 71 | + | |
| 72 | + foreach ($productIds as $productId) { | |
| 61 | 73 | if (!$this->isValidProductForCreate($productId)) { |
| 62 | 74 | continue; |
| 63 | 75 | } |
| 64 | 76 | |
| @@ -74,9 +86,11 @@ | ||
| 74 | 86 | } |
| 75 | 87 | |
| 76 | 88 | public function enqueueSelectedForUpdate(array $productIds): void |
| 77 | 89 | { |
| 78 | - if (!SettingsManager::isProductUpdateSelectionValid()) return; | |
| 90 | + $vendorSyncPolicy = syncBasalamContainer()->get(VendorSyncPolicy::class); | |
| 91 | + if (!$vendorSyncPolicy->canUpdate()) return; | |
| 92 | + if (!$vendorSyncPolicy->shouldRestrictUpdateFields(false) && !SettingsManager::isProductUpdateSelectionValid()) return; | |
| 79 | 93 | |
| 80 | 94 | $validProductIds = $this->filterValidProductsForUpdate($productIds); |
| 81 | 95 | |
| 82 | 96 | foreach ($validProductIds as $productId) { |