wcAdapter = $wcAdapter; } /** * Create instance from post ID. * * @param int|string $postId Post ID. * * @return Entity * @throws ProductNotFoundException Product not found. */ public function fromPostId( $postId ): Entity { $product = $this->wcAdapter->getProduct( $postId ); if ( ! ( $product instanceof \WC_Product ) ) { throw new ProductNotFoundException( "Product $postId not found." ); } return new Entity( $product ); } /** * Creates instance using global variables. * * @return Entity */ public function fromGlobals(): Entity { global $post; return $this->fromPostId( $post->ID ); } }