← All changes
|
includes/Admin/Product/Data/Handlers/SimpleProductHandler.php
+21
-1
1.8.5
→
1.10.21
View file →
| @@ -4,10 +4,12 @@ | ||
| 4 | 4 | |
| 5 | 5 | use SyncBasalam\Admin\Product\Data\Services\CategoryService; |
| 6 | 6 | use SyncBasalam\Admin\Product\Data\Services\PriceService; |
| 7 | 7 | use SyncBasalam\Admin\Product\Data\Services\PhotoService; |
| 8 | +use SyncBasalam\Admin\Product\Data\Services\VideoService; | |
| 8 | 9 | use SyncBasalam\Admin\Product\Data\Services\AttributeService; |
| 9 | 10 | use SyncBasalam\Admin\Settings\SettingsConfig; |
| 11 | +use SyncBasalam\Services\Products\PreparationDaysGuard; | |
| 10 | 12 | |
| 11 | 13 | defined('ABSPATH') || exit; |
| 12 | 14 | |
| 13 | 15 | class SimpleProductHandler implements ProductDataHandlerInterface |
| @@ -14,9 +16,11 @@ | ||
| 14 | 16 | { |
| 15 | 17 | private $categoryService; |
| 16 | 18 | private $priceService; |
| 17 | 19 | private $photoService; |
| 20 | + private $videoService; | |
| 18 | 21 | private $attributeService; |
| 22 | + private $preparationGuard; | |
| 19 | 23 | private array $settings; |
| 20 | 24 | |
| 21 | 25 | public function __construct() |
| 22 | 26 | { |
| @@ -22,9 +26,11 @@ | ||
| 22 | 26 | { |
| 23 | 27 | $this->categoryService = new CategoryService(); |
| 24 | 28 | $this->priceService = new PriceService(); |
| 25 | 29 | $this->photoService = new PhotoService(); |
| 30 | + $this->videoService = new VideoService(); | |
| 26 | 31 | $this->attributeService = new AttributeService(); |
| 32 | + $this->preparationGuard = new PreparationDaysGuard(); | |
| 27 | 33 | $this->settings = syncBasalamSettings()->getSettings(); |
| 28 | 34 | } |
| 29 | 35 | |
| 30 | 36 | public function getName($product): string |
| @@ -42,8 +48,15 @@ | ||
| 42 | 48 | |
| 43 | 49 | return mb_substr($name, 0, 120); |
| 44 | 50 | } |
| 45 | 51 | |
| 52 | + public function getSku($product): ?string | |
| 53 | + { | |
| 54 | + $sku = trim((string) $product->get_sku()); | |
| 55 | + | |
| 56 | + return $sku !== '' ? $sku : null; | |
| 57 | + } | |
| 58 | + | |
| 46 | 59 | public function getDescription($product): string |
| 47 | 60 | { |
| 48 | 61 | return $this->attributeService->generateDescription($product); |
| 49 | 62 | } |
| @@ -104,11 +117,18 @@ | ||
| 104 | 117 | { |
| 105 | 118 | return $this->photoService->getGalleryPhotoIds($product); |
| 106 | 119 | } |
| 107 | 120 | |
| 121 | + public function getVideo($product): ?int | |
| 122 | + { | |
| 123 | + return $this->videoService->getVideoFileId($product); | |
| 124 | + } | |
| 125 | + | |
| 108 | 126 | public function getPreparationDays($product): int |
| 109 | 127 | { |
| 110 | - return $this->settings[SettingsConfig::DEFAULT_PREPARATION]; | |
| 128 | + $preparationDays = (int) $this->settings[SettingsConfig::DEFAULT_PREPARATION]; | |
| 129 | + | |
| 130 | + return $this->preparationGuard->enforce($preparationDays, $product); | |
| 111 | 131 | } |
| 112 | 132 | |
| 113 | 133 | public function getUnitType($product): int |
| 114 | 134 | { |