Exemple #1
0
        //AF
        /// <summary>
        /// 1:satış fiyatı
        /// 2:satın alma fiyatı
        /// 3:ilk satış fiyatı
        /// </summary>
        /// <param name="Product"></param>
        /// <param name="currencyCode"></param>
        /// <param name="price1"></param>
        /// <param name="price2"></param>
        /// <param name="price3"></param>
        private void CreateProductBasePrice(NebimV3.Items.Product Product, string currencyCode, decimal price1 = 0, decimal price2 = 0, decimal price3 = 0)
        {
            using (NebimV3.DataConnector.JoinedSqlTransactionScope Trans = new NebimV3.DataConnector.JoinedSqlTransactionScope())
            {
                NebimV3.Items.ItemBasePrice ibp = new NebimV3.Items.ItemBasePrice(Product);
                ibp.BasePriceCode = (byte)NebimV3.Items.BasePriceCodes.RetailSalePrice;
                ibp.CurrencyCode  = currencyCode; // USD, EUR vs...
                ibp.CountryCode   = "TR";
                ibp.Price         = price1;
                ibp.PriceDate     = DateTime.Today; // Günün tarihini atıyoruz. Farklı bir tarih yazılmasına gerek yok.
                ibp.SaveOrUpdate();
                Product.BasePrices.Add(ibp);

                if (price2 > 0)
                {
                    ibp = new NebimV3.Items.ItemBasePrice(Product);
                    ibp.BasePriceCode = (byte)NebimV3.Items.BasePriceCodes.PurchasePrice;
                    ibp.CurrencyCode  = currencyCode; // USD, EUR vs...
                    ibp.CountryCode   = "TR";
                    ibp.Price         = price2;
                    ibp.PriceDate     = DateTime.Today; // Günün tarihini atıyoruz. Farklı bir tarih yazılmasına gerek yok.
                    ibp.SaveOrUpdate();
                    Product.BasePrices.Add(ibp);
                }
                if (price3 > 0)
                {
                    ibp = new NebimV3.Items.ItemBasePrice(Product);
                    ibp.BasePriceCode = (byte)NebimV3.Items.BasePriceCodes.FirstSalePrice;
                    ibp.CurrencyCode  = currencyCode; // USD, EUR vs...
                    ibp.CountryCode   = "TR";
                    ibp.Price         = price3;
                    ibp.PriceDate     = DateTime.Today; // Günün tarihini atıyoruz. Farklı bir tarih yazılmasına gerek yok.
                    ibp.SaveOrUpdate();
                    Product.BasePrices.Add(ibp);
                }

                Trans.Commit();
            }
        }
