Exemplo n.º 1
0
 public StoreItem()
 {
     Photos = new List<PhotoItem>();
     Store = new Store();
     Category = new StoreCategory();
     Colors = new List<ColorDisplay>();
     Reviews = new List<ItemReview>();
 }
Exemplo n.º 2
0
        public Classes.Store GetStore(Guid? merchantId, bool isRdn = false)
        {
            var store = new Classes.Store();
            try
            {
                if (!merchantId.HasValue && !isRdn)
                    throw new Exception("Invalid merchant id. (CreateNewShoppingCart in StoreGateway");

                var mc = new ManagementContext();
                Merchant merchant = null;
                if (merchantId.HasValue) // ToDo: When Store is updated, updated the references here to include more tables
                    merchant = mc.Merchants.Include("Items").FirstOrDefault(x => x.MerchantId.Equals(merchantId.Value));
                else
                    merchant = mc.Merchants.Include("Items").FirstOrDefault(x => x.IsRDNation.Equals(true));
                if (merchant == null)
                    return null;

                store.Name = merchant.ShopName;
                store.MerchantId = merchant.MerchantId;
                store.InternalId = merchant.InternalReference;
                foreach (var storeItem in merchant.Items)
                {
                    var item = new Classes.StoreItemDisplay();
                    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.IsPublished = storeItem.IsPublished;
                    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;
                    }
                    store.StoreItems.Add(item);
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return store;
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
0
        public static Classes.Store GetStoreIdsFromInternalId(Guid ownerId)
        {
            var store = new Classes.Store();
            try
            {
                var mc = new ManagementContext();
                var merchant = mc.Merchants.FirstOrDefault(x => x.InternalReference == ownerId);

                if (merchant != null)
                {
                    store.MerchantId = merchant.MerchantId;
                    store.PrivateManagerId = merchant.PrivateManagerId;
                    store.InternalId = merchant.InternalReference;
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return store;
        }
 public StoreItemDisplay()
 {
     Merchant = new Store();
     Colors = new List<ColorDisplay>();
 }