예제 #1
0
        public static void OffersFromString(Product product, string offersString)
        {
            product.HasMultiOffer = true;

            var oldOffers = new List<Offer>(product.Offers);
            product.Offers.Clear();

            var mainOffer = true;

            foreach (string[] fields in offersString.Split(';').Select(str => str.Replace("[", "").Replace("]", "").Split(':')))
            {
                if (fields.Count() == 6)
                {
                    var multiOffer = oldOffers.FirstOrDefault(offer => offer.ArtNo == fields[0]) ?? new Offer();
                    multiOffer.ProductId = product.ProductId;
                    multiOffer.Main = mainOffer;

                    multiOffer.ArtNo = fields[0]; // ArtNo

                    if (fields[1] != "null") // Size
                    {
                        Size size = SizeService.GetSize(fields[1]);
                        if (size == null)
                        {
                            size = new Size { SizeName = fields[1] };
                            size.SizeId = SizeService.AddSize(size);
                        }

                        multiOffer.SizeID = size.SizeId;
                    }

                    if (fields[2] != "null") // Color
                    {
                        Color color = ColorService.GetColor(fields[2]);
                        if (color == null)
                        {
                            color = new Color { ColorName = fields[2], ColorCode = "#000000" };
                            color.ColorId = ColorService.AddColor(color);
                        }

                        multiOffer.ColorID = color.ColorId;
                    }

                    multiOffer.Price = fields[3].TryParseFloat(); // Price
                    multiOffer.SupplyPrice = fields[4].TryParseFloat(); // SupplyPrice
                    multiOffer.Amount = fields[5].TryParseFloat(); //Amount

                    product.Offers.Add(multiOffer);
                    mainOffer = false;
                }
            }
        }
예제 #2
0
        public static void OfferFromStrings(Product product, string priceString, string purchasePriceString, string amountString)
        {
            if (priceString.IsNullOrEmpty() && purchasePriceString.IsNullOrEmpty() && amountString.IsNullOrEmpty())
                return;

            product.HasMultiOffer = false;

            var singleOffer = product.Offers.FirstOrDefault() ?? new Offer();
            product.Offers.Clear();

            singleOffer.ArtNo = product.ArtNo;
            singleOffer.Main = true;
            singleOffer.ProductId = product.ProductId;

            if (priceString.IsNotEmpty())
                singleOffer.Price = priceString.TryParseFloat();

            if (purchasePriceString.IsNotEmpty())
                singleOffer.SupplyPrice = purchasePriceString.TryParseFloat();

            if (amountString.IsNotEmpty())
                singleOffer.Amount = amountString.TryParseFloat();

            product.Offers.Add(singleOffer);
        }
예제 #3
0
        public static TableRow ProcessProductRow(Product product, int depth, int parentCategoryId, int taxID)
        {
            string parentCategoryPath = GetCategoryPath(parentCategoryId);

            var productTableRow = new TableRow();
            productTableRow.Attributes.Add("class", "productRow");
            productTableRow.Attributes.Add("onmouseover", "onDataRowMouseOver(this);");
            productTableRow.Attributes.Add("onmouseout", "onDataRowMouseOut(this);");
            productTableRow.Attributes.Add("onclick", "ProductRow_ClickHandler(this);");

            var productNameBlock = new TableCell();
            var margin = 15;
            for (var i = 1; i <= depth; i++)
            {
                margin += 20;
            }

            var span = new HtmlGenericControl("span");
            span.Style.Add("margin-left", margin.ToString());
            span.Style.Add("display", "block");
            span.Style.Add("position", "relative");

            var chkSpan = new HtmlGenericControl("span");
            chkSpan.Style.Add("position", "absolute");
            chkSpan.Style.Add("top", "50%");

            span.Controls.Add(chkSpan);

            var checkBox = new CheckBox
                               {
                                   ID = parentCategoryPath + product.ProductId + "_Product",
                                   Checked = GetProductSelectionState(product.ProductId, taxID)
                               };
            checkBox.Style.Add("position", "absolute");

            if (HttpContext.Current.Request.Browser.Browser == "IE")
            {
                checkBox.Style.Add("top", "-15px");
            }
            else
            {
                checkBox.Style.Add("top", "-9px");
            }

            chkSpan.Controls.Add(checkBox);

            var productNameLiteral = new HtmlGenericControl("span") { InnerText = product.Name };
            productNameLiteral.Attributes.Add("class", "productLiteral");
            productNameBlock.Controls.Add(productNameLiteral);
            span.Controls.Add(productNameLiteral);
            productNameBlock.Controls.Add(span);
            productTableRow.Cells.Add(productNameBlock);

            var priceBlock = new TableCell();
            productTableRow.Cells.Add(priceBlock);

            var quantBlock = new TableCell();
            productTableRow.Cells.Add(quantBlock);

            if (product.Offers.Count > 0 && (product.Offers[0] != null))
            {
                priceBlock.Text = CatalogService.GetStringPrice(product.Offers[0].Price);
                quantBlock.Text = product.Unit;
            }

            productTableRow.ID = parentCategoryPath + product.ProductId + "_TableRow";

            return productTableRow;
        }
