/**
  * Fetches product stock for every product in Woo from Fortnox
  *
  * @return bool
  */
 public function diff_woo_fortnox_inventory()
 {
     include_once "class-fortnox3-api.php";
     logthis('DIFF');
     //Init API
     $apiInterface = new WCF_API();
     if (!$apiInterface->create_api_validation_request()) {
         return $this->ERROR_API_KEY;
     }
     if ($apiInterface->has_error) {
         return $this->ERROR_LOGIN;
     }
     $args = array('post_type' => 'product', 'orderby' => 'id', 'posts_per_page' => -1);
     $the_query = new WP_Query($args);
     $missing = array();
     $missing_sku = array();
     foreach ($the_query->get_posts() as $fetched_product) {
         $pf = new WC_Product_Factory();
         $product = $pf->get_product($fetched_product->ID);
         //Init API
         $apiInterface = new WCF_API();
         if ($apiInterface->has_error) {
             return $this->ERROR_LOGIN;
         }
         if ($product->has_child()) {
             $totalAmount = 0;
             foreach ($product->get_children() as $child_id) {
                 $child = $pf->get_product($child_id);
                 $sku = $child->get_sku();
                 $article = $apiInterface->get_article($sku);
                 if ($sku === NULL) {
                     array_push($missing_sku, "VARIANT ID:" . $child_id);
                 }
                 if (array_key_exists('Error', $article)) {
                     array_push($missing, "VARIANT ID:" . $child_id . " SKU:" . $sku);
                 }
             }
         } else {
             $sku = $product->get_sku();
             $article = $apiInterface->get_article($sku);
             if ($sku === NULL) {
                 array_push($missing_sku, "VARIANT ID:" . $fetched_product->ID);
             }
             if (array_key_exists('Error', $article)) {
                 array_push($missing, "PRODUKT ID:" . $fetched_product->ID . " SKU:" . $sku);
             }
         }
     }
     logthis(print_r($missing, true));
     return print_r($missing, true);
 }
function check_diff_callback()
{
    global $wpdb;
    // this is how you get access to the database
    include_once "class-fortnox3-api.php";
    check_ajax_referer('fortnox_woocommerce', 'security');
    $pf = new WC_Product_Factory();
    $child = $pf->get_product($_POST['product_id']);
    $sku = $child->get_sku();
    $apiInterface = new WCF_API();
    $article = $apiInterface->get_article($sku);
    if ($sku === NULL) {
        echo json_encode(array('success' => false, 'product_id' => $_POST['product_id'], 'sku' => 'Inget artikelnummer', 'title' => $child->get_title()));
    } else {
        if (array_key_exists('Error', $article)) {
            echo json_encode(array('success' => false, 'product_id' => $_POST['product_id'], 'sku' => $sku, 'title' => $child->get_title()));
        } else {
            echo json_encode(array('success' => true, 'product_id' => $_POST['product_id'], 'sku' => $sku, 'title' => $child->get_title()));
        }
    }
    die;
    // this is required to return a proper result
}