| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Admin\Product\Data\Strategies; |
| 4 |
|
| 5 |
use SyncBasalam\Admin\Product\Data\Handlers\ProductDataHandlerInterface; |
| 6 |
|
| 7 |
defined('ABSPATH') || exit; |
| 8 |
|
| 9 |
class CreateProductStrategy implements DataStrategyInterface |
| 10 |
{ |
| 11 |
public function collect($product, ProductDataHandlerInterface $handler): array |
| 12 |
{ |
| 13 |
$data = apply_filters('sync_basalam_product_payload', null, $product, $handler, 'create'); |
| 14 |
if (!is_array($data)) { |
| 15 |
$data = []; |
| 16 |
} |
| 17 |
|
| 18 |
if (!array_key_exists('name', $data)) { |
| 19 |
$data['name'] = $handler->getName($product); |
| 20 |
} |
| 21 |
if (!array_key_exists('description', $data)) { |
| 22 |
$data['description'] = $handler->getDescription($product); |
| 23 |
} |
| 24 |
if (!array_key_exists('category_id', $data)) { |
| 25 |
$data['category_id'] = $handler->getCategoryId($product); |
| 26 |
} |
| 27 |
if (!array_key_exists('weight', $data)) { |
| 28 |
$data['weight'] = $handler->getWeight($product); |
| 29 |
} |
| 30 |
if (!array_key_exists('package_weight', $data)) { |
| 31 |
$data['package_weight'] = $handler->getPackageWeight($product); |
| 32 |
} |
| 33 |
if (!array_key_exists('photo', $data)) { |
| 34 |
$data['photo'] = $handler->getMainPhoto($product); |
| 35 |
} |
| 36 |
if (!array_key_exists('photos', $data)) { |
| 37 |
$data['photos'] = $handler->getGalleryPhotos($product); |
| 38 |
} |
| 39 |
if (!array_key_exists('video', $data)) { |
| 40 |
$video = $handler->getVideo($product); |
| 41 |
if ($video !== null) { |
| 42 |
$data['video'] = $video; |
| 43 |
} |
| 44 |
} |
| 45 |
if (!array_key_exists('status', $data)) { |
| 46 |
$data['status'] = 2976; |
| 47 |
} |
| 48 |
if (!array_key_exists('preparation_days', $data)) { |
| 49 |
$data['preparation_days'] = $handler->getPreparationDays($product); |
| 50 |
} |
| 51 |
if (!array_key_exists('unit_type', $data)) { |
| 52 |
$data['unit_type'] = $handler->getUnitType($product); |
| 53 |
} |
| 54 |
if (!array_key_exists('unit_quantity', $data)) { |
| 55 |
$data['unit_quantity'] = $handler->getUnitQuantity($product); |
| 56 |
} |
| 57 |
if (!array_key_exists('is_wholesale', $data)) { |
| 58 |
$data['is_wholesale'] = $handler->isWholesale($product); |
| 59 |
} |
| 60 |
if (!array_key_exists('variants', $data)) { |
| 61 |
$data['variants'] = $handler->getVariants($product); |
| 62 |
} |
| 63 |
if (!array_key_exists('product_attribute', $data)) { |
| 64 |
$data['product_attribute'] = $handler->getAttributes($product); |
| 65 |
} |
| 66 |
|
| 67 |
if (!$product->is_type('variable')) { |
| 68 |
if (!array_key_exists('primary_price', $data)) { |
| 69 |
$data['primary_price'] = $handler->getPrice($product); |
| 70 |
} |
| 71 |
if (!array_key_exists('stock', $data)) { |
| 72 |
$data['stock'] = $handler->getStock($product); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
return $data; |
| 77 |
} |
| 78 |
} |
| 79 |
|