| 1 |
<?php |
| 2 |
|
| 3 |
namespace SyncBasalam\Admin\Product; |
| 4 |
|
| 5 |
use SyncBasalam\Admin\Product\Data\Handlers\SimpleProductHandler; |
| 6 |
use SyncBasalam\Admin\Product\Data\Handlers\VariableProductHandler; |
| 7 |
use SyncBasalam\Admin\Product\Data\Handlers\ProductDataHandlerInterface; |
| 8 |
use SyncBasalam\Admin\Product\Data\Strategies\DataStrategyInterface; |
| 9 |
use SyncBasalam\Admin\Product\Data\Strategies\CreateProductStrategy; |
| 10 |
use SyncBasalam\Admin\Product\Data\Strategies\UpdateProductStrategy; |
| 11 |
use SyncBasalam\Admin\Product\Data\Strategies\QuickUpdateProductStrategy; |
| 12 |
use SyncBasalam\Admin\Product\Data\Strategies\CustomUpdateProductStrategy; |
| 13 |
|
| 14 |
defined('ABSPATH') || exit; |
| 15 |
|
| 16 |
class ProductDataFactory |
| 17 |
{ |
| 18 |
public function createHandler($product): ProductDataHandlerInterface |
| 19 |
{ |
| 20 |
switch ($product->get_type()) { |
| 21 |
case 'simple': |
| 22 |
return new SimpleProductHandler(); |
| 23 |
case 'variable': |
| 24 |
return new VariableProductHandler(); |
| 25 |
default: |
| 26 |
return new SimpleProductHandler(); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
public function createStrategy(string $type): DataStrategyInterface |
| 31 |
{ |
| 32 |
switch ($type) { |
| 33 |
case 'create': |
| 34 |
return new CreateProductStrategy(); |
| 35 |
case 'update': |
| 36 |
return new UpdateProductStrategy(); |
| 37 |
case 'quick_update': |
| 38 |
return new QuickUpdateProductStrategy(); |
| 39 |
case 'custom_update': |
| 40 |
return new CustomUpdateProductStrategy(); |
| 41 |
default: |
| 42 |
throw new \InvalidArgumentException(esc_html("Unknown strategy type: {$type}")); |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
|