Exemple #1
0
        // CALL MAGENTO API 
        private bool updateEUProduct(DTO.EurofarStock.DataContract.Post.productContractForUpdate data)
        {
            // update 0 (default basic store) store
            try
            {
                using (var client = new WebClient())
                {
                    client.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + eurofarstockToken);
                    client.Headers.Add(HttpRequestHeader.Accept, "application/json");
                    client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                    client.UploadString(eurofarstockURL + "all/V1/products/"+data.product.sku, "PUT", Newtonsoft.Json.JsonConvert.SerializeObject(data));
                }
            }
            catch (WebException exception)
            {
                string responseText = string.Empty;
                var responseStream = exception.Response?.GetResponseStream();
                if (responseStream != null)
                {
                    using (var reader = new StreamReader(responseStream))
                    {
                        responseText = reader.ReadToEnd();
                    }
                }
                HandlingException(new Exception("updateEUProduct[" + exception.Response.ResponseUri.ToString() + "]: (" + data.product.sku + ") - " + responseText));
                return false;
            }
            catch (Exception ex)
            {
                HandlingException(new Exception("updateEUProduct: (" + data.product.sku + ") - " + Library.Helper.GetInnerException(ex).Message));
                return false;
            }

            return true;
        }
Exemple #2
0
        private bool updateEUProduct(DTO.ProductDTO product)
        {
            DTO.EurofarStock.DataContract.Post.productContractForUpdate postedData = converter.Tilsoft2EurofarProductForUpdate(product);

            // assign material fs
            if (!string.IsNullOrEmpty(product.MaterialNM) && eurofarstockMaterial.Count(o => o.name.ToUpper() == product.MaterialNM.ToUpper()) > 0)
            {
                int materialID = eurofarstockMaterial.FirstOrDefault(o => o.name.ToUpper() == product.MaterialNM.ToUpper()).id;
                postedData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute() { attribute_code = "material_fs", value = materialID.ToString() });
            }

            return updateEUProduct(postedData);
        }
