/var/www/html_it/wp-content/plugins/woocommerce/src/Internal/StockNotifications/Factory.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
 * Notification Factory
 */

declare( strict_types );

namespace 
Automattic\WooCommerce\Internal\StockNotifications;

use 
Automattic\WooCommerce\Internal\StockNotifications\Notification;

defined'ABSPATH' ) || exit;

/**
 * Notification factory class
 */
class Factory {

    
/**
     * Get the notification object.
     *
     * @param  int $notification_id Notification ID to get.
     * @return Notification|bool
     */
    
public static function get_notificationint $notification_id ) {

        if ( ! 
$notification_id ) {
            return 
false;
        }

        try {
            
$notification = new Notification$notification_id );
            return 
$notification;
        } catch ( 
\Exception $e ) {
            
\wc_caught_exception$e__FUNCTION__, array( $notification_id ) );
            return 
false;
        }
    }

    
/**
     * Create a dummy notification for preview/testing purposes.
     *
     * @return Notification
     */
    
public static function create_dummy_notification(): Notification {
        
$notification = new Notification();

        
// Create a dummy product.
        
$product = new \WC_Product();
        
$product->set_name__'Dummy Product''woocommerce' ) );
        
$product->set_price25 );
        
$product->set_image_idget_option'woocommerce_placeholder_image') );

        
// Set required notification data.
        
$notification->set_product_id$product->get_id() );
        
$notification->set_user_email'[email protected]);

        
// Store the dummy product in the notification object for preview.
        
$notification->product $product;

        return 
$notification;
    }
}