| 1 |
<?php namespace TierPricingTable\Services\API\ProductFields; |
| 2 |
|
| 3 |
use TierPricingTable\Core\ServiceContainerTrait; |
| 4 |
use WC_Product; |
| 5 |
|
| 6 |
abstract class ProductField { |
| 7 |
|
| 8 |
use ServiceContainerTrait; |
| 9 |
|
| 10 |
abstract public function getFieldSlug(): string; |
| 11 |
|
| 12 |
abstract public function getValue( array $product ); |
| 13 |
|
| 14 |
abstract public function updateValue( $value, WC_Product $product ); |
| 15 |
|
| 16 |
abstract public function getType(); |
| 17 |
|
| 18 |
abstract public function getDescription(); |
| 19 |
|
| 20 |
public function register() { |
| 21 |
register_rest_field( $this->getSupportedProductTypes(), $this->getFieldSlug(), array( |
| 22 |
'get_callback' => array( $this, 'getValue' ), |
| 23 |
'update_callback' => array( $this, 'updateValue' ), |
| 24 |
'schema' => array( |
| 25 |
'description' => $this->getDescription(), |
| 26 |
'type' => $this->getType(), |
| 27 |
'context' => $this->getContext(), |
| 28 |
), |
| 29 |
) ); |
| 30 |
} |
| 31 |
|
| 32 |
public function getContext(): array { |
| 33 |
return array( 'view', 'edit' ); |
| 34 |
} |
| 35 |
|
| 36 |
public function getSupportedProductTypes() { |
| 37 |
|
| 38 |
return apply_filters( 'tiered_pricing_table/api/supported_product_types', array( |
| 39 |
'product', |
| 40 |
'product_variation', |
| 41 |
), $this ); |
| 42 |
} |
| 43 |
} |
| 44 |
|