Exemple #2
0
        //AF
        internal void CreateUpdateProduct(
            string Barcode,
            string ProductCode,        /*sku*/
            string ProductNameTR,
            string ProductNameEN,
            int ItemDimTypeCode,
            IList <Tuple <string, string, string, string, string, string, string> > combinations,     //renk kodu,renk adı, renk adı, boyut kodu,boyut adı,boyut adı
            string UnitOfMeasureCode1,
            string CountryCode,
            string PurcVatRate,                                       //tax rate
            string SellVatRate,                                       //tax rate
            string ItemAccountGrCode,                                 //tax rate
            int[] ProductHierarchyLevelCodes,
            IList <Tuple <byte, string, string, string> > attributes, //attr type code (1-20),attr code, attr name,attr name
            decimal price1,
            decimal price2,
            decimal price3,
            string currencyCode)
        {
            try
            {
                using (NebimV3.DataConnector.JoinedSqlTransactionScope Trans = new NebimV3.DataConnector.JoinedSqlTransactionScope())
                {
                    NebimV3.Items.Product Product = new NebimV3.Items.Product();
                    Product.ProductCode        = ProductCode;
                    Product.ProductDescription = ProductNameTR;
                    //kampanya grubu
                    Product.PromotionGroupCode = null;//"Sezon"; //sezon ürünleri
                    #region hierarchy

                    //TODO: yoksa önce hiyerarşi yaratılmalıdır.
                    // Ürün hiyerarşisindeki yeri
                    int?hierarchyId = FindProductHierarchy(ProductHierarchyLevelCodes);
                    if (!hierarchyId.HasValue)
                    {
                        throw new Exception("CreateUpdateProduct=> kategori*hiyerarşi eşleşrtirilemedi. product code:" + ProductCode + "hierarchy levels:" + String.Join("-", ProductHierarchyLevelCodes.Select(x => x.ToString())));
                    }
                    Product.ProductHierarchyID = 0;//ProductHierarchyLevel03.HasValue? ProductHierarchyLevel03.Value:ProductHierarchyLevel02.HasValue?ProductHierarchyLevel02.Value:ProductHierarchyLevel03.Value;

                    #endregion hierarchy

                    //NoDimension = 0,
                    //OnlyColor = 1,
                    //ColorAndOne = 2,
                    //ColorAndTwo = 3,
                    //ColorAndThree = 4,
                    Product.ItemDimTypeCode = (byte)ItemDimTypeCode;   // Örn: Renk + Beden + Ton

                    // Vergi grubu
                    Product.ItemTaxGrCode = ItemAccountGrCode;
                    Product.SaveOrUpdate();

                    // Farklı dilde ürün açıklaması için
                    string LangCode = "EN";
                    Product.Descriptions.Load();
                    NebimV3.v3Entities.LanguageDescription LanguageDescription = Product.Descriptions.Where((NebimV3.v3Entities.LanguageDescription X) => NebimV3.Library.ObjectComparer.AreEqual(X.DataLanguageCode, LangCode)).FirstOrDefault();
                    if (LanguageDescription != null)
                    {
                        LanguageDescription.Description = ProductNameEN;
                        LanguageDescription.SaveOrUpdate();
                    }

                    #region variants
                    // Renk ve boyut ekleme
                    foreach (var comb in combinations)
                    {
                        switch (ItemDimTypeCode)
                        {
                        case 0:
                            CreateProductBarcode(Product, comb.Item7);
                            break;

                        case 1:
                            CreateColorIfNotExists(comb.Item1, comb.Item2, comb.Item3);
                            Product.Variants.Load();
                            //check if variant is already exists?
                            if (Product.Variants.Any(x => x.ColorCode == comb.Item1))
                            {
                                break;
                            }
                            Product.AddItemVariant(comb.Item1);
                            CreateProductBarcode(Product, comb.Item7, comb.Item1);
                            break;

                        case 2:
                            CreateColorIfNotExists(comb.Item1, comb.Item2, comb.Item3);
                            CreateItemDim1IfNotExists(comb.Item4, comb.Item5, comb.Item6);
                            Product.Variants.Load();
                            //check if variant is already exists?
                            if (Product.Variants.Any(x => (x.ColorCode == comb.Item1) && (x.ItemDim1Code == comb.Item4)))
                            {
                                break;
                            }
                            Product.AddItemVariant(comb.Item1, comb.Item4);
                            CreateProductBarcode(Product, comb.Item7, comb.Item1, comb.Item4);
                            break;

                        default:
                            break;
                        }
                    }
                    #endregion variants

                    #region attributes

                    Product.Attributes.Load();
                    for (byte i = 0; i < attributes.Count; i++)
                    {
                        var attr = attributes[i];
                        if (string.IsNullOrWhiteSpace(attr.Item2))
                        {
                            continue;
                        }
                        if (Product.Attributes.Any(x => (x.AttributeCode == attr.Item2) && (x.AttributeTypeCode == attr.Item1)))
                        {
                            continue;
                        }

                        //this.CreateProductAttributeIfNotExists(attr.Item1, attr.Item2, attr.Item3, attr.Item4);
                        NebimV3.Items.ProductAttribute Attribute = new NebimV3.Items.ProductAttribute(Product);
                        Attribute.AttributeTypeCode = attr.Item1;
                        Attribute.AttributeCode     = attr.Item2;
                        Attribute.SaveOrUpdate();
                        Product.Attributes.Add(Attribute);
                    }
                    #endregion attributes

                    this.CreateProductBasePrice(Product, currencyCode, price1, price2, price3);

                    Trans.Commit();
                }
            }
            catch (Exception ex)
            {
                NebimV3.Library.V3Exception v3Ex = ex as NebimV3.Library.V3Exception;
                if (v3Ex != null)
                {
                    throw new Exception(NebimV3.ApplicationCommon.ExceptionHandlerBase.Default.GetExceptionMessage(v3Ex), ex);
                }
                throw;
            }
        }