| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Admin\Product\Operations; |
| 4 |
|
| 5 |
use SyncBasalam\Admin\Product\Operations\AbstractProductOperation; |
| 6 |
use SyncBasalam\Services\Products\UpdateSingleProductService; |
| 7 |
|
| 8 |
defined('ABSPATH') || exit; |
| 9 |
|
| 10 |
class RestoreProduct extends AbstractProductOperation |
| 11 |
{ |
| 12 |
private $updateProductService; |
| 13 |
private const STATUS_ACTIVE = 2976; |
| 14 |
|
| 15 |
public function __construct($updateProductService = null) |
| 16 |
{ |
| 17 |
parent::__construct(); |
| 18 |
$this->updateProductService = $updateProductService ?: syncBasalamContainer()->get(UpdateSingleProductService::class); |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
protected function run(int $product_id, array $args = []): array |
| 23 |
{ |
| 24 |
$result = $this->updateProductService->updateProductStatus($product_id, self::STATUS_ACTIVE); |
| 25 |
|
| 26 |
if (!$result) throw new \Exception('بازگردانی وضعیت � |
| 27 |
حصول نا� |
| 28 |
وفق بود'); |
| 29 |
|
| 30 |
return [ |
| 31 |
'success' => true, |
| 32 |
'message' => sprintf('� |
| 33 |
حصول با � |
| 34 |
وفقیت بازگردانی شد.'), |
| 35 |
'status_code' => 200, |
| 36 |
'product_id' => $product_id, |
| 37 |
'restored' => true |
| 38 |
]; |
| 39 |
} |
| 40 |
|
| 41 |
public function validate(int $product_id): bool |
| 42 |
{ |
| 43 |
if (!parent::validate($product_id)) return false; |
| 44 |
|
| 45 |
$validation = $this->validator->validateBasalamConnection($product_id); |
| 46 |
if (!$validation['valid']) { |
| 47 |
$this->validator->logValidationResult($product_id, $validation, $this->getOperationNameFromClass()); |
| 48 |
return false; |
| 49 |
} |
| 50 |
|
| 51 |
return true; |
| 52 |
} |
| 53 |
} |
| 54 |
|