function post_product_shopify($imonggo_inventory, $imonggo_products, $url_shopify, $http_header_post, $http_header_pull, $pull_url_shopify) { foreach ($imonggo_products as $i) { //traverse all imonggo products if ($i->tax_exempt == "true") { //tax_exempt in imonggo, taxable in shopify $tax_exempt = "false"; } else { $tax_exempt = "true"; } $check_id = mysql_query("SELECT imonggo_id FROM products WHERE imonggo_id = {$i->id}"); //check product id in the database $existing = mysql_fetch_row($check_id); if ($i->status != 'D') { //if not deleted, check whether or not existing in the database if (!$existing) { //if not deleted and not existing in the database, add foreach ($imonggo_inventory as $inventory) { $quantity = (double) $inventory->quantity; //quantity of a certain product if ((string) $i->id == (string) $inventory->product_id) { //traverse and check if the product matches the product in the inventory if ($quantity > 0) { //if the traversed product has stock $json = '{ "product": { "title" : "' . $i->name . '", "body_html" : "' . $i->description . '", "tags" : "' . $i->tag_list . '", "variant":{ "title" : "' . $i->name . '", "price" : "' . $i->retail_price . '", "sku" : "' . $i->stock_no . '", "taxable" : "' . $tax_exempt . '", "barcode" : "' . $i->barcode_list . '", "inventory_management" : "shopify", "inventory_quantity" : "' . $quantity . '" } } }'; echo $i->name . " was successfully added to Shopify with " . $quantity . " stock/s<br>"; $json = json_decode(post_shopify($url_shopify, $json, $http_header_post), true); //decode json to normal array foreach ($json as $key => $value) { $shopify_id = $value['id']; //gets the shopify id of each product to be saved into the databases } $insert_product = mysql_query("INSERT INTO products (imonggo_id, shopify_id, name) VALUES ('{$i->id}', '{$shopify_id}', '{$i->name}')"); } else { echo "Error: " . $i->name . " is out of stock<br>"; } } } } else { //not deleted, existing in database, update in Shopify foreach ($imonggo_inventory as $inventory) { $quantity = (double) $inventory->quantity; if ((string) $i->id == (string) $inventory->product_id) { if ($quantity > 0) { $shopify_products = pull_shopify($pull_url_shopify, $http_header_pull); $query = mysql_query("SELECT shopify_id FROM products WHERE imonggo_id = {$i->id}"); $exists = mysql_fetch_row($query); if ($exists) { $json = '{ "product": { "id" : "' . $exists['shopify_id'] . '", "title" : "' . $i->name . '", "body_html" : "' . $i->description . '", "tags" : "' . $i->tag_list . '" } }'; //variants can't be updated even in postman, quantity tag is under variants field echo $i->name . " was successfully updated in Shopify with " . $quantity . " stock/s<br>"; $put_url_shopify = 'https://' . $_SESSION['shopify_shop_name'] . '.myshopify.com/admin/products/' . $exists[0] . '.json'; $shopify = put_shopify($put_url_shopify, $json, $http_header_post); } } else { echo "Error: " . $i->name . " is out of stock<br>"; } } } } } else { //if deleted, check if existing or not if ($existing) { //if deleted and existing in the database, hide echo "Shopify has no hide method for products<br>"; } else { if (!$existing) { } } //if deleted and not existing in the database, do nothing } } }
post_product_shopify($imonggo_inventory, $imonggo_products, $url_shopify, $http_header_post, $http_header_pull, $pull_url_shopify); //post to shopify } else { if (isset($_GET['postCustomers'])) { $url_shopify = 'https://' . $_SESSION['shopify_shop_name'] . '.myshopify.com/admin/customers.xml'; $url_imonggo = 'https://' . $imonggo_account_id . '.c3.imonggo.com/api/customers.xml?active_only=1'; $customer = pull_shopify($url_shopify, $http_header_pull); //pull customers from shopify modal(); //prints all errors in a modal post_customer_imonggo($customer, $url_imonggo, $imonggo_username, $imonggo_password, $http_header_post); } else { if (isset($_GET['postInvoices'])) { $url_shopify = 'https://' . $_SESSION['shopify_shop_name'] . '.myshopify.com/admin/orders.xml'; $url_imonggo = 'https://' . $imonggo_account_id . '.c3.imonggo.com/api/invoices.xml'; $invoices = pull_shopify($url_shopify, $http_header_pull); //pull orders from shopify modal(); //prints all errors in a modal post_invoice_imonggo($invoices, $url_imonggo, $imonggo_username, $imonggo_password); //post invoices to imonggo } } } } set_time_limit($default); ?> <script> function checkAll(ele) { var checkboxes = document.getElementsByTagName('input'); if (ele.checked) { for (var i = 0; i < checkboxes.length; i++) { if (checkboxes[i].type == 'checkbox') {checkboxes[i].checked = true;}}}