コード例 #1
0
        /// <summary>
        /// Add taxes to products (i.e product attributes) (e.g ecotaxe)
        /// </summary>
        /// <param name="stock"></param>
        /// <param name="productId"></param>
        //private static JArray syncTaxAndCondit(STOCK stock, int productId = 0)
        //{
        //    JArray ja = new JArray();
        //    JObject attributeMapping;
        //    JArray attributeValues;
        //    string productVAttributeId;
        //    //Attributes
        //    foreach (ARTLIENS a in stock.ARTLIENS)
        //    {
        //        if (a.VEN)
        //        {
        //            int attributeId = 0;
        //            productVAttributeId = "";

        //            //Create attribute if it doesn't exist yet
        //            JObject paO = JObject.Parse(WebService.Get(WebServiceUrls.PRODUCT_ATTRIBUTE + "?$filter=Name+eq+'" + a.STOCK1.S_MODELE.TrimEnd() + "'"));
        //            var pa = paO["value"].ToArray();
        //            if (pa.Count() == 0)
        //            {
        //                string result = WebService.Post(WebServiceUrls.PRODUCT_ATTRIBUTE, ParserJSon.ParseTaxToProductAttribute(a.STOCK1.S_MODELE.TrimEnd()));
        //                JObject idO = JObject.Parse(result);
        //                attributeId = (int)idO["Id"];
        //            }
        //            else
        //            {
        //                attributeId = (int)pa[0]["Id"];
        //            }

        //            attributeMapping = ParserJSon.ParseArtLien1ToProductVariantAttribute(attributeId, productId);

        //            //Add value to attribute
        //            attributeValues = new JArray();
        //            //JObject pvavO = JObject.Parse(WebService.Get(WebServiceUrls.PRODUCT_VARIANT_ATTRIBUTE_VALUE + "?$filter=ProductAttributeMappingId+eq+" + productVAttributeId));
        //            //var pvav = pvavO["value"].ToArray();

        //            attributeValues.Add(ParserJSon.ParseArtLien1ToProductVariantAttributeValue(a.STOCK1.S_MODELE.TrimEnd(), a.STOCK1.S_PRIX_TI));

        //            attributeMapping.Add("ProductAttributeValues", attributeValues);
        //            ja.Add(attributeMapping);
        //        }

        //    }

        //    if (stock.S_CONDIT_V > 1)
        //    {
        //        attributeMapping = ParserJSon.ParseArtLien1ToProductVariantAttribute(1, productId);
        //        attributeValues = new JArray();
        //        attributeValues.Add(ParserJSon.ParseArtLien1ToProductVariantAttributeValue(stock.S_CONDIT_V.ToString() + " PC", 0));
        //        attributeMapping.Add("ProductAttributeValues", attributeValues);
        //        ja.Add(attributeMapping);
        //    }

        //    return ja;
        //}

        /// <summary>
        /// Map product to tier prices (Tarifs in Mercator)
        /// </summary>
        /// <param name="stock"></param>
        /// <param name="productId"></param>
        /// <param name="connection"></param>
        //private static JArray MapTierPrices(STOCK stock, SqlConnection connection, int productId)
        //{
        //    JArray array = new JArray();
        //    string json = WebService.Get("TierPrice?$filter=ProductId+eq+" + productId);
        //    JToken[] valuesTP = ParserJSon.ParseResultToJTokenList(json);

        //    List<String> tpToKeep = new List<String>();

        //    //Get existing customer roles
        //    string jsonCR = WebService.Get("CustomerRole?$filter=IsSystemRole+eq+false");
        //    JToken[] valuesCR = ParserJSon.ParseResultToJTokenList(jsonCR);

        //    //CustomerRoleID => Price in Nop
        //    IDictionary<String, String> tpMap = new Dictionary<String, String>();
        //    foreach (JToken v in valuesTP)
        //    {
        //        tpMap.Add(v["CustomerRoleId"].ToString()+"KEY", v["Id"].ToString());
        //        tpMap.Add(v["CustomerRoleId"].ToString(), v["Price"].ToString());

        //    }

        //    foreach (JToken v in valuesCR)
        //    {
        //        string tarId = v["SystemName"].ToString().Split('_').Last();
        //        double tarti = (double)connection.Entry(stock).Property("S_PRIXHT" + tarId).CurrentValue;
        //        decimal remise = GetRemise(stock,connection,tarId);
        //        string concernedPrice;
        //        tpMap.TryGetValue(v["Id"].ToString(), out concernedPrice);
        //        //If TierPrice contains customer role's id => Check if it's the same price
        //        if (concernedPrice != null)
        //        {
        //            //Price have changed => Patch
        //            if (tarti.ToString() != concernedPrice)
        //            {
        //                array.Add(ParserJSon.GetTierPriceJson((int)v["Id"], tarti, remise, productId));
        //            }
        //        }
        //        //If it's not in it, we add it
        //        else
        //        {
        //            array.Add(ParserJSon.GetTierPriceJson((int)v["Id"], tarti, remise, productId));
        //        }
        //    }
        //    return array;
        //    //DELETE DONE AUTOMATICALLY WHEN TARIF IS REMOVED
        //}

        /// <summary>
        /// Get remise by stock and tarif
        /// </summary>
        /// <param name="stock"></param>
        /// <param name="context"></param>
        /// <param name="tarId"></param>
        /// <returns></returns>
        //private static decimal GetRemise(STOCK stock, SqlConnection connection, string tarId)
        //{
        //    string scat2 = stock.S_CAT2;
        //    var cats = from c in context.CAT_STCK
        //                   where c.NOM.TrimEnd() == scat2.TrimEnd()
        //                   select c;

        //    if(cats.FirstOrDefault() != null)
        //    {
        //        CAT_STCK cs = cats.FirstOrDefault();
        //        object tarti = context.Entry(cs).Property("CAT" + tarId).CurrentValue;
        //        return (decimal)(double)tarti;
        //    }

        //    return 0;
        //}


        /// <summary>
        /// Add a new entry in Nop Product_Category_Mapping Table
        /// </summary>
        private JArray MapCategory(STOCK stock, IDictionary <string, int> categories, int productId = 0)
        {
            string ray   = stock.S_ID_RAYON.TrimEnd();
            string fam   = stock.S_ID_FAMIL.TrimEnd();
            string ssfam = stock.S_ID_SSFAM.TrimEnd();
            //Get CatId
            string rfsId = (ssfam == "") ? ((fam == "") ? ray : fam) : ssfam;

            int  catId;
            bool catExists = categories.TryGetValue(rfsId, out catId);

            //If catID is empty, the rfs have not been syncrhonised. Sync it or do nothing ?
            if (catExists)
            {
                JArray cats = new JArray();
                cats.Add(ParserJSon.getProductCategoryJson(catId, productId));
                return(cats);
            }
            return(null);
        }