Beispiel #1
0
        private static void ItemPostProcessing(FBAPickListItemViewModel item,
                                               IList <StyleLocationDTO> locations,
                                               IList <SoldSizeInfo> remainingQtyes,
                                               IList <StyleFeatureValueDTO> stylesValues)
        {
            if (item.StyleId != null)
            {
                //Set Locations
                item.Locations = ComposeLocations(locations, item.StyleId.Value);

                //Set Remaining Quantity from inventory
                foreach (var size in item.AllSizes)
                {
                    var soldSize     = item.SoldSizes.FirstOrDefault(s => s.StyleItemId == size.StyleItemId);
                    var remainingQty = remainingQtyes.FirstOrDefault(r => r.StyleItemId == size.StyleItemId);
                    if (remainingQty != null)
                    {
                        size.Quantity = Math.Max(0, (remainingQty.TotalQuantity ?? 0) - (soldSize != null ? soldSize.Quantity : 0));
                    }
                }

                item.SoldQuantity = item.SoldSizes.Sum(s => s.Quantity);
            }

            //Sort sizes
            item.SoldSizes = item.SoldSizes.OrderBy(s => s.SizeIndex).ThenBy(s => s.StyleSize).ThenBy(s => s.Color).ToList();
            item.AllSizes  = item.AllSizes.OrderBy(s => s.SizeIndex).ThenBy(s => s.StyleSize).ThenBy(s => s.Color).ToList();

            //Fill quantity
            foreach (var size in item.AllSizes)
            {
                var soldItem = item.SoldSizes.FirstOrDefault(i => i.StyleItemId == size.StyleItemId);
                size.OrderedQuantity = soldItem != null ? soldItem.Quantity : 0;
            }


            //Fill feature fields
            StyleFeatureValueDTO mainLicenseValue = null;
            StyleFeatureValueDTO subLicenseValue  = null;
            StyleFeatureValueDTO genderValue      = null;

            if (item.StyleId != null)
            {
                genderValue      = stylesValues.FirstOrDefault(v => v.StyleId == item.StyleId && v.FeatureId == StyleFeatureHelper.GENDER);
                mainLicenseValue = stylesValues.FirstOrDefault(v => v.StyleId == item.StyleId && v.FeatureId == StyleFeatureHelper.MAIN_LICENSE);
                subLicenseValue  = stylesValues.FirstOrDefault(v => v.StyleId == item.StyleId && v.FeatureId == StyleFeatureHelper.SUB_LICENSE1);
            }
            item.Gender      = genderValue != null ? genderValue.Value : "";
            item.MainLicense = mainLicenseValue != null ? mainLicenseValue.Value : null;
            item.SubLicense1 = subLicenseValue != null ? subLicenseValue.Value : null;


            //Keep only sold items for record w/o styles
            if (String.IsNullOrEmpty(item.StyleString))
            {
                item.AllSizes = item.AllSizes.Where(s => item.SoldSizes.Any(ss => ss.StyleSize == s.StyleSize)).ToList();
                //Replace null value
                item.StyleString = item.StyleString ?? "-";
            }
        }
