예제 #1
0
        public string UpdateOneProduct(string productSKU, string connectionString)
        {
            var product          = new M2CreateProducts();
            var proDucts         = new Product();
            var productQTY       = new StockItem();
            var productExtension = new ExtensionAttributes();
            List <CustomAttribute> NewCustomAttribute = new List <CustomAttribute>();
            var custom_attribute_url_key = new CustomAttribute();

            var request = CreateRequest("/rest/V1/products/" + productSKU, Method.PUT, Token);
            List <ProductLink> newProductLink = new List <ProductLink>();

            string strSQLString = " SELECT   [ItemNum],[ItemName_Extra],Price,In_Stock" +
                                  " FROM [Inventory] where [ItemNum]= '" + productSKU + "'";

            SqlConnection adoCon = new SqlConnection();

            adoCon.ConnectionString = connectionString;
            adoCon.Open();
            SqlCommand    command = new SqlCommand(strSQLString, adoCon);
            SqlDataReader reader  = command.ExecuteReader();


            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    proDucts.Sku            = productSKU;
                    proDucts.Name           = reader["ItemName_Extra"].ToString().Trim(); // ItemName_Extra
                    proDucts.AttributeSetId = 4;
                    proDucts.Price          = Convert.ToSingle(reader["Price"].ToString().Trim());
                    proDucts.Status         = 1;
                    proDucts.Visibility     = 1;
                    proDucts.TypeId         = "simple";

                    custom_attribute_url_key.AttributeCode = "url_key";
                    custom_attribute_url_key.Value         = productSKU;
                    NewCustomAttribute.Add(custom_attribute_url_key);
                    proDucts.CustomAttributes = NewCustomAttribute;

                    product.Product = proDucts;
                }
            }

            reader.Close();

            string json = JsonConvert.SerializeObject(product, Formatting.Indented);

            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = Client.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return("OK");
            }
            else
            {
                return("TimeOut");
            }
        }
예제 #2
0
        public string CreateProduct(string productSKU, M2CreateProducts product)
        {
            var request = CreateRequest("/rest/V1/products/" + productSKU, Method.PUT, Token);
            //var request = CreateRequest("/rest/V1/products/" + productSKU, Method.GET, Token);
            //var product = new M2CreateProducts();
            Stopwatch stopWatch = new Stopwatch();


            string json = JsonConvert.SerializeObject(product, Formatting.Indented);

            request.AddParameter("application/json", json, ParameterType.RequestBody);
            stopWatch.Start();
            var response = Client.Execute(request);

            stopWatch.Stop();
            TimeSpan ts          = stopWatch.Elapsed;
            string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                elapsedTime = elapsedTime + " - UPDATED";
                return("OK");
            }
            else
            {
                String aaa = response.Content;
                if (response.Content == "{\"message\":\"URL key for specified store already exists.\"}")
                {
                    elapsedTime = elapsedTime + " - URL key already exists.";
                    return("Error");
                }
                else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                {//Unauthorized
                    elapsedTime = elapsedTime + " - Error";
                    return("TimeOut");
                }
            }
            //return response.Content;
            //return elapsedTime;
            return("Error");
        }