Пример #1
0
        public StoreShoppingCart GetShoppingCart(Guid cartId)
        {
            var output = new StoreShoppingCart();
            try
            {
                var mc = new ManagementContext();
                DateTime now = DateTime.Now;
                var cart = mc.ShoppingCarts.Include("Items").Include("Items.StoreItem").Include("Items.StoreItem.Colors").Include("Items.StoreItem.Colors.Color").Include("Items.StoreItem.Merchant").FirstOrDefault(x => x.ShoppingCartId.Equals(cartId));
                if (cart == null) return output;

                output.ShoppingCartId = cart.ShoppingCartId;
                output.Ip = cart.Ip;

                foreach (var shoppingCartItem in cart.Items)
                {
                    output.ItemsCount += 1;
                    var item = new StoreItemDisplay();
                    item.Merchant.MerchantId = shoppingCartItem.StoreItem.Merchant.MerchantId;
                    item.Merchant.Name = shoppingCartItem.StoreItem.Merchant.ShopName;
                    item.Merchant.TaxRate = shoppingCartItem.StoreItem.Merchant.TaxRate;
                    if (shoppingCartItem.StoreItem.Merchant.CurrencyRate == null)
                    {
                        item.Merchant.Currency = "USD";
                        item.Merchant.CurrencyCost = 1;
                    }
                    else
                    {
                        item.Merchant.Currency = shoppingCartItem.StoreItem.Merchant.CurrencyRate.CurrencyAbbrName;
                        item.Merchant.CurrencyCost = shoppingCartItem.StoreItem.Merchant.CurrencyRate.CurrencyExchangePerUSD;
                    }
                    item.Name = shoppingCartItem.StoreItem.Name;
                    item.BasePrice = shoppingCartItem.StoreItem.Price;
                    item.Price = (shoppingCartItem.StoreItem.Price * shoppingCartItem.Quantity);
                    var color = DisplayStoreItemColor(shoppingCartItem.StoreItem.Colors.Where(x => x.Color.ColorIdCSharp == shoppingCartItem.Color).FirstOrDefault());
                    if (color != null)
                    {
                        item.Colors.Add(color);
                        item.ColorAGB = color.CSharpColor;
                        item.ColorHex = color.HexColor;
                    }
                    item.QuantityOrdered = shoppingCartItem.Quantity;
                    item.Weight = (shoppingCartItem.StoreItem.Weight * shoppingCartItem.Quantity);
                    item.ShoppingCartItemId = shoppingCartItem.ShoppingCartItemId;
                    item.ArticleNumber = shoppingCartItem.StoreItem.ArticleNumber;
                    if (shoppingCartItem.StoreItem.Merchant.CurrencyRate == null)
                    {
                        item.Currency = "USD";
                        item.CurrencyCost = 1;
                    }
                    else
                    {
                        item.Currency = shoppingCartItem.StoreItem.Merchant.CurrencyRate.CurrencyAbbrName;
                        item.CurrencyCost = shoppingCartItem.StoreItem.Merchant.CurrencyRate.CurrencyExchangePerUSD;
                    }
                    item.Description = shoppingCartItem.StoreItem.Description;
                    item.WillPickUpLocally = shoppingCartItem.WillPickUpLocally;
                    if (!shoppingCartItem.WillPickUpLocally)
                    {
                        item.Shipping = shoppingCartItem.StoreItem.ShippingCosts;
                        //if there are more than one of the same items being shipped, then we add on the additional fees.
                        if (shoppingCartItem.Quantity > 1)
                            item.Shipping += shoppingCartItem.StoreItem.ShippingCostsAdditional * (shoppingCartItem.Quantity - 1);
                    }
                    else
                        item.Shipping = 0;
                    item.CanRunOutOfStock = shoppingCartItem.StoreItem.CanRunOutOfStock;
                    item.StoreItemId = shoppingCartItem.StoreItem.StoreItemId;
                    item.Note = shoppingCartItem.StoreItem.Note;
                    item.BaseTaxOnItem = Math.Round((item.BasePrice * Convert.ToDecimal(shoppingCartItem.StoreItem.Merchant.TaxRate)), 2);
                    item.TotalTaxOnItem = (item.BaseTaxOnItem * shoppingCartItem.Quantity);
                    item.PriceInclTax = Math.Round((item.Price + item.TotalTaxOnItem), 2);
                    item.ItemType = (StoreItemTypeEnum)Enum.Parse(typeof(StoreItemTypeEnum), shoppingCartItem.StoreItem.ItemTypeEnum.ToString());
                    if (item.ItemType == StoreItemTypeEnum.Shirt)
                    {
                        item.ItemSize = (StoreItemShirtSizesEnum)Enum.Parse(typeof(StoreItemShirtSizesEnum), shoppingCartItem.Size.ToString());
                        item.ItemSizeEnum = shoppingCartItem.Size;
                    }
                    foreach (var photo in shoppingCartItem.StoreItem.Photos)
                    {
                        PhotoItem p = new PhotoItem(photo.ItemPhotoId, photo.ImageUrl, photo.ImageUrlThumb, photo.IsPrimaryPhoto, photo.AlternativeText);
                        item.Photos.Add(p);
                    }
                    var store = output.Stores.Where(x => x.MerchantId == item.Merchant.MerchantId).FirstOrDefault();
                    if (store != null)
                    {
                        store.TotalPrice += item.Price;
                        store.TotalShipping += item.Shipping;
                        store.TotalAfterShipping += item.Price + item.Shipping;
                        store.StoreItems.Add(item);
                    }
                    else
                    {
                        Store.Classes.Store s = new Classes.Store();
                        s.MerchantId = item.Merchant.MerchantId;
                        s.Currency = item.Merchant.Currency;
                        s.StripePublishableKey = item.Merchant.StripePublishableKey;
                        s.Name = item.Merchant.Name;
                        s.TotalPrice = item.Price;
                        s.TotalShipping = item.Shipping;
                        s.TotalAfterShipping = item.Price + item.Shipping;
                        s.StoreItems.Add(item);
                        output.Stores.Add(s);
                    }
                }
                cart.Expires = DateTime.Now.AddDays(1);
                mc.SaveChanges();
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return output;
        }
Пример #2
0
        public Classes.StoreItemDisplay GetStoreItemManager(Guid merchantId, Guid privateManagerId, int itemId)
        {
            var item = new Classes.StoreItemDisplay();
            try
            {
                var mc = new ManagementContext();
                var storeItem = mc.StoreItems.Include("Colors").Include("Colors.Color").Include("Photos").Where(x => x.StoreItemId == itemId).Where(x => x.Merchant.MerchantId == merchantId).Where(x => x.Merchant.PrivateManagerId == privateManagerId).FirstOrDefault();
                if (storeItem == null)
                    return item;

                item.CanPickUpLocally = storeItem.CanPickUpLocally;
                item.Name = storeItem.Merchant.ShopName;
                item.MerchantId = storeItem.Merchant.MerchantId;
                item.InternalId = storeItem.Merchant.InternalReference;
                item.PrivateManagerId = storeItem.Merchant.PrivateManagerId;
                item.ArticleNumber = storeItem.ArticleNumber;
                item.CanRunOutOfStock = storeItem.CanRunOutOfStock;
                if (storeItem.Merchant.CurrencyRate == null)
                {
                    item.Currency = "USD";
                    item.CurrencyCost = 1;
                }
                else
                {
                    item.Currency = storeItem.Merchant.CurrencyRate.CurrencyAbbrName;
                    item.CurrencyCost = storeItem.Merchant.CurrencyRate.CurrencyExchangePerUSD;
                }
                item.Description = storeItem.Description;
                item.Name = storeItem.Name;
                item.Price = storeItem.Price;
                item.QuantityInStock = storeItem.QuantityInStock;
                item.StoreItemId = storeItem.StoreItemId;
                item.Weight = storeItem.Weight;
                item.Note = storeItem.Note;
                item.Shipping = storeItem.ShippingCosts;
                item.ShippingAdditional = storeItem.ShippingCostsAdditional;
                item.IsPublished = storeItem.IsPublished;
                item.ItemTypeEnum = storeItem.ItemTypeEnum;
                item.ItemType = (StoreItemTypeEnum)Enum.Parse(typeof(StoreItemTypeEnum), storeItem.ItemTypeEnum.ToString());
                if (item.ItemType == StoreItemTypeEnum.Shirt)
                {
                    item.ItemSizeEnum = storeItem.SizesEnum;
                    item.ItemSize = (StoreItemShirtSizesEnum)Enum.Parse(typeof(StoreItemShirtSizesEnum), storeItem.SizesEnum.ToString());
                }
                DisplayStoreItemColors(storeItem, item);

                foreach (var photo in storeItem.Photos)
                {
                    PhotoItem p = new PhotoItem(photo.ItemPhotoId, photo.ImageUrl, photo.ImageUrlThumb, photo.IsPrimaryPhoto, photo.AlternativeText);
                    item.Photos.Add(p);
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return item;
        }
Пример #3
0
        private static StoreItem DisplayStoreItem(DataModels.Store.StoreItem storeItem, bool getAllReviews = false)
        {
            try
            {
                var item = new Classes.StoreItem();
                item.CanPickUpLocally = storeItem.CanPickUpLocally;
                item.ArticleNumber = storeItem.ArticleNumber;
                item.CanRunOutOfStock = storeItem.CanRunOutOfStock;
                if (storeItem.Merchant.CurrencyRate == null)
                {
                    item.Currency = "USD";
                    item.CurrencyCost = 1;
                }
                else
                {
                    item.Currency = storeItem.Merchant.CurrencyRate.CurrencyAbbrName;
                    item.CurrencyCost = storeItem.Merchant.CurrencyRate.CurrencyExchangePerUSD;
                }
                if (getAllReviews)
                {
                    foreach (var b in storeItem.Reviews)
                    {
                        item.Reviews.Add(ItemReview.DisplayReviewList(b));
                    }
                }
                item.Description = storeItem.Description;
                item.Shipping = storeItem.ShippingCosts;
                item.ShippingAdditional = storeItem.ShippingCostsAdditional;
                item.Name = storeItem.Name;
                if (item.Name.Length > 21)
                    item.NameTrimmed = item.Name.Remove(21) + "...";
                else
                    item.NameTrimmed = item.Name;

                item.Price = storeItem.Price;
                item.QuantityInStock = storeItem.QuantityInStock;
                item.StoreItemId = storeItem.StoreItemId;
                item.Weight = storeItem.Weight;

                if (storeItem.LastModified > new DateTime(2013, 11, 23) || storeItem.Created > new DateTime(2013, 11, 23))
                {
                    item.NoteHtml = storeItem.Note;
                }
                else if (storeItem.Created < new DateTime(2013, 11, 23))
                {
                    RDN.Library.Util.MarkdownSharp.Markdown markdown = new RDN.Library.Util.MarkdownSharp.Markdown();
                    markdown.AutoHyperlink = true;
                    markdown.LinkEmails = true;
                    item.NoteHtml = HtmlSanitize.FilterHtmlToWhitelist(markdown.Transform(storeItem.Note)).Replace("</p>", "</p><br/>");
                }

                item.Note = storeItem.Note;
                item.IsPublished = storeItem.IsPublished;
                item.Store.MerchantId = storeItem.Merchant.MerchantId;
                item.AcceptsPayPal = storeItem.Merchant.AcceptPaymentsViaPaypal;
                item.AcceptsStripe = storeItem.Merchant.AcceptPaymentsViaStripe;
                item.Views = storeItem.Views.ToString("N0");

                if (storeItem.Category != null)
                {
                    item.Category.Name = storeItem.Category.Name;
                    item.Category.StoreItemCategoryId = storeItem.Category.StoreItemCategoryId;
                }
                item.Store.Name = storeItem.Merchant.ShopName;

                if (!String.IsNullOrEmpty(storeItem.Merchant.ShopName) && storeItem.Merchant.ShopName.Length > 15)
                    item.Store.NameTrimmed = storeItem.Merchant.ShopName.Remove(15) + "...";
                else
                    item.Store.NameTrimmed = storeItem.Merchant.ShopName;
                item.Store.Description = storeItem.Merchant.Description;
                item.Store.MerchantId = storeItem.Merchant.MerchantId;
                item.ItemType = (StoreItemTypeEnum)Enum.Parse(typeof(StoreItemTypeEnum), storeItem.ItemTypeEnum.ToString());
                if (item.ItemType == StoreItemTypeEnum.Shirt)
                {
                    item.ItemSize = (StoreItemShirtSizesEnum)Enum.Parse(typeof(StoreItemShirtSizesEnum), storeItem.SizesEnum.ToString());
                    item.ItemSizeEnum = storeItem.SizesEnum;
                }

                foreach (var photo in storeItem.Photos)
                {
                    PhotoItem p = new PhotoItem(photo.ItemPhotoId, photo.ImageUrl, photo.ImageUrlThumb, photo.IsPrimaryPhoto, photo.AlternativeText);
                    item.Photos.Add(p);
                }
                DisplayStoreItemColors(storeItem, item);

                return item;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return null;
        }