Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //if (validationResult() == true)
            //{
            if (txtCableStart.Text != "")
            {
                double cableStart = Convert.ToDouble(txtCableStart.Text);
                double cableEnd   = Convert.ToDouble(txtCableEnd.Text);
                txtQuantity.Text = (cableEnd - cableStart).ToString();
            }
            double quantity = Convert.ToDouble(txtQuantity.EditValue == "" ? 0 : txtQuantity.EditValue);

            if (_stockDetailId == 0)
            {
                var stockDetail = new StockDetail();
                stockDetail.STOCKDETAIL_BARCODE_ID    = BarcodeHelper.GenerateBarcode();
                stockDetail.STOCKDETAIL_MASTER_ID     = _stockMasterId;
                stockDetail.STOCKDETAIL_STORE_ID      = (int)lueStore.EditValue;
                stockDetail.STOCKDETAIL_ITEM_ID       = (int)lueItem.EditValue;
                stockDetail.STOCKDETAIL_RACK_ID       = 7;
                stockDetail.STOCKDETAIL_QUANTITY      = quantity;
                stockDetail.STOCKDETAIL_PRIVATEVALUE1 = string.IsNullOrEmpty(txtCableStart.Text) ? 0 : Convert.ToDouble(txtCableStart.EditValue);
                stockDetail.STOCKDETAIL_PRIVATEVALUE2 = string.IsNullOrEmpty(txtCableEnd.Text) ? 0 : Convert.ToDouble(txtCableEnd.EditValue);
                stockDetail.STOCKDETAIL_SERIALNUMBER  = txtSerialNumber.Text;
                if (lueProject.EditValue != string.Empty)
                {
                    stockDetail.STOCKDETAIL_REF_ID = (int)lueProject.EditValue;
                }
                stockDetail.STOCKDETAIL_REF_LINK = "ProjectImport";

                dbContext.StockDetail.Add(stockDetail);
                dbContext.SaveChanges();
                _stockDetailId            = 0;
                txtQuantity.EditValue     = "";
                txtSerialNumber.EditValue = "";
                lueItem.EditValue         = "";
                lueProject.EditValue      = "";
                txtCableStart.EditValue   = "";
                txtCableEnd.EditValue     = "";
                btnDelete.Enabled         = false;
                lueItem.Enabled           = true;
            }
            else
            {
                var existStockDetail = dbContext.StockDetail.Find(_stockDetailId);
                existStockDetail.STOCKDETAIL_QUANTITY      = quantity;
                existStockDetail.STOCKDETAIL_SERIALNUMBER  = txtSerialNumber.Text;
                existStockDetail.STOCKDETAIL_PRIVATEVALUE1 = string.IsNullOrEmpty(txtCableStart.Text) ? 0 : Convert.ToDouble(txtCableStart.EditValue);
                existStockDetail.STOCKDETAIL_PRIVATEVALUE2 = string.IsNullOrEmpty(txtCableEnd.Text) ? 0 : Convert.ToDouble(txtCableEnd.EditValue);
                dbContext.SaveChanges();
                _stockDetailId            = 0;
                txtQuantity.EditValue     = "";
                txtSerialNumber.EditValue = "";
                lueItem.EditValue         = "";
                lueProject.EditValue      = "";
                txtCableStart.EditValue   = "";
                txtCableEnd.EditValue     = "";
                btnDelete.Enabled         = false;
                lueItem.Enabled           = true;
            }
            LoadData();
            //}
        }
        public static IList <ExcelWFSProductUSViewModel> GenerateToExcelUS(IUnitOfWork db,
                                                                           IBarcodeService barcodeService,
                                                                           IMarketCategoryService categoryService,
                                                                           StyleViewModel model,
                                                                           DateTime when,
                                                                           out string filename)
        {
            /*
             *  1.	Item_sku:
             *      a.	First row = Style
             *      b.	Other rows – Style-%size%, i.e. K123123-2T, K123123-3T..
             *  2.	Item name:
             *      a.	First Raw - %Name% + “,”+%Size Group% (Infant, Toddler, Kids)+”Sizes”+%Size_Range%” (example: Planes Boys 'Turn Up the Heat' Coat Style Pajama Set, Toddler Sizes 2T-4T)
             *      b.	Other rows: %Name% + “,”+%Size Group% (Infant, Toddler, Kids)+%Size% (i.e. Planes Boys 'Turn Up the Heat' Coat Style Pajama Set, Toddler Size 2T)
             *  3.	external_product_id – barcode (empty for first raw)
             *  4.	external_product_id_type – harcoded “UPC” (empty for first raw)
             *  16.	brand_name - Main License
             *  17.	item_type – use same logic as you use when you generate xls from ASIN
             *  18.	main_image_url – upload image to server, and insert public URL to this image here
             *  19.	Color - %Color%
             *  20.	Department_name - use same logic as you use when you generate xls from ASIN
             *  21.	Size - %size%
             *  22.	update_delete – “Update”
             *  23.	standard_price - %price%
             *  24.	list_price -- %MSRP%
             *  25.	currency – “USD”
             *  26.	quantity – “%Quantity%
             *  27.	bullet_point1 – “Authentic ”+ %Main License% +” product with reliable quality and durability
             *  28.	bullet_point2 – “Featuring “+%sublicense%
             *  29.	bullet_point3 – if(Material  != Cotton) “Flame resistant” else “100% Cotton”
             *  30.	bullet_point4 – “Machine Wash, Easy Care”
             *  31.	generic_keywords1 = if(Item style = pajama) “ sleepwear, pj, jummie, new, %sleeve%”
             *      if(nightgown) “night, gown, night-gown, sleepwear, pj, jummie, new, %sleeve%, dress up”
             *  32.	“Gift, present, 2015, cozy ” If(Material =fleece) “Fleece, microfleece, warm, winter spring”
             *  33.	parent_child, parent_sku, relationship_type, variation_theme – same logic as you use when you generate xls from ASIN
             *  34.	if More then one picture provided insert their URL into other_image_url1, other_image_url2, other_image_url3
             */

            var models = new List <ExcelWFSProductUSViewModel>();

            var parent = new ExcelWFSProductUSViewModel();
            var childs = new List <ExcelWFSProductUSViewModel>();

            var sizes = model.StyleItems.Items;

            //Size Group, Size Range
            var             hasKids2      = sizes.Any(s => ItemExportHelper.GetSizeGroupByName(s.SizeGroupName, true) == ExportSizeGroup.Kids2);
            ExportSizeGroup?sizeGroup     = sizes.Any() ? (ExportSizeGroup?)ItemExportHelper.GetSizeGroupByName(sizes.Last().SizeGroupName, false) : null;
            var             sizeGroupName = ItemExportHelper.GetSizeGroupName(sizeGroup);
            var             sizeRange     = ItemExportHelper.GetSizeRangeName(sizes.Select(s => s.Size).ToList(), hasKids2);
            var             firstSize     = sizes.Any() ? sizes[0].Size : String.Empty;

            //Features Values
            var features = model.Features.Select(f => new FeatureValueDTO()
            {
                FeatureId = f.FeatureId,
                Value     = f.Value,
            }).ToList();
            var allFeatureValues = db.FeatureValues.GetAllFeatureValueByItemType(1);

            var gender      = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.GENDER);
            var itemStyle   = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.ITEMSTYLE);
            var sleeve      = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SLEEVE);
            var material    = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.MATERIAL);
            var color1      = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.COLOR1);
            var mainLicense = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.MAIN_LICENSE);
            var subLicense  = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SUB_LICENSE1);
            //var shippingSize = ItemExportHelper.GetFeatureValue(features, allFeatureValues, Feature.SHIPPING_SIZE);

            //var itemType = ItemExportHelper.GetItemType(itemStyle);
            var sizeType     = ItemExportHelper.GetSizeType(firstSize);
            var categoryInfo = categoryService.GetCategory(MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId, itemStyle, gender, sizeType);

            var brandName = ItemExportHelper.GetBrandName(mainLicense, subLicense);

            var    newItemType   = categoryInfo.Key1;// ItemExportHelper.ItemTypeConverter(firstSize ?? "", itemType, itemStyle, gender);
            var    newDepartment = StringHelper.GetFirstNotEmpty(categoryInfo.Key2, ItemExportHelper.DepartmentConverter(gender, newItemType, sizeType));
            string clothingType  = categoryInfo.Key3;

            var searchTerms = model.SearchTerms;       // ItemExportHelper.BuildSearchTerms(itemStyle, material, sleeve);
            var keyFeatures = model.GetBulletPoints(); // ItemExportHelper.BuildKeyFeatures(mainLicense, subLicense, material);


            //--------------------------
            //Parent item
            //--------------------------
            parent.SKU  = model.StyleId;
            parent.ASIN = "";

            parent.Title = model.Name + "," + (!String.IsNullOrEmpty(sizeGroupName) ? " " + ItemExportHelper.FormatSizeGroupName(sizeGroupName) : String.Empty) + " " + sizeRange;
            //If it causes name length to exceed maximum allowed, please drop words “Kids” or Toddler”
            var inlcudeSizeGroup = true;

            if (parent.Title.Length > ItemExportHelper.MaxItemNameLength)
            {
                parent.Title     = model.Name + ", " + sizeRange;
                inlcudeSizeGroup = false;
            }


            parent.ProductId = "";
            parent.BrandName = brandName;

            parent.Type = newItemType;


            var images      = new List <string>();
            var swatchImage = "";

            if (model.ImageSet != null)
            {
                images = model.ImageSet.Images
                         .Where(im => im.Category != (int)StyleImageCategories.Swatch)
                         .OrderByDescending(im => ImageHelper.GetSortIndex(im.Category))
                         .ThenByDescending(im => im.IsDefault)
                         .ThenBy(im => im.Id)
                         .Select(im => im.ImageUrl)
                         .ToList();
                swatchImage = model.ImageSet.Images
                              .FirstOrDefault(im => im.Category == (int)StyleImageCategories.Swatch)?.ImageUrl;

                parent.MainImageURL   = images.Count > 0 ? images[0] : "";
                parent.OtherImageUrl1 = images.Count > 1 ? images[1] : "";
                parent.OtherImageUrl2 = images.Count > 2 ? images[2] : "";
                parent.OtherImageUrl3 = images.Count > 3 ? images[3] : "";
                parent.SwatchImageUrl = swatchImage;
            }

            parent.Color      = "";// color1;
            parent.Department = newDepartment;

            parent.Size           = "";
            parent.Description    = model.Description;
            parent.Update         = "Update";
            parent.StandardPrice  = "";
            parent.SuggestedPrice = Math.Round(model.MSRP).ToString("G");
            parent.Currency       = "USD";

            parent.Quantity = "";

            parent.KeyProductFeatures1 = keyFeatures.Count > 0 ? keyFeatures[0] : "";
            parent.KeyProductFeatures2 = keyFeatures.Count > 1 ? keyFeatures[1] : "";
            parent.KeyProductFeatures3 = keyFeatures.Count > 2 ? keyFeatures[2] : "";
            parent.KeyProductFeatures4 = keyFeatures.Count > 3 ? keyFeatures[3] : "";
            parent.KeyProductFeatures5 = keyFeatures.Count > 4 ? keyFeatures[4] : "";

            parent.SearchTerms1 = searchTerms;
            //parent.SearchTerms3 = "";
            //parent.SearchTerms4 = "";
            //parent.SearchTerms5 = "";

            parent.Parentage        = "Parent";
            parent.ParentSKU        = "";
            parent.RelationshipType = "";
            parent.VariationTheme   = "Size";
            parent.FeedProductType  = clothingType;

            //--------------------------
            //Child items
            //--------------------------
            foreach (var size in sizes)
            {
                var child = new ExcelWFSProductUSViewModel();
                child.SKU = model.StyleId + "-" + ItemExportHelper.ConvertSizeForStyleId(size.Size, hasKids2);

                child.StyleItemId = size.Id;
                child.StyleId     = model.Id;

                if (size.AutoGeneratedBarcode)
                {
                    var newBarcode = BarcodeHelper.GenerateBarcode(barcodeService, child.SKU, when);
                    if (!String.IsNullOrEmpty(newBarcode))
                    {
                        if (size.Barcodes == null)
                        {
                            size.Barcodes = new List <BarcodeDTO>();
                        }
                        size.Barcodes.Insert(0, new BarcodeDTO()
                        {
                            Barcode = newBarcode
                        });
                    }
                }

                child.ASIN = (size.Barcodes != null && size.Barcodes.Any()) ? size.Barcodes.FirstOrDefault().Barcode : String.Empty;

                child.Title = model.Name + "," + (inlcudeSizeGroup ? " " + ItemExportHelper.FormatSizeGroupName(size.SizeGroupName) : "") + " Size " + ItemExportHelper.ConvertSizeForItemName(size.Size, hasKids2);

                child.ProductId = "UPC";
                child.BrandName = brandName;

                child.Type = newItemType;

                child.MainImageURL   = images.Count > 0 ? images[0] : "";
                child.OtherImageUrl1 = images.Count > 1 ? images[1] : "";
                child.OtherImageUrl2 = images.Count > 2 ? images[2] : "";
                child.OtherImageUrl3 = images.Count > 3 ? images[3] : "";
                child.SwatchImageUrl = swatchImage;

                child.Color      = ItemExportHelper.PrepareColor(String.IsNullOrEmpty(size.Color) ? color1 : size.Color);
                child.Department = newDepartment;

                child.Size           = size.Size;
                child.Description    = model.Description;
                child.Update         = "Update";
                child.StandardPrice  = model.Price.ToString("G");
                child.SuggestedPrice = Math.Round(model.MSRP).ToString("G");
                child.Currency       = "USD";

                child.Quantity = size.Quantity.ToString();

                child.KeyProductFeatures1 = parent.KeyProductFeatures1;
                child.KeyProductFeatures2 = parent.KeyProductFeatures2;
                child.KeyProductFeatures3 = parent.KeyProductFeatures3;
                child.KeyProductFeatures4 = parent.KeyProductFeatures4;
                child.KeyProductFeatures5 = parent.KeyProductFeatures5;

                child.SearchTerms1 = parent.SearchTerms1;
                //child.SearchTerms1 = parent.SearchTerms1;
                //child.SearchTerms2 = parent.SearchTerms2;
                //child.SearchTerms3 = parent.SearchTerms3;
                //child.SearchTerms4 = parent.SearchTerms4;
                //child.SearchTerms5 = parent.SearchTerms5;

                child.Parentage        = "Child";
                child.ParentSKU        = parent.SKU;
                child.RelationshipType = "Variation";
                child.VariationTheme   = "Size";

                child.FeedProductType = clothingType;

                childs.Add(child);
            }

            models.Add(parent);
            models.AddRange(childs);

            filename = model.StyleId + "_" + subLicense;
            filename = filename.Replace(" ", "") + "_US.xls";


            return(models);
        }
