| 1 |
<?php namespace TierPricingTable\Services\API\ProductFields; |
| 2 |
|
| 3 |
use TierPricingTable\PriceManager; |
| 4 |
use WC_Product; |
| 5 |
|
| 6 |
class FixedTieredPricing extends ProductField { |
| 7 |
|
| 8 |
public function getFieldSlug(): string { |
| 9 |
return 'tiered_pricing_fixed_rules'; |
| 10 |
} |
| 11 |
|
| 12 |
public function sanitizeValue( $value ): array { |
| 13 |
$rules = array(); |
| 14 |
$value = is_array( $value ) ? $value : array(); |
| 15 |
|
| 16 |
foreach ( $value as $key => $val ) { |
| 17 |
$rules[ (int) $key ] = (float) $val; |
| 18 |
} |
| 19 |
|
| 20 |
return $rules; |
| 21 |
} |
| 22 |
|
| 23 |
public function getValue( array $product ): array { |
| 24 |
return PriceManager::getFixedPriceRules( (int) $product['id'], 'edit' ); |
| 25 |
} |
| 26 |
|
| 27 |
public function updateValue( $value, WC_Product $product ) { |
| 28 |
update_post_meta( $product->get_id(), '_fixed_price_rules', $this->sanitizeValue( $value ) ); |
| 29 |
} |
| 30 |
|
| 31 |
public function getType(): string { |
| 32 |
return 'object'; |
| 33 |
} |
| 34 |
|
| 35 |
public function getDescription(): string { |
| 36 |
return 'Tiered pricing fixed rules. Key is a quantity and value is a price. Minimum quantity is 2'; |
| 37 |
} |
| 38 |
} |
| 39 |
|