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 64 65
<?php
namespace Onlineforce\Woocommerce_Izettle;
class Woocommerce_Izettle_Background_Worker extends \WP_Background_Process {
protected $action = 'woocommerce_izettle_background_worker';
protected $cron_interval = 0.25;
protected function task( $item ) {
if ( 'stock_sync' === $item->type ) {
return $this->stock_sync( $item->item );
}
return false;
}
protected function stock_sync( $item ) {
if ( ! get_option( 'izettle_inventory_enabled' )
|| ! get_option( 'izettle_inventory_pull_enabled' ) ) {
return false;
}
$wc_product_id = Woocommerce_Izettle_Products::get_product_from_uuids(
$item['productUuid'],
$item['variantUuid']
);
if ( ! Woocommerce_Izettle_Products::is_synced( $wc_product_id ) ) {
return false;
}
$new_qty = Woocommerce_Izettle_Inventory::get_inventory_from_izettle( $wc_product_id );
Woocommerce_Izettle_Inventory::update_inventory_in_wc(
$wc_product_id,
$new_qty
);
return false;
}
protected function complete() {
parent::complete();
Woocommerce_Izettle_Admin::plugin_log( 'Finished cron background task.' );
}
}