Пример #3
0
        public static IList <ExcelProductUKViewModel> GenerateToExcelUK(IUnitOfWork db,
                                                                        IBarcodeService barcodeService,
                                                                        IMarketCategoryService categoryService,
                                                                        StyleViewModel model,
                                                                        DateTime when,
                                                                        out string filename)
        {
            var gbpExchangeRate = PriceHelper.GBPtoUSD;

            var models = new List <ExcelProductUKViewModel>();

            var parent = new ExcelProductUKViewModel();
            var childs = new List <ExcelProductUKViewModel>();

            var sizes = model.StyleItems.Items;

            //Size Group, Size Range
            var             hasKids2      = sizes.Any(s => ItemExportHelper.GetSizeGroupByName(s.SizeGroupName, true) == ExportSizeGroup.Kids2);
            ExportSizeGroup?sizeGroup     = sizes.Any() ? (ExportSizeGroup?)ItemExportHelper.GetSizeGroupByName(sizes.Last().SizeGroupName, false) : null;
            var             sizeGroupName = ItemExportHelper.GetSizeGroupName(sizeGroup);

            var sizeRange = ItemExportHelper.GetSizeRangeName(sizes.Select(s => s.Size).ToList(), hasKids2);

            var firstSize = sizes.Any() ? sizes[0].Size : String.Empty;


            //Features Values
            var features = model.Features.Select(f => new FeatureValueDTO()
            {
                FeatureId = f.FeatureId,
                Value     = f.Value,
            }).ToList();
            var allFeatureValues = db.FeatureValues.GetAllFeatureValueByItemType(1);

            var gender    = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.GENDER);
            var itemStyle = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.ITEMSTYLE);
            var sleeve    = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SLEEVE);
            var material  = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.MATERIAL);

            var color1      = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.COLOR1);
            var mainLicense = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.MAIN_LICENSE);
            var subLicense  = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SUB_LICENSE1);
            //var shippingSize = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SHIPPING_SIZE);

            var materialComposition = ItemExportHelper.GetFeatureTextValue(features, StyleFeatureHelper.MATERIAL_COMPOSITION);

            var sizeType     = ItemExportHelper.GetSizeType(firstSize);
            var categoryInfo = categoryService.GetCategory(MarketType.AmazonEU, MarketplaceKeeper.AmazonUkMarketplaceId, itemStyle, gender, sizeType);
            //var itemType = ItemExportHelper.GetItemType(itemStyle);

            var brandName = ItemExportHelper.GetBrandName(mainLicense, subLicense);

            var newItemType   = categoryInfo.Key1;// ItemExportHelper.ItemTypeConverter(firstSize ?? "", itemType, itemStyle, gender);
            var newDepartment = StringHelper.GetFirstNotEmpty(categoryInfo.Key2, ItemExportHelper.DepartmentConverter(gender, newItemType, sizeType));


            var searchTerms = model.SearchTerms;       // ItemExportHelper.BuildSearchTerms(itemStyle, material, sleeve);
            var keyFeatures = model.GetBulletPoints(); // ItemExportHelper.BuildKeyFeatures(mainLicense, subLicense, material);


            var hasCotton = StringHelper.GetInOneOfStrings("Cotton", new List <string>()
            {
                searchTerms,
                model.Name,
                model.Description,
                material
            });

            if (String.IsNullOrEmpty(materialComposition))
            {
                if (hasCotton)
                {
                    materialComposition = "Cotton";
                }
                else
                {
                    materialComposition = "Polyester";
                }
            }


            //--------------------------
            //Parent item
            //--------------------------
            parent.SKU  = model.StyleId;
            parent.ASIN = "";

            parent.Title = model.Name + "," + (!String.IsNullOrEmpty(sizeGroupName) ? " " + ItemExportHelper.FormatSizeGroupName(sizeGroupName) : String.Empty) + " " + sizeRange;
            //If it causes name length to exceed maximum allowed, please drop words “Kids” or Toddler”
            var inlcudeSizeGroup = true;

            if (parent.Title.Length > ItemExportHelper.MaxItemNameLength)
            {
                parent.Title     = model.Name + ", " + sizeRange;
                inlcudeSizeGroup = false;
            }

            parent.ProductId = "";
            parent.BrandName = brandName;

            parent.ClothingType = "sleepwear"; // = newItemType;

            var images      = new List <string>();
            var swatchImage = "";

            if (model.ImageSet != null)
            {
                images = model.ImageSet.Images
                         .Where(im => im.Category != (int)StyleImageCategories.Swatch)
                         .OrderByDescending(im => ImageHelper.GetSortIndex(im.Category))
                         .ThenByDescending(im => im.IsDefault)
                         .ThenBy(im => im.Id)
                         .Select(im => im.ImageUrl)
                         .ToList();
                swatchImage = model.ImageSet.Images
                              .FirstOrDefault(im => im.Category == (int)StyleImageCategories.Swatch)?.ImageUrl;

                parent.MainImageURL   = images.Count > 0 ? images[0] : "";
                parent.OtherImageUrl1 = images.Count > 1 ? images[1] : "";
                parent.OtherImageUrl2 = images.Count > 2 ? images[2] : "";
                parent.OtherImageUrl3 = images.Count > 3 ? images[3] : "";
                //parent.SwatchImageUrl = swatchImage;
            }

            parent.Color      = "";
            parent.Department = newDepartment;

            parent.Size = "";
            parent.MaterialComposition = materialComposition;
            parent.Description         = model.Description;
            parent.Update        = "Update";
            parent.StandardPrice = "";
            //parent.SuggestedPrice = model.MSRP.ToString("G");
            parent.Currency = "GBP";

            parent.Quantity = "";

            parent.RecommendedBrowseNodes1 = ExcelProductUKViewModel.GetRecommendedBrowseNodes1(newDepartment, firstSize, newItemType);

            parent.SearchTerms1 = searchTerms;

            parent.KeyProductFeatures1 = keyFeatures.Count > 0 ? keyFeatures[0] : "";
            parent.KeyProductFeatures2 = keyFeatures.Count > 1 ? keyFeatures[1] : "";
            parent.KeyProductFeatures3 = keyFeatures.Count > 2 ? keyFeatures[2] : "";
            parent.KeyProductFeatures4 = keyFeatures.Count > 3 ? keyFeatures[3] : "";
            parent.KeyProductFeatures5 = keyFeatures.Count > 4 ? keyFeatures[4] : "";


            parent.Parentage        = "Parent";
            parent.ParentSKU        = "";
            parent.RelationshipType = "";
            parent.VariationTheme   = "Size";

            //--------------------------
            //Child items
            //--------------------------
            foreach (var size in sizes)
            {
                var child = new ExcelProductUKViewModel();
                child.SKU = model.StyleId + "-" + ItemExportHelper.ConvertSizeForStyleId(size.Size, hasKids2);
                if (size.AutoGeneratedBarcode)
                {
                    var newBarcode = BarcodeHelper.GenerateBarcode(barcodeService, child.SKU, when);
                    if (!String.IsNullOrEmpty(newBarcode))
                    {
                        if (size.Barcodes == null)
                        {
                            size.Barcodes = new List <BarcodeDTO>();
                        }
                        size.Barcodes.Insert(0, new BarcodeDTO()
                        {
                            Barcode = newBarcode
                        });
                    }
                }

                child.UPC = (size.Barcodes != null && size.Barcodes.Any()) ? size.Barcodes.FirstOrDefault().Barcode : String.Empty;

                child.Title = model.Name + "," + (inlcudeSizeGroup ? " " + ItemExportHelper.FormatSizeGroupName(size.SizeGroupName) : "") + " Size " + ItemExportHelper.ConvertSizeForItemName(size.Size, hasKids2);

                child.ProductId = "UPC";
                child.BrandName = brandName;

                child.ClothingType = "sleepwear";// newItemType;

                child.MainImageURL   = images.Count > 0 ? images[0] : "";
                child.OtherImageUrl1 = images.Count > 1 ? images[1] : "";
                child.OtherImageUrl2 = images.Count > 2 ? images[2] : "";
                child.OtherImageUrl3 = images.Count > 3 ? images[3] : "";
                //child.SwatchImageUrl = swatchImage;

                child.Color      = ItemExportHelper.PrepareColor(String.IsNullOrEmpty(size.Color) ? color1 : size.Color);
                child.Department = newDepartment;

                child.Size = ExcelProductUKViewModel.SizeConverter(size.Size, material);
                child.MaterialComposition = materialComposition;
                child.Description         = model.Description;
                child.Update        = "Update";
                child.StandardPrice = PriceHelper.Convert(model.Price, gbpExchangeRate, true).ToString("G");
                //child.SuggestedPrice = model.MSRP.ToString("G");
                child.Currency = "GBP";

                child.Quantity = size.Quantity.ToString();

                child.RecommendedBrowseNodes1 = ExcelProductUKViewModel.GetRecommendedBrowseNodes1(newDepartment, child.Size, newItemType);

                child.KeyProductFeatures1 = parent.KeyProductFeatures1;
                child.KeyProductFeatures2 = parent.KeyProductFeatures2;
                child.KeyProductFeatures3 = parent.KeyProductFeatures3;
                child.KeyProductFeatures4 = parent.KeyProductFeatures4;
                child.KeyProductFeatures5 = parent.KeyProductFeatures5;

                child.SearchTerms1 = parent.SearchTerms1;
                //child.SearchTerms2 = parent.SearchTerms2;
                //child.SearchTerms3 = parent.SearchTerms3;
                //child.SearchTerms4 = parent.SearchTerms4;
                //child.SearchTerms5 = parent.SearchTerms5;

                child.Parentage        = "Child";
                child.ParentSKU        = parent.SKU;
                child.RelationshipType = "Variation";
                child.VariationTheme   = "Size";

                childs.Add(child);
            }


            models.Add(parent);
            models.AddRange(childs);

            filename = model.StyleId + "_" + subLicense;
            filename = filename.Replace(" ", "") + "_UK.xls";
            return(models); //ExcelHelper.ExportIntoFile(HttpContext.Current.Server.MapPath(UKTemplatePath), models);
        }
