PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.8
ووسلام – همگام سازی ووکامرس و باسلام v1.10.8
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 / UpdateProduct.php

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

55 lines 1.8 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\UpdateSingleProductService;
7 use SyncBasalam\Admin\Product\Data\ProductDataFacade;
8 use SyncBasalam\Logger\Logger;
9 use SyncBasalam\Services\Products\Discount\DiscountTaskProcessor;
10
11 defined('ABSPATH') || exit;
12
13 class UpdateProduct extends AbstractProductOperation
14 {
15 private $updateProductService;
16 private $discountProcessor;
17
18 public function __construct(
19 $updateProductService = null,
20 $discountProcessor = null
21 )
22 {
23 parent::__construct();
24 $this->updateProductService = $updateProductService ?: syncBasalamContainer()->get(UpdateSingleProductService::class);
25 $this->discountProcessor = $discountProcessor ?: syncBasalamContainer()->get(DiscountTaskProcessor::class);
26 }
27
28
29 protected function run(int $productId, array $args = []): array
30 {
31 $categoryIds = $args['category_ids'] ?? null;
32
33 $productData = ProductDataFacade::get($productId, $categoryIds);
34
35 $updateResult = $this->updateProductService->updateProductInBasalam($productData, $productId);
36
37 if ($updateResult['success']) $this->discountProcessor->handleProductDiscount($productId);
38
39 return $updateResult;
40 }
41
42 public function validate(int $productId): bool
43 {
44 if (!parent::validate($productId)) return false;
45
46 $validation = $this->validator->validateBasalamConnection($productId);
47 if (!$validation['valid']) {
48 $this->validator->logValidationResult($productId, $validation, $this->getOperationNameFromClass());
49 return false;
50 }
51
52 return true;
53 }
54 }
55