Exemplo n.º 1
0
function post_customer_imonggo($shopify_customers, $url_imonggo, $imonggo_username, $imonggo_password, $http_header_post)
{
    foreach ($shopify_customers as $i) {
        foreach ($i->{'default-address'} as $address) {
            $company = $address->company;
            $mobile = $address->phone;
            $country = $address->country;
            $city = $address->city;
            $zip = $address->zip;
        }
        $check_id = mysql_query("SELECT shopify_id FROM customers WHERE shopify_id = {$i->id}");
        $existing = mysql_fetch_row($check_id);
        if ($i->state != "disabled") {
            //if not disabled, check if existing in the database or not
            if (!$existing) {
                //if not disabled and not existing, add
                $xml = '<?xml version="1.0" encoding="UTF-8"?> 
					<customer> 
						<first_name>' . $i->{'first-name'} . '</first_name> 
						<last_name>' . $i->{'last-name'} . '</last_name> 
						<email nil="true">' . $i->email . '</email>
						<tax_exempt>' . $i->{'tax-exempt'} . '</tax_exempt>
						<company_name nil="true">' . $company . '</company_name>
						<mobile nil="true">' . $mobile . '</mobile>
						<telephone nil="true">' . $mobile . '</telephone>
						<country nil="true">' . $country . '</country>
						<city nil="true">' . $city . '</city>
						<zipcode nil="true">' . $zip . '</zipcode>
					</customer>';
                echo $i->{'first-name'} . " " . $i->{'last-name'} . " was successfully added to Imonggo.<br>";
                $imonggo_id = post_imonggo($url_imonggo, $xml, $imonggo_username, $imonggo_password);
                $insert_customer = mysql_query("INSERT INTO customers (imonggo_id, shopify_id, email) VALUES ('{$imonggo_id->id}', '{$i->id}', '{$i->email}')");
            } else {
                //not disabled, existing in database, update
                $imonggo_customers = pull_imonggo($url_imonggo, $imonggo_username, $imonggo_password);
                foreach ($imonggo_customers as $cust) {
                    $query = mysql_query("SELECT imonggo_id FROM customers WHERE imonggo_id = {$cust->id}");
                    $exists = mysql_fetch_row($query);
                    if ($exists) {
                        $json = '{ 
									"customer": { 
										"id" : "' . $i->id . '",
										"first_name": "' . $cust->first_name . '",
										"last_name": "' . $cust->last_name . '",
										"email": "' . $cust->email . '",
										"addresses":[{
											"city":"' . $cust->city . '",
											"company":"' . $cust->company_name . '",
											"phone":"' . $cust->mobile . '",
											"country_name":"' . $cust->country . '",
											"zip":"' . $cust->zipcode . '"
										}]
										}
									}';
                        echo $i->{'first-name'} . " " . $i->{'last-name'} . " was successfully updated in Shopify.<br>";
                        $url_shopify = 'https://' . $_SESSION['shopify_shop_name'] . '.myshopify.com/admin/customers/' . $i->id . '.json';
                        $shopify = put_shopify($url_shopify, $json, $http_header_post);
                    }
                }
            }
        } else {
            if ($existing) {
                //if disabled but already existing in the database,
            } else {
                if (!$existing) {
                }
            }
            //if disabled and not existing in the database, do nothing
            echo "Error: " . $i->{'first-name'} . " " . $i->{'last-name'} . " is disabled in Shopify.<br>";
        }
    }
}
Exemplo n.º 2
0
    //pull products from imonggo
    $imonggo_inventory = pull_imonggo($url_imonggo_inventory, $imonggo_username, $imonggo_password);
    //pull inventory for quantity update
    parse($imonggo_products);
    //will parse products
    post_parsed($imonggo_inventory, $imonggo_products, $url_shopify, $http_header_post, $http_header_pull, $pull_url_shopify);
    //post to shopify
} else {
    if (isset($_GET['postProducts'])) {
        $url_shopify = 'https://' . $_SESSION['shopify_shop_name'] . '.myshopify.com/admin/products.json';
        $pull_url_shopify = 'https://' . $_SESSION['shopify_shop_name'] . '.myshopify.com/admin/products.xml';
        $url_imonggo = 'https://' . $imonggo_account_id . '.c3.imonggo.com/api/products.xml';
        $url_imonggo_inventory = 'https://' . $imonggo_account_id . '.c3.imonggo.com/api/inventories.xml';
        $imonggo_products = pull_imonggo($url_imonggo, $imonggo_username, $imonggo_password);
        //pull products from imonggo
        $imonggo_inventory = pull_imonggo($url_imonggo_inventory, $imonggo_username, $imonggo_password);
        //pull inventory for quantity update
        modal();
        //prints all errors in a modal
        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 {