예제 #4
0
        private static void UpdateInsertProductWorker(object o)
        {
            //return;

            var productInStrings = (Dictionary<ProductFields.Fields, string>)o;
            try
            {
                bool addingNew;
                Product product = null;
                if (productInStrings.ContainsKey(ProductFields.Fields.Sku) && productInStrings[ProductFields.Fields.Sku].IsNullOrEmpty())
                    throw new Exception("SKU can not be empty");

                var artNo = productInStrings.ContainsKey(ProductFields.Fields.Sku) ? productInStrings[ProductFields.Fields.Sku] : string.Empty;
                if (string.IsNullOrEmpty(artNo))
                {
                    addingNew = true;
                }
                else
                {
                    product = ProductService.GetProduct(artNo);
                    addingNew = product == null;
                }

                if (addingNew)
                {
                    product = new Product { ArtNo = string.IsNullOrEmpty(artNo) ? null : artNo, Multiplicity=1};
                }

                if (productInStrings.ContainsKey(ProductFields.Fields.Name))
                    product.Name = productInStrings[ProductFields.Fields.Name];
                else
                    product.Name = product.Name ?? string.Empty;

                if (productInStrings.ContainsKey(ProductFields.Fields.Enabled))
                {
                    product.Enabled = productInStrings[ProductFields.Fields.Enabled].Trim().Equals("+");
                }
                else
                {
                    product.Enabled = true;
                }

                if (productInStrings.ContainsKey(ProductFields.Fields.OrderByRequest))
                    product.AllowPreOrder = productInStrings[ProductFields.Fields.OrderByRequest].Trim().Equals("+");

                if (productInStrings.ContainsKey(ProductFields.Fields.Discount))
                    product.Discount = SQLDataHelper.GetFloat(productInStrings[ProductFields.Fields.Discount]);

                if (productInStrings.ContainsKey(ProductFields.Fields.Weight))
                    product.Weight = SQLDataHelper.GetFloat(productInStrings[ProductFields.Fields.Weight]);

                if (productInStrings.ContainsKey(ProductFields.Fields.Size))
                    product.Size = GetSizeForBdFormat(productInStrings[ProductFields.Fields.Size]);

                if (productInStrings.ContainsKey(ProductFields.Fields.BriefDescription))
                    product.BriefDescription = productInStrings[ProductFields.Fields.BriefDescription];

                if (productInStrings.ContainsKey(ProductFields.Fields.Description))
                    product.Description = productInStrings[ProductFields.Fields.Description];

                if (productInStrings.ContainsKey(ProductFields.Fields.SalesNote))
                    product.SalesNote = productInStrings[ProductFields.Fields.SalesNote];
                if (productInStrings.ContainsKey(ProductFields.Fields.ShippingPrice))
                    product.ShippingPrice = SQLDataHelper.GetFloat(productInStrings[ProductFields.Fields.ShippingPrice]);

                if (productInStrings.ContainsKey(ProductFields.Fields.Unit))
                    product.Unit = productInStrings[ProductFields.Fields.Unit];

                if (productInStrings.ContainsKey(ProductFields.Fields.MultiOffer))
                {
                    OfferService.OffersFromString(product, productInStrings[ProductFields.Fields.MultiOffer]);
                }
                else
                {
                    OfferService.OfferFromStrings(product,
                                                  productInStrings.ContainsKey(ProductFields.Fields.Price)
                                                      ? productInStrings[ProductFields.Fields.Price]
                                                      : string.Empty,
                                                  productInStrings.ContainsKey(ProductFields.Fields.PurchasePrice)
                                                      ? productInStrings[ProductFields.Fields.PurchasePrice]
                                                      : string.Empty,
                                                  productInStrings.ContainsKey(ProductFields.Fields.Amount)
                                                      ? productInStrings[ProductFields.Fields.Amount]
                                                      : string.Empty);
                }

                if (productInStrings.ContainsKey(ProductFields.Fields.ParamSynonym))
                {
                    var prodUrl = productInStrings[ProductFields.Fields.ParamSynonym].IsNotEmpty()
                                      ? productInStrings[ProductFields.Fields.ParamSynonym]
                                      : product.ArtNo;
                    product.UrlPath = UrlService.GetEvalibleValidUrl(product.ID, ParamType.Product, prodUrl);
                }
                else
                {
                    product.UrlPath = product.UrlPath ??
                                      UrlService.GetEvalibleValidUrl(product.ID, ParamType.Product,
                                      product.ArtNo ?? product.Name.Substring(0, product.Name.Length-1 < 50 ? product.Name.Length-1: 50));

                }

                product.Meta.ObjId = product.ProductId;

                if (productInStrings.ContainsKey(ProductFields.Fields.Title))
                    product.Meta.Title = productInStrings[ProductFields.Fields.Title];
                else
                    product.Meta.Title = product.Meta.Title ?? SettingsSEO.ProductMetaTitle;

                if (productInStrings.ContainsKey(ProductFields.Fields.H1))
                    product.Meta.H1 = productInStrings[ProductFields.Fields.H1];
                else
                    product.Meta.H1 = product.Meta.H1 ?? SettingsSEO.ProductMetaTitle;

                if (productInStrings.ContainsKey(ProductFields.Fields.MetaKeywords))
                    product.Meta.MetaKeywords = productInStrings[ProductFields.Fields.MetaKeywords];
                else
                    product.Meta.MetaKeywords = product.Meta.MetaKeywords ?? SettingsSEO.ProductMetaKeywords;

                if (productInStrings.ContainsKey(ProductFields.Fields.MetaDescription))
                    product.Meta.MetaDescription = productInStrings[ProductFields.Fields.MetaDescription];
                else
                    product.Meta.MetaDescription = product.Meta.MetaDescription ?? SettingsSEO.ProductMetaDescription;

                if (productInStrings.ContainsKey(ProductFields.Fields.Markers))
                    ProductService.MarkersFromString(product, productInStrings[ProductFields.Fields.Markers]);

                if (productInStrings.ContainsKey(ProductFields.Fields.Producer))
                    product.BrandId = BrandService.BrandFromString(productInStrings[ProductFields.Fields.Producer]);

                if (!addingNew)
                {
                    ProductService.UpdateProduct(product, false);
                    //Log(string.Format(Resource.Admin_Import1C_Updated, product.Name, product.ArtNo));
                    CommonStatistic.TotalUpdateRow++;
                }
                else
                {
                    if (!(SaasDataService.IsSaasEnabled && ProductService.GetProductsCount() >= SaasDataService.CurrentSaasData.ProductsCount))
                    {
                        ProductService.AddProduct(product, false);
                        //Log(string.Format(Resource.Admin_Import1C_Added, product.Name, product.ArtNo));
                        CommonStatistic.TotalAddRow++;
                    }
                }

                if (product.ProductId > 0)
                    OtherFields(productInStrings, product.ProductId);
            }
            catch (Exception e)
            {
                CommonStatistic.TotalErrorRow++;
                Log(CommonStatistic.RowPosition + ": " + e.Message);
            }

            productInStrings.Clear();
            CommonStatistic.RowPosition++;
        }