Beispiel #2
0
        private static FBAPickListItemViewModel ComposeNewGroup(ListingOrderDTO item,
                                                                bool hasColorVariation,
                                                                Style style,
                                                                IList <StyleItemDTO> styleItems)
        {
            //Add new group
            IList <PickListSizeInfo> allSizes = new List <PickListSizeInfo>();

            //Prepare image
            var image = item.ItemPicture;

            if (String.IsNullOrEmpty(image))
            {
                image = item.StyleImage;
            }

            var title = item.Title;

            if (item.SourceStyleString != item.StyleID)        //NOTE: happens when item has linked style OR item style was changed
            {
                if (!String.IsNullOrEmpty(item.StyleImage))
                {
                    image = item.StyleImage;
                }

                if (style != null && !String.IsNullOrEmpty(style.Name))
                {
                    title = style.Name;
                }
            }

            title = SizeHelper.ExcludeSizeInfo(title);

            if (style != null)
            {
                allSizes = styleItems.Where(i => i.StyleId == style.Id)
                           .Select(i => new PickListSizeInfo()
                {
                    StyleSize   = i.Size,
                    StyleItemId = i.StyleItemId,
                    Weight      = i.Weight
                }).ToList();
            }

            var itemPrice = item.ItemPrice;

            if (item.Market == (int)MarketType.Amazon ||
                item.Market == (int)MarketType.AmazonEU ||
                item.Market == (int)MarketType.AmazonAU)
            {
                itemPrice = item.QuantityOrdered != 0 ? item.ItemPrice / item.QuantityOrdered : 0;
            }

            var newGroup = new FBAPickListItemViewModel
            {
                StyleName         = style != null ? style.Name : null,
                StyleId           = style != null ? (long?)style.Id : null,
                Color             = item.Color,
                StyleString       = style != null ? style.StyleID : null,
                ProductName       = title,
                Picture           = image,
                HasColorVariation = hasColorVariation,

                ListingInfoes = new List <ListingInfo>()
                {
                    new ListingInfo()
                    {
                        ASIN           = item.ASIN,
                        ParentASIN     = item.ParentASIN,
                        SourceMarketId = item.SourceMarketId,
                        MarketplaceId  = item.MarketplaceId,
                        Market         = item.Market,
                        Quantity       = item.QuantityOrdered,
                        Rank           = item.Rank,
                    }
                },

                SoldSizes = new List <PickListSizeInfo>
                {
                    new PickListSizeInfo
                    {
                        Quantity = item.QuantityOrdered,
                        Sizes    = new List <string>()
                        {
                            item.Size
                        },
                        StyleSize   = item.StyleSize,
                        StyleItemId = item.StyleItemId,
                        Color       = item.Color,
                        Weight      = item.Weight,
                        Prices      = new List <PriceInfo>()
                        {
                            new PriceInfo()
                            {
                                Price    = itemPrice,
                                Currency = PriceHelper.GetCurrencySymbol((MarketType)item.Market, item.MarketplaceId)
                            }
                        }
                    }
                },
                AllSizes = allSizes,
            };

            return(newGroup);
        }
Beispiel #3
0
        private static void UpdateExistGroup(FBAPickListItemViewModel existGroup,
                                             bool hasColorVariation,
                                             ListingOrderDTO item)
        {
            //This group always has appropriate color, only check size
            PickListSizeInfo existSize = null;

            if (hasColorVariation)
            {
                existSize = existGroup.SoldSizes.FirstOrDefault(s => s.StyleSize == item.StyleSize && s.Color == item.Color);
            }
            else
            {
                existSize = existGroup.SoldSizes.FirstOrDefault(s => s.StyleSize == item.StyleSize);
            }

            var currency  = PriceHelper.GetCurrencySymbol((MarketType)item.Market, item.MarketplaceId);
            var itemPrice = item.ItemPrice;

            if (item.Market == (int)MarketType.Amazon ||
                item.Market == (int)MarketType.AmazonEU ||
                item.Market == (int)MarketType.AmazonAU)
            {
                itemPrice = item.QuantityOrdered != 0 ? item.ItemPrice / item.QuantityOrdered : 0;
            }

            if (existSize != null)
            {
                existSize.Quantity += item.QuantityOrdered;

                if (!existSize.Prices.Any(p => p.Currency == currency && Math.Abs(p.Price - itemPrice) <= 0.1M))
                {
                    existSize.Prices.Add(new PriceInfo()
                    {
                        Price    = itemPrice,
                        Currency = currency
                    });
                }

                if (existSize.Sizes.All(s => s != item.Size))
                {
                    existSize.Sizes.Add(item.Size);
                }
            }
            else
            {
                existGroup.SoldSizes.Add(new PickListSizeInfo
                {
                    Quantity = item.QuantityOrdered,
                    Sizes    = new List <string>()
                    {
                        item.Size
                    },
                    StyleSize   = item.StyleSize,
                    StyleItemId = item.StyleItemId,
                    Color       = item.Color,
                    Weight      = item.Weight,
                    Prices      = new List <PriceInfo>()
                    {
                        new PriceInfo()
                        {
                            Price    = itemPrice,
                            Currency = currency,
                        }
                    }
                });
            }

            var existListing = existGroup.ListingInfoes.FirstOrDefault(l => l.ASIN == item.ASIN &&
                                                                       l.Market == item.Market &&
                                                                       l.MarketplaceId == item.MarketplaceId);

            if (existListing == null)
            {
                existGroup.ListingInfoes.Add(new ListingInfo()
                {
                    ASIN           = item.ASIN,
                    ParentASIN     = item.ParentASIN,
                    SourceMarketId = item.SourceMarketId,
                    MarketplaceId  = item.MarketplaceId,
                    Market         = item.Market,
                    Quantity       = item.QuantityOrdered,
                    Rank           = item.Rank,
                });
            }
            else
            {
                existListing.Quantity += item.QuantityOrdered;
            }
        }