PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.21
ووسلام – همگام سازی ووکامرس و باسلام v1.10.21
1.10.21 1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 All 54 releases
← All changes | includes/Admin/Product/Services/ProductSyncService.php +28 -11 1.8.81.10.21 View file →
@@ -1,10 +1,12 @@
1 1 <?php
2 2
3 3 namespace SyncBasalam\Admin\Product\Services;
4 4
5 -use SyncBasalam\JobManager;
6 -use SyncBasalam\Utilities\ProductMetaKey;
5 +use SyncBasalam\JobManager;
6 +use SyncBasalam\Admin\Settings\SettingsManager;
7 +use SyncBasalam\Utilities\ProductMetaKey;
8 +use SyncBasalam\Services\VendorSyncPolicy;
7 9
8 10 defined('ABSPATH') || exit;
9 11
10 12 class ProductSyncService
@@ -20,11 +22,20 @@
20 22 {
21 23 $this->jobManager = $jobManager ?: syncBasalamContainer()->get(JobManager::class);
22 24 }
23 25
24 - public function enqueueBulkCreate(bool $includeOutOfStock = false, int $postsPerPage = 100): array
25 - {
26 - $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([
27 38 'job_type' => self::JOB_TYPE_CREATE_ALL,
28 39 'status' => 'pending',
29 40 ]);
30 41
@@ -53,11 +64,13 @@
53 64 'status_code' => 200,
54 65 ];
55 66 }
56 67
57 - public function enqueueSelectedForCreate(array $productIds): void
58 - {
59 - 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) {
60 73 if (!$this->isValidProductForCreate($productId)) {
61 74 continue;
62 75 }
63 76
@@ -71,11 +84,15 @@
71 84 }
72 85 }
73 86 }
74 87
75 - public function enqueueSelectedForUpdate(array $productIds): void
76 - {
77 - $validProductIds = $this->filterValidProductsForUpdate($productIds);
88 + public function enqueueSelectedForUpdate(array $productIds): void
89 + {
90 + $vendorSyncPolicy = syncBasalamContainer()->get(VendorSyncPolicy::class);
91 + if (!$vendorSyncPolicy->canUpdate()) return;
92 + if (!$vendorSyncPolicy->shouldRestrictUpdateFields(false) && !SettingsManager::isProductUpdateSelectionValid()) return;
93 +
94 + $validProductIds = $this->filterValidProductsForUpdate($productIds);
78 95
79 96 foreach ($validProductIds as $productId) {
80 97 if (!$this->jobManager->hasProductJobInProgress($productId, self::JOB_TYPE_UPDATE_SINGLE)) {
81 98 $this->jobManager->createJob(