← All changes
|
includes/Admin/Product/Data/ProductDataFacade.php
+23
-9
1.10.2
→
1.10.21
View file →
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace SyncBasalam\Admin\Product\Data; |
| 4 | 4 | |
| @@ -6,10 +6,14 @@ | ||
| 6 | 6 | use SyncBasalam\Admin\Product\Data\Validators\ImageValidator; |
| 7 | 7 | use SyncBasalam\Admin\Product\Data\Validators\ProductExistenceValidator; |
| 8 | 8 | use SyncBasalam\Admin\Product\Data\Validators\ProductStatusValidator; |
| 9 | 9 | use SyncBasalam\Admin\Product\Data\Validators\WeightValidator; |
| 10 | -use SyncBasalam\Admin\Product\ProductDataFactory; | |
| 11 | -use SyncBasalam\Utilities\ProductMetaKey; | |
| 10 | +use SyncBasalam\Admin\Product\ProductDataFactory; | |
| 11 | +use SyncBasalam\Admin\Settings\SettingsConfig; | |
| 12 | +use SyncBasalam\Admin\Settings\SettingsManager; | |
| 13 | +use SyncBasalam\Jobs\Exceptions\NonRetryableException; | |
| 14 | +use SyncBasalam\Services\VendorSyncPolicy; | |
| 15 | +use SyncBasalam\Utilities\ProductMetaKey; | |
| 12 | 16 | |
| 13 | 17 | defined('ABSPATH') || exit; |
| 14 | 18 | |
| 15 | 19 | class ProductDataFacade |
| @@ -42,16 +46,26 @@ | ||
| 42 | 46 | |
| 43 | 47 | $basalamProductId = get_post_meta($productId, ProductMetaKey::basalamProductId(), true); |
| 44 | 48 | $isUpdate = !empty($basalamProductId); |
| 45 | 49 | |
| 46 | - $syncFields = syncBasalamSettings()->getSettings(\SyncBasalam\Admin\Settings\SettingsConfig::SYNC_PRODUCT_FIELDS); | |
| 50 | + $settings = SettingsManager::getSettings(); | |
| 51 | + $syncFields = $settings[SettingsConfig::SYNC_PRODUCT_FIELDS] ?? 'all'; | |
| 52 | + $vendorSyncPolicy = syncBasalamContainer()->get(VendorSyncPolicy::class); | |
| 53 | + | |
| 54 | + if ( | |
| 55 | + $isUpdate | |
| 56 | + && !$vendorSyncPolicy->shouldRestrictUpdateFields(false) | |
| 57 | + && !SettingsManager::isProductUpdateSelectionValid($settings) | |
| 58 | + ) { | |
| 59 | + throw NonRetryableException::invalidData(SettingsConfig::CUSTOM_PRODUCT_UPDATE_REQUIRED_MESSAGE); | |
| 60 | + } | |
| 47 | 61 | |
| 48 | - $strategy = 'create'; | |
| 49 | - if ($isUpdate) { | |
| 50 | - if ($syncFields === 'price_stock') $strategy = 'quick_update'; | |
| 51 | - elseif ($syncFields === 'custom') $strategy = 'custom_update'; | |
| 52 | - else $strategy = 'update'; | |
| 53 | - } | |
| 62 | + $strategy = 'create'; | |
| 63 | + if ($isUpdate) { | |
| 64 | + if ($vendorSyncPolicy->shouldRestrictUpdateFields() || $syncFields === 'price_stock') $strategy = 'quick_update'; | |
| 65 | + elseif ($syncFields === 'custom') $strategy = 'custom_update'; | |
| 66 | + else $strategy = 'update'; | |
| 67 | + } | |
| 54 | 68 | |
| 55 | 69 | return self::$builder |
| 56 | 70 | ->reset() |
| 57 | 71 | ->setStrategy(self::$factory->createStrategy($strategy)) |