Concerns
6 months ago
Jobs
1 year ago
Tasks
1 year ago
WooCommerce
2 weeks ago
BatchCheckService.php
6 months ago
ContentSyncService.php
6 months ago
CustomerSyncService.php
1 year ago
ImportState.php
2 months ago
PostSyncService.php
2 days ago
ProductSyncService.php
1 year ago
ProductsSyncService.php
1 year ago
StoreSyncService.php
1 year ago
SyncService.php
2 months ago
SyncServiceProvider.php
2 months ago
ProductsSyncService.php
109 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Sync; |
| 4 | |
| 5 | /** |
| 6 | * Syncs customer records to WordPress users. |
| 7 | */ |
| 8 | class ProductsSyncService { |
| 9 | /** |
| 10 | * Application instance. |
| 11 | * |
| 12 | * @var \SureCart\Application |
| 13 | */ |
| 14 | protected $app = null; |
| 15 | |
| 16 | /** |
| 17 | * The notice id. |
| 18 | * |
| 19 | * @var string |
| 20 | */ |
| 21 | protected $notice_id = 'surecart_products_sync'; |
| 22 | |
| 23 | /** |
| 24 | * Constructor. |
| 25 | * |
| 26 | * @param \SureCart\Application $app The application. |
| 27 | */ |
| 28 | public function __construct( $app ) { |
| 29 | $this->app = $app; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Bootstrap the service. |
| 34 | * |
| 35 | * @return void |
| 36 | */ |
| 37 | public function bootstrap() { |
| 38 | add_action( 'admin_notices', [ $this, 'showMigrationNotice' ] ); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Get the queue. |
| 43 | * |
| 44 | * @return object |
| 45 | */ |
| 46 | public function jobs() { |
| 47 | return $this->app->resolve( 'surecart.jobs' ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Is this process active? |
| 52 | * |
| 53 | * @return boolean |
| 54 | */ |
| 55 | public function isActive() { |
| 56 | return $this->jobs()->isActive(); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Show the migration notice. |
| 61 | * |
| 62 | * @return void |
| 63 | */ |
| 64 | public function showMigrationNotice() { |
| 65 | if ( ! $this->isActive() ) { |
| 66 | return; |
| 67 | } |
| 68 | echo wp_kses_post( |
| 69 | \SureCart::notices()->render( |
| 70 | [ |
| 71 | 'name' => $this->notice_id, |
| 72 | 'type' => 'info', |
| 73 | 'title' => esc_html__( 'SureCart: Getting things ready...', 'surecart' ), |
| 74 | 'text' => wp_sprintf( |
| 75 | '<p>%s</p>', |
| 76 | esc_html__( 'We are getting things ready and optimized in the background. This may take a few minutes.', 'surecart' ), |
| 77 | ), |
| 78 | ] |
| 79 | ) |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Start the sync process. |
| 85 | * |
| 86 | * @param boolean $args The arguments. |
| 87 | * |
| 88 | * @return array|WP_Error The response or WP_Error on failure. |
| 89 | */ |
| 90 | public function dispatch( $args = [] ) { |
| 91 | $args = wp_parse_args( |
| 92 | $args, |
| 93 | [ |
| 94 | 'page' => 1, |
| 95 | 'per_page' => 25, |
| 96 | ] |
| 97 | ); |
| 98 | |
| 99 | // reset the notice. |
| 100 | \SureCart::notices()->reset( $this->notice_id ); |
| 101 | |
| 102 | // clear account cache. |
| 103 | \SureCart::account()->clearCache(); |
| 104 | |
| 105 | // run all jobs. |
| 106 | return $this->jobs()->run( $args ); |
| 107 | } |
| 108 | } |
| 109 |