PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.6
ووسلام – همگام سازی ووکامرس و باسلام v1.10.6
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 1.8.6 All 53 releases
sync-basalam / includes / Admin / Product / Operations / CreateProduct.php

CreateProduct.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.6, at includes/Admin/Product/Operations/CreateProduct.php

66 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Admin\Product\Operations;
4
5 use SyncBasalam\Admin\Product\Operations\AbstractProductOperation;
6 use SyncBasalam\Services\Products\CreateSingleProductService;
7 use SyncBasalam\Services\Products\Discount\DiscountTaskProcessor;
8 use SyncBasalam\Logger\Logger;
9 use SyncBasalam\Admin\Product\Data\ProductDataFacade;
10 use SyncBasalam\Utilities\ProductMetaKey;
11
12 defined('ABSPATH') || exit;
13
14 class CreateProduct extends AbstractProductOperation
15 {
16 private $createProductService;
17 private $discountProcessor;
18
19 public function __construct(
20 $createProductService = null,
21 $discountProcessor = null
22 )
23 {
24 parent::__construct();
25 $this->createProductService = $createProductService ?: syncBasalamContainer()->get(CreateSingleProductService::class);
26 $this->discountProcessor = $discountProcessor ?: syncBasalamContainer()->get(DiscountTaskProcessor::class);
27 }
28
29
30 protected function run(int $product_id, array $args = []): array
31 {
32 $categoryIds = $args['category_ids'] ?? [];
33
34 $productData = ProductDataFacade::get($product_id, $categoryIds);
35
36 $createResult = $this->createProductService->createProductInBasalam($productData, $product_id);
37
38 if ($createResult['success']) $this->discountProcessor->handleProductDiscount($product_id);
39
40 return $createResult;
41 }
42
43 public function validate(int $product_id): bool
44 {
45 if (!parent::validate($product_id)) return false;
46
47 $basalamProductId = get_post_meta($product_id, ProductMetaKey::basalamProductId(), true);
48 if (!empty($basalamProductId)) {
49 Logger::warning(sprintf('�
50 حصول %d از قبل به باسلا�
51
52 تصل است.', $product_id), [
53 'product_id' => $product_id,
54 'شناسه_�
55 حصول_باسلا�
56 ' => $basalamProductId,
57 'ع�
58 لیات' => $this->getOperationNameFromClass()
59 ]);
60 return false;
61 }
62
63 return true;
64 }
65 }
66