| 1 |
<?php |
| 2 |
/** |
| 3 |
* Product category entity. |
| 4 |
* |
| 5 |
* @package Packetery |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace Packetery\Module\ProductCategory; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class Entity |
| 14 |
* |
| 15 |
* @package Packetery |
| 16 |
*/ |
| 17 |
class Entity { |
| 18 |
|
| 19 |
public const META_DISALLOWED_SHIPPING_RATES = 'packetery_disallowed_shipping_rates_by_cat'; |
| 20 |
public const TAXONOMY_NAME = 'product_cat'; |
| 21 |
|
| 22 |
/** |
| 23 |
* Category. |
| 24 |
* |
| 25 |
* @var \WP_Term |
| 26 |
*/ |
| 27 |
private $category; |
| 28 |
|
| 29 |
/** |
| 30 |
* Entity constructor. |
| 31 |
* |
| 32 |
* @param \WP_Term $category Category. |
| 33 |
*/ |
| 34 |
public function __construct( \WP_Term $category ) { |
| 35 |
$this->category = $category; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Disallowed carrier choices. |
| 40 |
* |
| 41 |
* @return array<string, bool> |
| 42 |
*/ |
| 43 |
public function getDisallowedShippingRateChoices(): array { |
| 44 |
$choices = get_term_meta( $this->category->term_id, self::META_DISALLOWED_SHIPPING_RATES, true ); |
| 45 |
if ( ! is_array( $choices ) ) { |
| 46 |
return []; |
| 47 |
} |
| 48 |
|
| 49 |
return $choices; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Disallowed carrier choices. |
| 54 |
* |
| 55 |
* @return string[] |
| 56 |
*/ |
| 57 |
public function getDisallowedShippingRateIds(): array { |
| 58 |
return array_keys( $this->getDisallowedShippingRateChoices() ); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Gets product ID. |
| 63 |
* |
| 64 |
* @return int |
| 65 |
*/ |
| 66 |
public function getId(): int { |
| 67 |
return $this->category->term_id; |
| 68 |
} |
| 69 |
} |
| 70 |
|