RuleSchema.php
| 1 | <?php |
| 2 | namespace SureCart\Models; |
| 3 | |
| 4 | /** |
| 5 | * Handle working of Rule String. |
| 6 | */ |
| 7 | class RuleSchema extends Model { |
| 8 | /** |
| 9 | * Rest API endpoint |
| 10 | * |
| 11 | * @var string |
| 12 | */ |
| 13 | public $endpoint = 'auto_fees/rule_schema'; |
| 14 | |
| 15 | /** |
| 16 | * Rest API endpoint |
| 17 | * |
| 18 | * @var string |
| 19 | */ |
| 20 | public $object_name = 'rule_schema'; |
| 21 | |
| 22 | /** |
| 23 | * Rule Schema. |
| 24 | */ |
| 25 | protected function getIdAttribute() { |
| 26 | return str_replace( 'auto_fee__', '', $this->schema_id ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Rule Schema. |
| 31 | */ |
| 32 | protected function getRuleSchemaAttribute() { |
| 33 | if ( empty( $this->attributes ) || empty( $this->attributes['attributes'] ) ) { |
| 34 | return []; |
| 35 | } |
| 36 | |
| 37 | // Add wp_user_role attribute. |
| 38 | $this->attributes['attributes'][] = (object) [ |
| 39 | 'key' => 'wp_user_role', |
| 40 | 'metadata' => true, |
| 41 | 'type' => 'string', |
| 42 | 'operators' => [ |
| 43 | 'is', |
| 44 | 'is_not', |
| 45 | ], |
| 46 | ]; |
| 47 | |
| 48 | // Remove the metadata & checkout.metadata attributes. |
| 49 | $this->attributes['attributes'] = array_values( |
| 50 | array_filter( |
| 51 | $this->attributes['attributes'], |
| 52 | function ( $attribute ) { |
| 53 | return ! in_array( $attribute->key, [ 'metadata', 'checkout.metadata' ], true ); |
| 54 | } |
| 55 | ) |
| 56 | ); |
| 57 | |
| 58 | return $this->attributes['attributes']; |
| 59 | } |
| 60 | } |
| 61 |