Admin
4 weeks ago
AsyncTasks
4 weeks ago
Emails
4 weeks ago
Enums
10 months ago
Frontend
4 weeks ago
Privacy
4 weeks ago
Utilities
4 weeks ago
Config.php
4 weeks ago
DataRetentionController.php
4 weeks ago
Factory.php
10 months ago
Notification.php
4 weeks ago
NotificationQuery.php
10 months ago
StockNotifications.php
4 weeks ago
StockSyncController.php
10 months ago
StockNotifications.php
81 lines
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types = 1 ); |
| 4 | |
| 5 | namespace Automattic\WooCommerce\Internal\StockNotifications; |
| 6 | |
| 7 | use Automattic\WooCommerce\Internal\DataStores\StockNotifications\StockNotificationsDataStore; |
| 8 | use Automattic\WooCommerce\Internal\StockNotifications\Emails\EmailActionController; |
| 9 | use Automattic\WooCommerce\Internal\StockNotifications\StockSyncController; |
| 10 | use Automattic\WooCommerce\Internal\StockNotifications\Privacy\PrivacyEraser; |
| 11 | use Automattic\WooCommerce\Internal\StockNotifications\Emails\EmailManager; |
| 12 | use Automattic\WooCommerce\Internal\StockNotifications\AsyncTasks\NotificationsProcessor; |
| 13 | use Automattic\WooCommerce\Internal\StockNotifications\Admin\AdminManager; |
| 14 | use Automattic\WooCommerce\Internal\StockNotifications\Frontend\ProductPageIntegration; |
| 15 | use Automattic\WooCommerce\Internal\StockNotifications\Frontend\FormHandlerService; |
| 16 | use Automattic\WooCommerce\Internal\StockNotifications\Frontend\NotificationManagementService; |
| 17 | |
| 18 | /** |
| 19 | * The controller for the stock notifications. |
| 20 | */ |
| 21 | class StockNotifications { |
| 22 | |
| 23 | /** |
| 24 | * Initialize the controller. |
| 25 | */ |
| 26 | public function __construct() { |
| 27 | add_action( 'plugins_loaded', array( $this, 'init_hooks' ) ); |
| 28 | add_action( 'woocommerce_installed', array( $this, 'on_install_or_update' ) ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Handle the WooCommerce installation event. |
| 33 | * |
| 34 | * This method is called when WooCommerce is installed or updated. |
| 35 | * It initializes the data retention controller to set up necessary tasks. |
| 36 | */ |
| 37 | public function on_install_or_update() { |
| 38 | wc_get_container()->get( DataRetentionController::class )->on_woo_install_or_update(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Register hooks and services. |
| 43 | * |
| 44 | * @internal |
| 45 | */ |
| 46 | public function init_hooks() { |
| 47 | add_filter( 'woocommerce_data_stores', array( $this, 'register_data_stores' ) ); |
| 48 | |
| 49 | $container = wc_get_container(); |
| 50 | $container->get( EmailManager::class ); |
| 51 | $container->get( StockSyncController::class ); |
| 52 | $container->get( NotificationsProcessor::class ); |
| 53 | $container->get( PrivacyEraser::class ); |
| 54 | $container->get( DataRetentionController::class ); |
| 55 | $container->get( EmailActionController::class ); |
| 56 | |
| 57 | $container->get( ProductPageIntegration::class ); |
| 58 | $container->get( FormHandlerService::class ); |
| 59 | $container->get( NotificationManagementService::class ); |
| 60 | |
| 61 | if ( is_admin() ) { |
| 62 | $container->get( AdminManager::class ); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Register the data stores. |
| 68 | * |
| 69 | * @param array $data_stores Data stores. |
| 70 | * @return array |
| 71 | */ |
| 72 | public function register_data_stores( $data_stores ) { |
| 73 | if ( ! is_array( $data_stores ) ) { |
| 74 | return $data_stores; |
| 75 | } |
| 76 | |
| 77 | $data_stores['stock_notification'] = wc_get_container()->get( StockNotificationsDataStore::class ); |
| 78 | return $data_stores; |
| 79 | } |
| 80 | } |
| 81 |