PluginProbe
Packeta / 2.0.9
Packeta v2.0.9
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Module / Product / Entity.php

Entity.php in Packeta 2.0.9, at src/Packetery/Module/Product/Entity.php

119 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Product entity.
4 *
5 * @package Packetery\Module\Product
6 */
7
8 declare( strict_types=1 );
9
10 namespace Packetery\Module\Product;
11
12 use Packetery\Core\CoreHelper;
13 use Packetery\Module\Framework\WpAdapter;
14
15 /**
16 * Class Entity
17 *
18 * @package Packetery\Module\Product
19 */
20 class Entity {
21
22 public const META_AGE_VERIFICATION_18_PLUS = 'packetery_age_verification_18_plus';
23 public const META_DISALLOWED_SHIPPING_RATES = 'packetery_disallowed_shipping_rates';
24
25 /**
26 * Product.
27 *
28 * @var \WC_Product
29 */
30 private $product;
31
32 /**
33 * Entity constructor.
34 *
35 * @param \WC_Product $product Product.
36 */
37 public function __construct( \WC_Product $product ) {
38 $this->product = $product;
39 }
40
41 /**
42 * Is product relevant for Packeta processing?
43 *
44 * @return bool
45 */
46 public function isPhysical(): bool {
47 return $this->product->is_virtual() === false && $this->product->is_downloadable() === false;
48 }
49
50 /**
51 * Is age verification required?
52 *
53 * @return bool
54 */
55 public function isAgeVerificationRequired(): bool {
56 return (string) $this->product->get_meta( self::META_AGE_VERIFICATION_18_PLUS ) === '1';
57 }
58
59 /**
60 * Disallowed carrier choices.
61 *
62 * @return string[]
63 */
64 public function getDisallowedShippingRateChoices(): array {
65 $choices = $this->product->get_meta( self::META_DISALLOWED_SHIPPING_RATES );
66 if ( ! is_array( $choices ) ) {
67 // TODO: log this event, really happened.
68 return [];
69 }
70
71 return $choices;
72 }
73
74 /**
75 * Disallowed carrier ids.
76 *
77 * @return string[]
78 */
79 public function getDisallowedShippingRateIds(): array {
80 return array_keys( $this->getDisallowedShippingRateChoices() );
81 }
82
83 /**
84 * Gets product ID.
85 *
86 * @return int
87 */
88 public function getId(): int {
89 return $this->product->get_id();
90 }
91
92 public function getLengthInCm( WpAdapter $wpAdapter ): float {
93 return round(
94 CoreHelper::convertToCentimeters(
95 (float) $this->product->get_length(),
96 (string) $wpAdapter->getOption( 'woocommerce_dimension_unit' )
97 )
98 );
99 }
100
101 public function getWidthInCm( WpAdapter $wpAdapter ): float {
102 return round(
103 CoreHelper::convertToCentimeters(
104 (float) $this->product->get_width(),
105 (string) $wpAdapter->getOption( 'woocommerce_dimension_unit' )
106 )
107 );
108 }
109
110 public function getHeightInCm( WpAdapter $wpAdapter ): float {
111 return round(
112 CoreHelper::convertToCentimeters(
113 (float) $this->product->get_height(),
114 (string) $wpAdapter->getOption( 'woocommerce_dimension_unit' )
115 )
116 );
117 }
118 }
119