Пример #4
0
        public void UpdateProduct(ParentItemDTO parentItemDto,
                                  IUnitOfWork db,
                                  DateTime when,
                                  long?by)
        {
            var parentItem   = db.ParentItems.Get(parentItemDto.Id);
            var previousASIN = parentItem.ASIN;

            if (parentItem.ASIN != parentItemDto.ASIN)
            {
                parentItem.ASIN = parentItemDto.ASIN;
            }
            parentItem.SKU = parentItemDto.ASIN;

            parentItem.ForceEnableColorVariations = parentItemDto.ForceEnableColorVariations;
            parentItem.OnHold     = parentItemDto.OnHold;
            parentItem.AmazonName = parentItemDto.AmazonName;

            parentItem.UpdateDate = when;
            parentItem.UpdatedBy  = by;

            db.Commit();

            var variationDtoList = parentItemDto.Variations
                                   .Select(v => new ItemDTO()
            {
                ParentASIN = parentItem.ASIN,
                Name       = parentItemDto.AmazonName,

                Id          = v.Id,
                StyleString = v.StyleString,
                StyleId     = v.StyleId,
                StyleItemId = v.StyleItemId,
                Size        = v.Size,
                Color       = v.Color,

                ASIN      = v.SKU,
                IsDefault = v.IsDefault,
                ListingId = v.SKU,

                SKU     = v.SKU,
                Barcode = v.AutoGeneratedBarcode ? BarcodeHelper.GenerateBarcode(_barcodeService, v.SKU, when) : v.Barcode,

                RealQuantity = v.RealQuantity,

                CurrentPrice = v.CurrentPrice,

                PublishedStatus = v.OverridePublishedStatus.HasValue && v.OverridePublishedStatus.Value != v.PublishedStatus ? v.OverridePublishedStatus.Value : (int)PublishedStatuses.None
            }).ToList();

            db.Items.UpdateItemsForParentItem(_itemHistoryService,
                                              "AutoCreateBaseListingService.UpdateProduct",
                                              previousASIN,
                                              parentItem.Market,
                                              parentItem.MarketplaceId,
                                              variationDtoList,
                                              when,
                                              by);

            _cacheService.RequestParentItemIdUpdates(db,
                                                     new List <long>()
            {
                parentItem.Id
            },
                                                     UpdateCacheMode.IncludeChild,
                                                     by);
        }