Exemple #3
0
 private bool disableEUProduct(DTO.EurofarStock.Item item)
 {
     try
     {
         DTO.EurofarStock.DataContract.Post.productContractForUpdate postedData = new DTO.EurofarStock.DataContract.Post.productContractForUpdate();
         postedData.product = new DTO.EurofarStock.DataContract.Post.productContractDetailForUpdate()
         {
             sku = item.sku
             , attribute_set_id = item.attribute_set_id
             , status = (int)DTO.EurofarStock.EUConstant.DisabledStatus
             , visibility = (int)DTO.EurofarStock.EUConstant.Visibility
             , type_id = item.type_id
             , custom_attributes = new List<DTO.EurofarStock.DataContract.Post.productContractCustomAttribute>()
         };
         // update default store
         using (var client = new WebClient())
         {
             client.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + eurofarstockToken);
             client.Headers.Add(HttpRequestHeader.Accept, "application/json");
             client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
             //client.UploadString(eurofarstockURL + "all/V1/products", "POST", Newtonsoft.Json.JsonConvert.SerializeObject(postedData));
             client.UploadString(eurofarstockURL + "all/V1/products/" + postedData.product.sku, "PUT", Newtonsoft.Json.JsonConvert.SerializeObject(postedData));
         }
         return true;
     }
     catch (WebException exception)
     {
         string responseText = string.Empty;
         var responseStream = exception.Response?.GetResponseStream();
         if (responseStream != null)
         {
             using (var reader = new StreamReader(responseStream))
             {
                 responseText = reader.ReadToEnd();
             }
         }
         HandlingException(new Exception("disableEUProduct: (" + item.sku + ") - " + responseText));
     }
     catch (Exception ex)
     {
         HandlingException(new Exception("disableEUProduct: (" + item.sku + ") - " + Library.Helper.GetInnerException(ex).Message));
         return false;
     }
     return false;
 }
        public DTO.EurofarStock.DataContract.Post.productContractForUpdate Tilsoft2EurofarProductForUpdate(DTO.ProductDTO item)
        {
            DTO.EurofarStock.DataContract.Post.productContractForUpdate postData = new DTO.EurofarStock.DataContract.Post.productContractForUpdate();
            postData.product = new DTO.EurofarStock.DataContract.Post.productContractDetailForUpdate()
            {
                sku = item.ArticleCode
                , attribute_set_id  = (int)DTO.EurofarStock.EUConstant.AttributeSetID
                , status            = (int)(item.IsEnabled ? DTO.EurofarStock.EUConstant.EnabledStatus : DTO.EurofarStock.EUConstant.DisabledStatus)
                , visibility        = (int)DTO.EurofarStock.EUConstant.Visibility
                , type_id           = "simple"
                , custom_attributes = new List <DTO.EurofarStock.DataContract.Post.productContractCustomAttribute>()
            };

            if (!item.UnitPrice.HasValue || item.UnitPrice.Value == 0)
            {
                postData.product.price  = 0;
                postData.product.status = (int)DTO.EurofarStock.EUConstant.DisabledStatus;
            }
            else
            {
                //postData.product.price = item.UnitPrice.Value;
                postData.product.price = Math.Round(item.UnitPrice.Value * (decimal)1.3, 2, MidpointRounding.AwayFromZero); // up 30% for magento discount
            }

            // map custom attribute
            postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
            {
                attribute_code = "tax_class_id", value = (int)DTO.EurofarStock.EUConstant.TaxClass
            });
            postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
            {
                attribute_code = "sorting_qnt", value = item.StockQnt
            });
            if (!string.IsNullOrEmpty(item.ModelNM))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "short_description", value = item.Description
                });
            }
            if (!string.IsNullOrEmpty(item.ArticleCode))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "article_code", value = item.ArticleCode
                });
            }
            if (!string.IsNullOrEmpty(item.SubEANCode))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "sub_ean_code", value = item.SubEANCode
                });
            }
            if (!string.IsNullOrEmpty(item.MaterialColorNM))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "material_color", value = item.MaterialColorNM
                });
            }
            if (!string.IsNullOrEmpty(item.MaterialTypeNM))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "material_type", value = item.MaterialTypeNM
                });
            }
            if (!string.IsNullOrEmpty(item.FrameMaterialNM))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "frame_material", value = item.FrameMaterialNM
                });
            }
            if (!string.IsNullOrEmpty(item.FrameMaterialColorNM))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "frame_material_color", value = item.FrameMaterialColorNM
                });
            }
            if (!string.IsNullOrEmpty(item.BackCushionNM))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "back_cushion", value = item.BackCushionNM
                });
            }
            if (!string.IsNullOrEmpty(item.SeatCushionNM))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "seat_cushion", value = item.SeatCushionNM
                });
            }
            if (!string.IsNullOrEmpty(item.CushionColorNM))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "cushion_color", value = item.CushionColorNM
                });
            }
            if (!string.IsNullOrEmpty(item.OverallDimH))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "height", value = item.OverallDimH + "cm"
                });
            }
            if (!string.IsNullOrEmpty(item.OverallDimL))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "length", value = item.OverallDimL + "cm"
                });
            }
            if (!string.IsNullOrEmpty(item.OverallDimW))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "width", value = item.OverallDimW + "cm"
                });
            }
            if (!string.IsNullOrEmpty(item.SeatCushionDimH))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "seat_height", value = item.SeatCushionDimH
                });
            }
            if (!string.IsNullOrEmpty(item.SeatCushionDimL))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "seat_length", value = item.SeatCushionDimL
                });
            }
            if (!string.IsNullOrEmpty(item.SeatCushionDimW))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "seat_width", value = item.SeatCushionDimW
                });
            }
            if (!string.IsNullOrEmpty(item.OverallDimL) && !string.IsNullOrEmpty(item.OverallDimW) && !string.IsNullOrEmpty(item.OverallDimH))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "wxlxh_cm", value = item.OverallDimW + "cm x " + item.OverallDimL + "cm x " + item.OverallDimH + "cm"
                });
            }
            if (!string.IsNullOrEmpty(item.CartonBoxDimL))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "carton_box_length", value = item.CartonBoxDimL
                });
            }
            if (!string.IsNullOrEmpty(item.CartonBoxDimH))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "carton_box_height", value = item.CartonBoxDimH
                });
            }
            if (!string.IsNullOrEmpty(item.CartonBoxDimW))
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "carton_box_width", value = item.CartonBoxDimW
                });
            }
            if (item.Qnt40HC.HasValue)
            {
                postData.product.custom_attributes.Add(new DTO.EurofarStock.DataContract.Post.productContractCustomAttribute()
                {
                    attribute_code = "qnt40hc", value = item.Qnt40HC.Value.ToString()
                });
            }
            return(postData);
        }