| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Admin\Product\Data\Strategies; |
| 4 |
|
| 5 |
use SyncBasalam\Admin\Product\Data\Handlers\ProductDataHandlerInterface; |
| 6 |
use SyncBasalam\Utilities\ProductMetaKey; |
| 7 |
|
| 8 |
defined('ABSPATH') || exit; |
| 9 |
|
| 10 |
class QuickUpdateProductStrategy implements DataStrategyInterface |
| 11 |
{ |
| 12 |
public function collect($product, ProductDataHandlerInterface $handler): array |
| 13 |
{ |
| 14 |
$data = [ |
| 15 |
'id' => get_post_meta($product->get_id(), ProductMetaKey::basalamProductId(), true), |
| 16 |
'variants' => $handler->getVariants($product), |
| 17 |
'type' => $product->get_type(), |
| 18 |
]; |
| 19 |
|
| 20 |
$sku = $handler->getSku($product); |
| 21 |
if ($sku !== null) { |
| 22 |
$data['sku'] = $sku; |
| 23 |
} |
| 24 |
|
| 25 |
if (!$product->is_type('variable')) { |
| 26 |
$data['primary_price'] = $handler->getPrice($product); |
| 27 |
$data['stock'] = $handler->getStock($product); |
| 28 |
} |
| 29 |
|
| 30 |
return array_filter($data, fn($value) => $value !== null); |
| 31 |
} |
| 32 |
} |
| 33 |
|