Пример #5
0
        public long CreateProduct(ParentItemDTO parentItemDto,
                                  IUnitOfWork db,
                                  DateTime when,
                                  long?by)
        {
            var id = 0;

            var parentItem = new ParentItem()
            {
                ASIN          = parentItemDto.ASIN,
                Market        = parentItemDto.Market,
                MarketplaceId = parentItemDto.MarketplaceId,

                ForceEnableColorVariations = parentItemDto.ForceEnableColorVariations,
                OnHold = parentItemDto.OnHold,

                SKU        = parentItemDto.ASIN,
                AmazonName = parentItemDto.AmazonName,

                CreateDate = when,
                CreatedBy  = by
            };

            db.ParentItems.Add(parentItem);
            db.Commit();

            parentItemDto.Id = parentItem.Id;
            id = parentItem.Id;

            var variationDtoList = parentItemDto.Variations
                                   .Select(v => new ItemDTO()
            {
                ParentASIN = parentItem.ASIN,
                Name       = parentItem.AmazonName, //Equal parent name

                StyleString = v.StyleString,
                StyleId     = v.StyleId,
                StyleItemId = v.StyleItemId,
                Size        = v.Size,
                Color       = v.Color,

                ASIN      = v.SKU,
                SKU       = v.SKU,
                IsDefault = v.IsDefault,
                ListingId = v.SKU,

                Barcode = v.AutoGeneratedBarcode ? BarcodeHelper.GenerateBarcode(_barcodeService, v.SKU, when) : v.Barcode,

                CurrentPrice = v.CurrentPrice,
                RealQuantity = 0,

                PublishedStatus = (int)PublishedStatuses.New,
            }).ToList();

            db.Items.UpdateItemsForParentItem(_itemHistoryService,
                                              "AutoCreateBaseListingService.CreateProduct",
                                              parentItem.ASIN,
                                              parentItem.Market,
                                              parentItem.MarketplaceId,
                                              variationDtoList,
                                              when,
                                              by);

            _cacheService.RequestParentItemIdUpdates(db,
                                                     new List <long>()
            {
                parentItem.Id
            },
                                                     UpdateCacheMode.IncludeChild,
                                                     by);

            return(id);
        }
