| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* WooCommerce Controller |
| 5 |
*/ |
| 6 |
|
| 7 |
namespace Extendify\Launch\Controllers; |
| 8 |
|
| 9 |
defined('ABSPATH') || die('No direct access.'); |
| 10 |
|
| 11 |
use Extendify\Launch\Services\WooCommerceImporter; |
| 12 |
|
| 13 |
/** |
| 14 |
* The controller for interacting with WooCommerce to import temporary data. |
| 15 |
*/ |
| 16 |
|
| 17 |
class WooCommerceController |
| 18 |
{ |
| 19 |
/** |
| 20 |
* Import the temporary products. |
| 21 |
* |
| 22 |
* @return \WP_REST_Response |
| 23 |
*/ |
| 24 |
public static function importTemporaryProducts() |
| 25 |
{ |
| 26 |
if (count(get_posts(['post_type' => 'product']))) { |
| 27 |
return new \WP_REST_Response(['success' => true]); |
| 28 |
} |
| 29 |
|
| 30 |
$results = WooCommerceImporter::import(); |
| 31 |
|
| 32 |
if (is_wp_error($results)) { |
| 33 |
return new \WP_REST_Response([ |
| 34 |
'success' => false, |
| 35 |
'message' => $results->get_error_message(), |
| 36 |
]); |
| 37 |
} |
| 38 |
|
| 39 |
update_option('extendify_wc_import_results', $results); |
| 40 |
|
| 41 |
return new \WP_REST_Response(['success' => true]); |
| 42 |
} |
| 43 |
} |
| 44 |
|