# packeta/1.6.3/src/Packetery/Module/Product/Entity.php

Packeta, version 1.6.3. 114 lines.

- Page: https://pluginprobe.com/plugins/packeta/1.6.3/code/src/Packetery/Module/Product/Entity.php
- Raw: https://pluginprobe.com/plugins/packeta/1.6.3/raw/src/Packetery/Module/Product/Entity.php
- Modified: 2022-12-12T16:21:06+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/packeta/1.6.3/code/src/Packetery/Module/Product/Entity.php#L10-L20`.

```php
<?php
/**
 * Product entity.
 *
 * @package Packetery\Module\Product
 */

declare( strict_types=1 );


namespace Packetery\Module\Product;

/**
 * Class Entity
 *
 * @package Packetery\Module\Product
 */
class Entity {

	public const META_AGE_VERIFICATION_18_PLUS  = 'packetery_age_verification_18_plus';
	public const META_DISALLOWED_SHIPPING_RATES = 'packetery_disallowed_shipping_rates';

	/**
	 * Product.
	 *
	 * @var \WC_Product
	 */
	private $product;

	/**
	 * Entity constructor.
	 *
	 * @param \WC_Product $product Product.
	 */
	public function __construct( \WC_Product $product ) {
		$this->product = $product;
	}

	/**
	 * Creates instance using global variables.
	 *
	 * @return static
	 */
	public static function fromGlobals(): self {
		global $post;

		return self::fromPostId( $post->ID );
	}

	/**
	 * Create instance from post ID.
	 *
	 * @param int|string $postId Post ID.
	 *
	 * @return static
	 */
	public static function fromPostId( $postId ): self {
		$product = wc_get_product( $postId );

		return new self( $product );
	}

	/**
	 * Is product relevant for Packeta processing?
	 *
	 * @return bool
	 */
	public function isPhysical(): bool {
		return false === $this->product->is_virtual() && false === $this->product->is_downloadable();
	}

	/**
	 * Is age verification required?
	 *
	 * @return bool
	 */
	public function isAgeVerification18PlusRequired(): bool {
		return (string) $this->product->get_meta( self::META_AGE_VERIFICATION_18_PLUS ) === '1';
	}

	/**
	 * Disallowed carrier choices.
	 *
	 * @return array
	 */
	public function getDisallowedShippingRateChoices(): array {
		$choices = $this->product->get_meta( self::META_DISALLOWED_SHIPPING_RATES );
		if ( ! is_array( $choices ) ) {
			// TODO: log this event, really happened.
			return [];
		}

		return $choices;
	}

	/**
	 * Disallowed carrier ids.
	 *
	 * @return array
	 */
	public function getDisallowedShippingRateIds(): array {
		return array_keys( $this->getDisallowedShippingRateChoices() );
	}

	/**
	 * Gets product ID.
	 *
	 * @return int
	 */
	public function getId(): int {
		return $this->product->get_id();
	}
}

```