Пример #6
0
        public void Generate_BarcodeFormat_ContainOnlyDigits()
        {
            string barcode = BarcodeHelper.GenerateBarcode();

            Assert.AreEqual(true, IsAllDigits(barcode));
        }
        public static IList <ExcelProductWalmartViewModel> GenerateToExcelWalmart(IUnitOfWork db,
                                                                                  IBarcodeService barcodeService,
                                                                                  StyleViewModel model,
                                                                                  DateTime when,
                                                                                  out string filename)
        {
            var models = new List <ExcelProductWalmartViewModel>();

            var childs = new List <ExcelProductWalmartViewModel>();

            var sizes = model.StyleItems.Items;

            //Size Group, Size Range
            var             hasKids2      = sizes.Any(s => ItemExportHelper.GetSizeGroupByName(s.SizeGroupName, true) == ExportSizeGroup.Kids2);
            ExportSizeGroup?sizeGroup     = sizes.Any() ? (ExportSizeGroup?)ItemExportHelper.GetSizeGroupByName(sizes.Last().SizeGroupName, false) : null;
            var             sizeGroupName = ItemExportHelper.GetSizeGroupName(sizeGroup);
            var             sizeRange     = ItemExportHelper.GetSizeRangeName(sizes.Select(s => s.Size).ToList(), hasKids2);
            var             firstSize     = sizes.Any() ? sizes[0].Size : String.Empty;

            //Features Values
            var features = model.Features.Select(f => new FeatureValueDTO()
            {
                FeatureId = f.FeatureId,
                Value     = f.Value,
            }).ToList();
            var allFeatureValues = db.FeatureValues.GetAllFeatureValueByItemType(1);

            var gender      = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.GENDER);
            var itemStyle   = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.ITEMSTYLE);
            var sleeve      = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SLEEVE);
            var material    = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.MATERIAL);
            var color1      = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.COLOR1);
            var mainLicense = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.MAIN_LICENSE);
            var subLicense  = ItemExportHelper.GetFeatureValue(features, allFeatureValues, StyleFeatureHelper.SUB_LICENSE1);
            //var shippingSize = ItemExportHelper.GetFeatureValue(features, allFeatureValues, Feature.SHIPPING_SIZE);

            //var itemType = ItemExportHelper.GetItemType(itemStyle);

            var brandName = ItemExportHelper.GetBrandName(mainLicense, subLicense);

            //var newItemType = ItemExportHelper.ItemTypeConverter(firstSize ?? "", itemType, itemStyle, gender);
            //var newDepartment = ItemExportHelper.DepartmentConverter(newItemType, gender, firstSize);


            var searchTerms = model.SearchTerms;       // ItemExportHelper.BuildSearchTerms(itemStyle, material, sleeve);
            var keyFeatures = model.GetBulletPoints(); // ItemExportHelper.BuildKeyFeatures(mainLicense, subLicense, material);


            ////--------------------------
            ////Parent item
            ////--------------------------
            //parent.SKU = model.StyleId;
            //parent.ASIN = "";
            //parent.Title = model.Name
            //               + (!String.IsNullOrEmpty(sizeGroupName) ? ", " + ItemExportHelper.FormatSizeGroupName(sizeGroupName) : String.Empty)
            //               + " " + sizeRange;

            //parent.ProductId = "";
            //parent.BrandName = brandName;

            //parent.Type = newItemType;

            //if (model.ImageSet != null)
            //{
            //    parent.MainImageURL = model.ImageSet.Image1Url;
            //    parent.OtherImageUrl1 = model.ImageSet.Image2Url;
            //    parent.OtherImageUrl2 = model.ImageSet.Image3Url;
            //    parent.OtherImageUrl3 = model.ImageSet.Image4Url;
            //}

            //parent.Color = "";// color1;
            //parent.Department = newDepartment;

            //parent.Size = "";
            //parent.Description = model.Description;
            //parent.Update = "Update";
            //parent.StandardPrice = "";
            //parent.SuggestedPrice = model.MSRP.ToString("G");
            //parent.Currency = "USD";

            //parent.Quantity = "";

            //parent.KeyProductFeatures1 = keyFeatures.Count > 0 ? keyFeatures[0] : "";
            //parent.KeyProductFeatures2 = keyFeatures.Count > 1 ? keyFeatures[1] : "";
            //parent.KeyProductFeatures3 = keyFeatures.Count > 2 ? keyFeatures[2] : "";
            //parent.KeyProductFeatures4 = keyFeatures.Count > 3 ? keyFeatures[3] : "";
            //parent.KeyProductFeatures5 = keyFeatures.Count > 4 ? keyFeatures[4] : "";

            //parent.SearchTerms1 = searchTerms;
            ////parent.SearchTerms3 = "";
            ////parent.SearchTerms4 = "";
            ////parent.SearchTerms5 = "";

            //parent.Parentage = "Parent";
            //parent.ParentSKU = "";
            //parent.RelationshipType = "";
            //parent.VariationTheme = "Size";

            //--------------------------
            //Child items
            //--------------------------
            foreach (var size in sizes)
            {
                var child = new ExcelProductWalmartViewModel();
                child.SKU = model.StyleId + "-" + ItemExportHelper.ConvertSizeForStyleId(size.Size, hasKids2);

                if (size.AutoGeneratedBarcode)
                {
                    var newBarcode = BarcodeHelper.GenerateBarcode(barcodeService, child.SKU, when);
                    if (!String.IsNullOrEmpty(newBarcode))
                    {
                        if (size.Barcodes == null)
                        {
                            size.Barcodes = new List <BarcodeDTO>();
                        }
                        size.Barcodes.Insert(0, new BarcodeDTO()
                        {
                            Barcode = newBarcode
                        });
                    }
                }

                child.ProductIdType    = "UPC";
                child.ProductId        = (size.Barcodes != null && size.Barcodes.Any()) ? size.Barcodes.FirstOrDefault().Barcode : String.Empty;
                child.Title            = model.Name + ", " + ItemExportHelper.FormatSizeGroupName(size.SizeGroupName) + " Size " + ItemExportHelper.ConvertSizeForItemName(size.Size, hasKids2);
                child.LongDescription  = String.IsNullOrEmpty(model.Description) ? child.Title : model.Description;
                child.ShortDescription = String.IsNullOrEmpty(model.Description) ? child.Title : model.Description;
                child.ShelfDescription = String.IsNullOrEmpty(model.Description) ? child.Title : model.Description;
                child.Brand            = brandName;

                if (model.ImageSet != null)
                {
                    child.MainImageUrl = model.ImageSet.Image1Url;
                    //child.OtherImageUrl1 = model.ImageSet.Image2Url;
                    //child.OtherImageUrl2 = model.ImageSet.Image3Url;
                    //child.OtherImageUrl3 = model.ImageSet.Image4Url;
                }
                child.MainImageAltText = child.Title;

                child.Color = ItemExportHelper.PrepareColor(String.IsNullOrEmpty(size.Color) ? color1 : size.Color);


                child.ClothingSize  = size.Size;
                child.PriceCurrency = "USD";
                child.PriceAmount   = 99.99M; //TODO: price

                child.MinAdvertisedPriceAmount   = child.PriceAmount;
                child.MinAdvertisedPriceCurrency = child.PriceCurrency;

                child.VariantGroupId        = model.StyleId;
                child.VariantAttributeNames = "ClothingSize"; //TODO: add optional Color

                child.ProductTaxCode = "2038345";

                child.ShippingWeightValue = size.Weight.ToString();
                child.ShippingWeightUnit  = "OZ";

                childs.Add(child);
            }

            models.AddRange(childs);

            filename = model.StyleId + "_" + subLicense;
            filename = filename.Replace(" ", "") + "_Walmart" + Path.GetExtension(TemplatePath);

            return(models);
        }