← All changes
|
includes/Admin/Product/Operations/CreateProduct.php
+11
-4
1.10.2
→
1.10.19
View file →
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace SyncBasalam\Admin\Product\Operations; |
| 4 | 4 | |
| @@ -6,9 +6,11 @@ | ||
| 6 | 6 | use SyncBasalam\Services\Products\CreateSingleProductService; |
| 7 | 7 | use SyncBasalam\Services\Products\Discount\DiscountTaskProcessor; |
| 8 | 8 | use SyncBasalam\Logger\Logger; |
| 9 | 9 | use SyncBasalam\Admin\Product\Data\ProductDataFacade; |
| 10 | -use SyncBasalam\Utilities\ProductMetaKey; | |
| 10 | +use SyncBasalam\Utilities\ProductMetaKey; | |
| 11 | +use SyncBasalam\Jobs\Exceptions\NonRetryableException; | |
| 12 | +use SyncBasalam\Services\VendorSyncPolicy; | |
| 11 | 13 | |
| 12 | 14 | defined('ABSPATH') || exit; |
| 13 | 15 | |
| 14 | 16 | class CreateProduct extends AbstractProductOperation |
| @@ -26,11 +28,16 @@ | ||
| 26 | 28 | $this->discountProcessor = $discountProcessor ?: syncBasalamContainer()->get(DiscountTaskProcessor::class); |
| 27 | 29 | } |
| 28 | 30 | |
| 29 | 31 | |
| 30 | - protected function run(int $product_id, array $args = []): array | |
| 31 | - { | |
| 32 | - $categoryIds = $args['category_ids'] ?? []; | |
| 32 | + protected function run(int $product_id, array $args = []): array | |
| 33 | + { | |
| 34 | + $vendorSyncPolicy = syncBasalamContainer()->get(VendorSyncPolicy::class); | |
| 35 | + if (!$vendorSyncPolicy->canCreate()) { | |
| 36 | + throw NonRetryableException::invalidData($vendorSyncPolicy->getRestrictionMessage(false)); | |
| 37 | + } | |
| 38 | + | |
| 39 | + $categoryIds = $args['category_ids'] ?? []; | |
| 33 | 40 | |
| 34 | 41 | $productData = ProductDataFacade::get($product_id, $categoryIds); |
| 35 | 42 | |
| 36 | 43 | $createResult = $this->createProductService->createProductInBasalam($productData, $product_id); |