ApiController.php
5 months ago
AsyncGenerator.php
4 months ago
FeedValidator.php
5 months ago
POSIntegration.php
5 months ago
POSProductVisibilitySync.php
5 months ago
ProductMapper.php
5 months ago
POSIntegration.php
124 lines
| 1 | <?php |
| 2 | /** |
| 3 | * POS Catalog Integration class. |
| 4 | * |
| 5 | * @package Automattic\WooCommerce\Internal\ProductFeed |
| 6 | */ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace Automattic\WooCommerce\Internal\ProductFeed\Integrations\POSCatalog; |
| 11 | |
| 12 | use Automattic\WooCommerce\Container; |
| 13 | use Automattic\WooCommerce\Internal\ProductFeed\Feed\FeedInterface; |
| 14 | use Automattic\WooCommerce\Internal\ProductFeed\Feed\FeedValidatorInterface; |
| 15 | use Automattic\WooCommerce\Internal\ProductFeed\Integrations\IntegrationInterface; |
| 16 | use Automattic\WooCommerce\Internal\ProductFeed\Storage\JsonFileFeed; |
| 17 | |
| 18 | if ( ! defined( 'ABSPATH' ) ) { |
| 19 | exit; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * POS Catalog Integration |
| 24 | * |
| 25 | * @since 10.5.0 |
| 26 | */ |
| 27 | class POSIntegration implements IntegrationInterface { |
| 28 | /** |
| 29 | * Container instance. |
| 30 | * |
| 31 | * @var Container |
| 32 | */ |
| 33 | private Container $container; |
| 34 | |
| 35 | /** |
| 36 | * Dependency injector. |
| 37 | * |
| 38 | * @param Container $container Dependency container. |
| 39 | * @internal |
| 40 | */ |
| 41 | final public function init( Container $container ): void { |
| 42 | $this->container = $container; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * {@inheritdoc} |
| 47 | */ |
| 48 | public function get_id(): string { |
| 49 | return 'pos'; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * {@inheritdoc} |
| 54 | */ |
| 55 | public function get_product_feed_query_args(): array { |
| 56 | return array( |
| 57 | 'type' => array( 'simple', 'variable', 'variation' ), |
| 58 | // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query |
| 59 | 'tax_query' => array( |
| 60 | array( |
| 61 | 'taxonomy' => 'pos_product_visibility', |
| 62 | 'field' => 'slug', |
| 63 | 'terms' => 'pos-hidden', |
| 64 | 'operator' => 'NOT IN', |
| 65 | ), |
| 66 | ), |
| 67 | ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * {@inheritdoc} |
| 72 | */ |
| 73 | public function register_hooks(): void { |
| 74 | add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); |
| 75 | $this->container->get( AsyncGenerator::class )->register_hooks(); |
| 76 | $this->container->get( POSProductVisibilitySync::class )->register_hooks(); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Initialize the REST API. |
| 81 | * |
| 82 | * @return void |
| 83 | */ |
| 84 | public function rest_api_init(): void { |
| 85 | // Only load the controller when necessary. |
| 86 | $this->container->get( ApiController::class )->register_routes(); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * {@inheritdoc} |
| 91 | */ |
| 92 | public function activate(): void { |
| 93 | // At the moment, there are no activation steps for the POS catalog. |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * {@inheritdoc} |
| 98 | */ |
| 99 | public function deactivate(): void { |
| 100 | // At the moment, there are no deactivation steps for the POS catalog. |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * {@inheritdoc} |
| 105 | */ |
| 106 | public function create_feed(): FeedInterface { |
| 107 | return new JsonFileFeed( 'pos-catalog-feed' ); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * {@inheritdoc} |
| 112 | */ |
| 113 | public function get_product_mapper(): ProductMapper { |
| 114 | return $this->container->get( ProductMapper::class ); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * {@inheritdoc} |
| 119 | */ |
| 120 | public function get_feed_validator(): FeedValidatorInterface { |
| 121 | return $this->container->get( FeedValidator::class ); |
| 122 | } |
| 123 | } |
| 124 |