function submit_products()
{
    $start = 0;
    while (true) {
        $inventories = Inventory::whereNull('shopify_id')->orWhere('dirty', 1)->skip($start)->take(100)->get();
        $cnt = count($inventories);
        if ($cnt == 0) {
            break;
        }
        foreach ($inventories as $inventory) {
            if ($inventory->image == '') {
                continue;
            }
            if ($inventory->shopify_id == NULL) {
                $amzInfo = AmazonInfo::where("inventory_id", $inventory->id)->first();
                $collection = Collection::where("name", $amzInfo->category1)->first();
                if ($collection == NULL) {
                    //echo '[', date('Y-m-d H:m:s'), '] Skip - ', $inventory->name, "\r\n";
                    continue;
                }
                $result = create_product($inventory->name, $inventory->description, 'Bellwether', 'Book', $inventory->sku, $inventory->price, $inventory->quantity, $inventory->image, $inventory->isbn);
                if ($result['success'] == 'true') {
                    /*
                    	Check if collection exists and add product & category...
                    */
                    if ($collection != NULL) {
                        $inventory->dirty = 0;
                        $sid = $result['product']['id'];
                        $inventory->shopify_id = $sid;
                        $inventory->save();
                        echo '[', date('Y-m-d H:m:s'), '] Added Product - ', "ID ", $sid, ", ", $inventory->name, "\r\n";
                        add_product_to_collection($result['product']['id'], $collection->shopify_id);
                        echo 'Added to Collection - ' . $collection->name . "\r\n";
                    }
                }
            } else {
                $result = update_product_content($inventory->shopify_id, $inventory->price, $inventory->quantity, $inventory->sku);
                if ($result['success'] == 'true') {
                    $inventory->dirty = 0;
                    $inventory->save();
                    echo 'Updated Product - ' . $inventory->name . "\r\n";
                }
            }
        }
        $start += $cnt;
    }
}
function submit_products()
{
    $start = 0;
    while (true) {
        $inventories = Inventory::where('dirty', 1)->take(100)->get();
        $cnt = count($inventories);
        if ($cnt == 0) {
            break;
        }
        foreach ($inventories as $inventory) {
            if ($inventory->image == '') {
                $inventory->dirty = -3;
                $inventory->save();
                continue;
            }
            $inventory = Inventory::where('isbn', $inventory->isbn)->orderBy('price', 'asc')->first();
            Inventory::where('isbn', $inventory->isbn)->update(['dirty' => 0]);
            if ($inventory->shopify_id == NULL) {
                $amzInfo = AmazonInfo::where("inventory_id", $inventory->id)->first();
                $collection = Collection::where("name", $amzInfo->category1)->first();
                if ($amzInfo->url == null || $amzInfo->description == null) {
                    continue;
                }
                $dimension = $amzInfo->width . 'W x ' . $amzInfo->height . 'H x ' . $amzInfo->length . 'L (in)';
                $result = create_product($inventory->name, $amzInfo->description, 'Bellwether', 'Book', $inventory->sku, $inventory->price, $inventory->quantity, $inventory->image, $inventory->isbn, $amzInfo->list_price, $inventory->condition, $inventory->author, $inventory->publisher, $dimension, $amzInfo->pages, $amzInfo->url);
                print_r($result);
                if ($result['success'] == 'true') {
                    $inventory->dirty = 0;
                    $sid = $result['product']['id'];
                    $inventory->shopify_id = $sid;
                    $inventory->shopify_var_id = $result['variants'][0]['id'];
                    $inventory->save();
                    echo 'Added Product - ', "ID ", $sid, ", ", $inventory->name, "\r\n";
                    /*
                    	Add collection...
                    */
                    if ($collection != NULL) {
                        add_product_to_collection($result['product']['id'], $collection->shopify_id);
                        echo 'Added to Collection - ' . $collection->name . "\r\n";
                    }
                } else {
                    echo 'Failed Product - ', "ID ", $sid, ", ", $inventory->name, "\r\n";
                    $inventory->dirty = -1;
                    $inventory->save();
                }
            } else {
                if ($amzInfo->url == null || $amzInfo->description == null) {
                    continue;
                }
                $result = update_product_content($inventory->shopify_id, $inventory->name, $amzInfo->description, $inventory->sku, $inventory->price, $inventory->quantity, $inventory->isbn, $amzInfo->list_price, $inventory->condition, $inventory->author, $inventory->publisher, $dimension, $amzInfo->pages, $amzInfo->url);
                if ($result['success'] == 'true') {
                    $inventory->dirty = 0;
                    $inventory->save();
                    echo 'Updated Product - ' . $inventory->name . "\r\n";
                } else {
                    echo 'Failed to update Product - ' . $inventory->name . "\r\n";
                    echo json_encode($result), "r\n";
                    $inventory->dirty = -2;
                    $inventory->save();
                }
            }
            //usleep(100);
        }
        $start += $cnt;
    }
}