예제 #5
0
        public ProductItem(int offerId, Product product, IEnumerable<string> propertyNames)
        {
            OfferId = offerId;
            ProductId = product.ProductId;
            CategoryId = ProductService.GetFirstCategoryIdByProductId(ProductId);
            Name = product.Name;
            ArtNo = product.ArtNo;
            Photo = product.Photo;
            UrlPath = product.UrlPath;
            var firstOrDefault = product.Offers.FirstOrDefault();
            if (firstOrDefault != null)
            {
                Price = firstOrDefault.GetPrice(CustomerPriceType, CustomerId);
                Amount = firstOrDefault.Amount;
            }
            Discount = product.Discount;
            AllowPreorder = product.AllowPreOrder;

            Properties = new List<ProductProperty>();

            var properties = PropertyService.GetPropertyValuesByProductId(product.ProductId);
            foreach (var propertyName in propertyNames)
            {
                var list = properties.Where(p => p.Property.Name == propertyName);
                if (list.Any())
                {
                    foreach (var propertyValue in list)
                    {
                        Properties.Add(new ProductProperty
                            {
                                PropertyId = propertyValue.PropertyId,
                                Name = propertyName,
                                Value = propertyValue.Value
                            });
                    }
                }
                else
                {
                    Properties.Add(new ProductProperty
                        {
                            Name = propertyName,
                            Value = " - "
                        });
                }
            }
        }