| 1 |
<?php |
| 2 |
|
| 3 |
namespace TierPricingTable\Services\API\ProductFields; |
| 4 |
|
| 5 |
use TierPricingTable\Addons\RoleBasedPricing\RoleBasedPriceManager; |
| 6 |
use TierPricingTable\Addons\RoleBasedPricing\RoleBasedPricingRule; |
| 7 |
use WC_Product; |
| 8 |
class RoleBasedPricingData extends ProductField { |
| 9 |
public function getFieldSlug() : string { |
| 10 |
return 'tiered_pricing_roles_data'; |
| 11 |
} |
| 12 |
|
| 13 |
public function sanitizeValue( $value, $productId ) : array { |
| 14 |
$value = ( is_array( $value ) ? $value : array() ); |
| 15 |
$sanitizedValue = array(); |
| 16 |
wp_roles()->roles; |
| 17 |
foreach ( $value as $role => $roleData ) { |
| 18 |
if ( array_key_exists( $role, wp_roles()->roles ) ) { |
| 19 |
$roleBasedRule = RoleBasedPricingRule::build( $productId, $role ); |
| 20 |
$sanitizedValue[$role] = wp_parse_args( $roleData, $roleBasedRule->asArray() ); |
| 21 |
} |
| 22 |
} |
| 23 |
return $sanitizedValue; |
| 24 |
} |
| 25 |
|
| 26 |
public function getValue( array $product ) : array { |
| 27 |
return array(); |
| 28 |
} |
| 29 |
|
| 30 |
public function updateValue( $value, WC_Product $product ) { |
| 31 |
} |
| 32 |
|
| 33 |
public function getType() : string { |
| 34 |
return 'object'; |
| 35 |
} |
| 36 |
|
| 37 |
public function getDescription() : string { |
| 38 |
return 'Roles pricing data. See RoleBasedPricingRule class to get more information about the structure of the data.'; |
| 39 |
} |
| 40 |
|
| 41 |
} |
| 42 |
|