public bool InsertOrderDetail(int orderId, int userId)
 {
     var shoppingCartDetails = new ShoppingCartService().GetShoppingCartDetail(userId);
     var orderDetails = new List<OrderDetail>();
     foreach (var item in shoppingCartDetails)
     {
         orderDetails.Add(new OrderDetail()
         {
             Price = item.Price,
             Quantity = item.Quantity,
             OrderId = orderId,
             ProductId = item.ProductId,
             Title = item.Title,
             Author = item.Author,
             Image = item.Image,
             Detail = item.Detail,
             Isbn = item.Isbn,
             CategoryName = item.CategoryName
             });
     }
     var orderDetailRepository = new OrderDetailRepository();
     return orderDetailRepository.InsertOrderDetail(orderDetails, orderId);
 }
        public void ProcessItems(ShoppingCartOverviewModel model, User user)
        {
            //discounts

            if (model.Items.Count > 0)
            {
                var userdata = ShoppingCartService.GetCheckoutData();
                System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();



                var  discounts = LS.Get <Discount>(model.ShopID.ToString() + "_" + DiscountType.ForCartItem.ToString()); // search discounts for shop and type
                bool success   = false;
                foreach (var curdiscount in discounts)
                {
                    #region process discount for cart items
                    bool breakmain = false;
                    if (curdiscount.IsCodeRequired)
                    {
                        if (string.IsNullOrEmpty(userdata.CouponCode) || userdata.CouponCode != curdiscount.DiscountCode)
                        {
                            continue; // code doesn`t match
                        }
                    }
                    if (!DiscountService.ExpiriedCheck(curdiscount))
                    {
                        continue;
                    }
                    int curUsesNumber = GetCurrentLimitPosition(curdiscount, user, _UseCache, userdata.FullName, userdata.Phone, userdata.Address, user.Email);
                    if (LimitCheck(curUsesNumber, curdiscount.Limit, curdiscount.LimitType))
                    {
                        success = true;
                        foreach (var d in GetRules().Where(x =>
                                                           // x.Value.Type == DiscountType.ForCartItem &&
                                                           curdiscount.RuleList.Select(y => y.Name).Contains(x.Key)
                                                           ))
                        {
                            var confitem = d.Value.GetConfigItem();

                            int i = 0;
                            foreach (var r in curdiscount.RuleList.Where(x => x.Name == d.Key))
                            {
                                i++;

                                //from cache :)
                                var o = curdiscount.GetRuleConfigObject(i.ToString() + r.Name, () =>
                                {
                                    return(js.Deserialize(r.Value, confitem.GetType()));
                                });


                                success = success && d.Value.Process(model, curdiscount, o, user, curUsesNumber);
                            }
                        }
                        if (success)
                        {
                            var productsList = curdiscount.GetProductsList();
                            if (curdiscount.IsCodeRequired && curdiscount.DiscountCode == userdata.CouponCode)
                            {
                                model.DiscountByCouponeCodeText = curdiscount.Name;
                            }
                            foreach (var item in model.Items.Where(x => productsList.Contains(x.ProductShopID.ToString())))
                            {
                                if (!DiscountService.LimitCheck(curUsesNumber, curdiscount.Limit, curdiscount.LimitType))
                                {
                                    break;
                                }
                                if (item.Price > 0 && item.TotalDiscountAmount < item.Price * item.Quantity)//only if actual
                                {
                                    if (curdiscount.DiscountCartItemType == DiscountCartItemType.ForItemPrice)
                                    {
                                        if (curdiscount.IsPercent)
                                        {
                                            item.Price = item.Price - (item.Price * curdiscount.Percent / 100);
                                        }
                                        else
                                        {
                                            item.Price = item.Price - curdiscount.Amount;
                                        }
                                        if (item.Price < 0)
                                        {
                                            item.Price = 0;
                                        }
                                    }
                                    else
                                    {
                                        if (curdiscount.IsPercent)
                                        {
                                            item.TotalDiscountAmount = item.Price * curdiscount.Percent * item.Quantity / 100;
                                        }
                                        else
                                        {
                                            item.TotalDiscountAmount = curdiscount.Amount;
                                        }
                                    }
                                    if (!string.IsNullOrEmpty(item.DiscountDescription))
                                    {
                                        item.DiscountDescription += ", " + curdiscount.Name;
                                    }
                                    else
                                    {
                                        item.DiscountDescription = curdiscount.Name;
                                    }
                                    item.DiscountIDs.Add(curdiscount.ID);
                                    if (curdiscount.LessShopFee)
                                    {
                                        model.IsLessMemberFee = true;
                                    }
                                    curUsesNumber++;
                                }
                            }

                            if (curdiscount.PreventNext)
                            {
                                breakmain = true;
                            }
                        }

                        if (breakmain)
                        {
                            break;
                        }
                    }
                    #endregion
                }
            }
        }
Exemple #3
0
 public RentController(IStoreService storeService, ApplicationState applicationState, ShoppingCartService shoppingCartService, UserManager <Customer> userManager)
     : base(storeService, applicationState)
 {
     this.shoppingCartService = shoppingCartService;
     this.userManager         = userManager;
 }
Exemple #4
0
 public OrderModel(JsonOrderRepository repoService, ShoppingCartService cartService)
 {
     repository = repoService;
     cart       = cartService;
 }
        public ActionResult _ChangeShopPopup(int shopID)
        {
            var data     = new List <ShoppingCartOverviewModel>();
            var curdate  = DateTime.Now.Date;
            var lastdate = curdate.AddDays(7);
            var culture  = new System.Globalization.CultureInfo("he-IL");

            ViewBag.CurrentShopID = shopID;
            var curShop      = ShoppingService.GetShopByID(shopID);
            var curShopModel = new ShoppingCartOverviewModel();

            curShopModel.Items    = _shoppingCartService.GetShoppingCartItems(shopID, true);
            curShopModel.ShopID   = shopID;
            curShopModel.Shop     = curShop;
            curShopModel.Total    = curShopModel.Items.Count > 0 ? curShopModel.Items.Sum(x => x.UnitPrice) : 0;
            curShopModel.TotalStr = ShoppingService.FormatPrice(curShopModel.Total);
            curShopModel.Count    = curShopModel.Items.Count;
            //work times
            curShopModel.WorkTimes = _db.ShopWorkTimes.Where(x => x.ShopID == shopID && x.Active &&
                                                             (!x.IsSpecial || (x.Date >= curdate && x.Date <= lastdate))
                                                             ).OrderBy(x => x.IsSpecial).ThenBy(x => x.Day).ThenBy(x => x.Date)
                                     .Select(x => new ShipTimeModel()
            {
                Date        = x.Date,
                Day         = x.Day,
                TimeFromInt = x.TimeFrom,
                TimeToInt   = x.TimeTo,
                IsSpecial   = x.IsSpecial,
            })
                                     .ToList();
            foreach (var t in curShopModel.WorkTimes)
            {
                t.DayStr       = culture.DateTimeFormat.GetDayName(t.Day);
                t.TimeFromeStr = TimeSpan.FromMinutes(t.TimeFromInt).ToString("hh':'mm");
                t.TimeToStr    = TimeSpan.FromMinutes(t.TimeToInt).ToString("hh':'mm");
                t.DateStr      = t.Date.ToString("dd/MM");
            }
            data.Add(curShopModel);
            //missing products


            // find by address
            decimal longitude = 0;
            decimal latitude  = 0;

            if (LS.isLogined())
            {
                if (LS.CurrentUser.Latitude != 0)
                {
                    latitude = LS.CurrentUser.Latitude;
                }
                if (LS.CurrentUser.Longitude != 0)
                {
                    longitude = LS.CurrentUser.Longitude;
                }
            }


            //if not regognized
            if (longitude == 0)
            {
                if (Session["longitude"] != null)
                {
                    longitude = (decimal)Session["longitude"];
                }
            }
            if (latitude == 0)
            {
                if (Session["latitude"] != null)
                {
                    latitude = (decimal)Session["latitude"];
                }
            }
            string address = "";

            if (Session["address"] != null)
            {
                address = (string)Session["address"];
            }
            var shops = new List <Shop>();

            if (latitude == 0 || longitude == 0)
            {
                shops = ShoppingService.GetNearestShop(0, latitude, longitude, address, true).ToList();
            }
            else
            {
                shops = ShoppingService.GetNearestShop(0, latitude, longitude, address).ToList();
            }
            string[] ids = new string[] { };
            if (!string.IsNullOrEmpty(curShop.ShopTypeIDs))
            {
                ids = curShop.ShopTypeIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            }
            Expression <Func <Shop, bool> > predicate = null;

            foreach (var s in ids)
            {
                if (predicate != null)
                {
                    predicate = predicate.MultiSearchOr(x => x.ShopTypeIDs != null &&
                                                        (x.ShopTypeIDs.Contains("," + s + ",") ||
                                                         x.ShopTypeIDs == s ||
                                                         x.ShopTypeIDs.StartsWith(s + ",") ||
                                                         x.ShopTypeIDs.EndsWith("," + s)
                                                        )
                                                        );
                }
                else
                {
                    predicate = x => x.ShopTypeIDs != null && (x.ShopTypeIDs.Contains("," + s + ",") ||
                                                               x.ShopTypeIDs == s ||
                                                               x.ShopTypeIDs.StartsWith(s + ",") ||
                                                               x.ShopTypeIDs.EndsWith("," + s)
                                                               );
                }
            }
            if (predicate != null)
            {
                shops = shops.Where(predicate.Compile()).ToList();
            }

            foreach (var shop in shops)
            {
                if (shop.ID != curShopModel.ShopID)
                {
                    var model = new ShoppingCartOverviewModel();
                    // model.Items = ShoppingCartService.GetShoppingCartItems(shop.ID, true);
                    model.Items  = ShoppingCartService.GetShoppingCartItemsByList(shop.ID, curShopModel.Items);
                    model.ShopID = shop.ID;
                    model.Shop   = shop;
                    var items = model.Items.Where(x => !x.IsNotAvaliable &&
                                                  !x.SelectedAttributeNotAvaliable &&
                                                  !x.IsHaveNotQuantity).ToList();
                    model.NotAvaliableItems = model.Items.Where(x => x.IsNotAvaliable ||
                                                                x.SelectedAttributeNotAvaliable ||
                                                                x.IsHaveNotQuantity).ToList();
                    model.Total    = items.Count > 0 ? items.Sum(x => x.UnitPrice) : 0;
                    model.TotalStr = ShoppingService.FormatPrice(model.Total);
                    model.Count    = model.Items.Count;
                    //work times

                    model.WorkTimes = _db.ShopWorkTimes.Where(x => x.ShopID == shopID && x.Active &&
                                                              (!x.IsSpecial || (x.Date >= curdate && x.Date <= lastdate))
                                                              ).OrderBy(x => x.IsSpecial).ThenBy(x => x.Day).ThenBy(x => x.Date)
                                      .Select(x => new ShipTimeModel()
                    {
                        Date        = x.Date,
                        Day         = x.Day,
                        TimeFromInt = x.TimeFrom,
                        TimeToInt   = x.TimeTo,
                        IsSpecial   = x.IsSpecial,
                    })
                                      .ToList();
                    foreach (var t in model.WorkTimes)
                    {
                        t.DayStr       = culture.DateTimeFormat.GetDayName(t.Day);
                        t.TimeFromeStr = TimeSpan.FromMinutes(t.TimeFromInt).ToString("hh':'mm");
                        t.TimeToStr    = TimeSpan.FromMinutes(t.TimeToInt).ToString("hh':'mm");
                        t.DateStr      = t.Date.ToString("dd/MM");
                    }

                    data.Add(model);
                }
            }

            if (!string.IsNullOrEmpty(curShop.Theme))
            {
                this.HttpContext.Items["ShopTheme"] = curShop.Theme;
            }

            return(PartialView(data));
        }
 public ShoppingCartSummary(ShoppingCartService shoppingCart)
 {
     _shoppingCart = shoppingCart;
 }
 public OrderRepository(AppDbContext appDbContext, ShoppingCartService shoppingCartService)
 {
     _appDbContext        = appDbContext;
     _shoppingCartService = shoppingCartService;
 }
 public ShoppingCartController(ShoppingCartService cartService)
 {
     _cartService = cartService;
 }
 public AccountController()
 {
     db              = new KAIROS_SHOPEntities();
     accountService  = new AccountService(db);
     shoppingService = new ShoppingCartService(db);
 }
 public ShoppingCartsController(ShoppingCartService shoppingcartService, BookService bookService)
 {
     _shoppingcartService = shoppingcartService;
     _bookService         = bookService;
 }
Exemple #11
0
 public PartialViewResult Summary(ShoppingCartService cart)
 {
     return(PartialView(cart));
 }
Exemple #12
0
 public ViewResult Index(ShoppingCartService cart, string returnUrl)
 {
     return(View(new CartIndexViewModel {
         ReturnUrl = returnUrl, Cart = cart
     }));
 }
Exemple #13
0
    private Order DoCreateOrder()
    {
        var shoppingCart = ShoppingCartService.CurrentShoppingCart;

        if (shoppingCart.GetHashCode() != PageData.OrderConfirmationData.CheckSum || !shoppingCart.HasItems)
        {
            Redirect("shoppingcart.aspx");
            return(null);
        }

        if (PageData.OrderConfirmationData.UserType == EnUserType.JustRegistredUser)
        {
            RegistrationNow();
        }


        var ord = CreateOrder(shoppingCart);

        var    paymentMethod = PaymentService.GetPaymentMethod(ord.PaymentMethodId);
        string email         = PageData.OrderConfirmationData.Customer.EMail;

        string htmlOrderTable = OrderService.GenerateHtmlOrderTable(ord.OrderItems, CurrencyService.CurrentCurrency,
                                                                    shoppingCart.TotalPrice,
                                                                    shoppingCart.DiscountPercentOnTotalPrice,
                                                                    ord.Coupon, ord.Certificate,
                                                                    shoppingCart.TotalDiscount,
                                                                    ord.ShippingCost,
                                                                    PageData.OrderConfirmationData.TaxesTotal,
                                                                    PageData.OrderConfirmationData.BillingContact,
                                                                    PageData.OrderConfirmationData.ShippingContact);

        // declare class to collect info about what was buy
        var googleAnalystic = new GoogleAnalyticsString();
        var trans           = new GoogleAnalyticsTrans
        {
            OrderId     = ord.OrderID.ToString(),
            Affiliation = SettingsMain.ShopName,
            Total       = shoppingCart.TotalPrice.ToString("F2", System.Globalization.CultureInfo.InvariantCulture),
            Tax         = (PageData.OrderConfirmationData.TaxesTotal).ToString("F2", System.Globalization.CultureInfo.InvariantCulture),
            Shipping    = ord.ShippingCost.ToString("F2", System.Globalization.CultureInfo.InvariantCulture),
            City        = string.Empty,
            State       = string.Empty,
            Country     = string.Empty,
        };

        googleAnalystic.Trans = trans;
        googleAnalystic.Items = GetListItemForGoogleAnalytics(shoppingCart, ord.OrderID.ToString());
        ltGaECommerce.Text    = googleAnalystic.GetGoogleAnalyticsEComerceString();


        // Build a new mail
        var customerSb = new StringBuilder();

        customerSb.AppendFormat(Resource.Client_Registration_Name + ": {0}<br/>", PageData.OrderConfirmationData.Customer.FirstName);
        customerSb.AppendFormat(Resource.Client_Registration_Surname + ": {0}<br/>", PageData.OrderConfirmationData.Customer.LastName);
        customerSb.AppendFormat(Resource.Client_Registration_Phone + ": {0}<br/>", PageData.OrderConfirmationData.Customer.Phone);
        customerSb.AppendFormat(Resource.Client_Registration_Country + ": {0}<br/>", PageData.OrderConfirmationData.ShippingContact.Country);
        customerSb.AppendFormat(Resource.Client_Registration_State + ": {0}<br/>", PageData.OrderConfirmationData.ShippingContact.RegionName);
        customerSb.AppendFormat(Resource.Client_Registration_City + ": {0}<br/>", PageData.OrderConfirmationData.ShippingContact.City);
        customerSb.AppendFormat(Resource.Client_Registration_Zip + ": {0}<br/>", PageData.OrderConfirmationData.ShippingContact.Zip);
        customerSb.AppendFormat(Resource.Client_Registration_Address + ": {0}<br/>", string.IsNullOrEmpty(PageData.OrderConfirmationData.ShippingContact.Address) ? Resource.Client_OrderConfirmation_NotDefined : PageData.OrderConfirmationData.ShippingContact.Address);
        customerSb.AppendFormat("Email: {0}<br/>", PageData.OrderConfirmationData.Customer.EMail);


        string htmlMessage = SendMail.BuildMail(new ClsMailParamOnNewOrder
        {
            CustomerContacts    = customerSb.ToString(),
            PaymentType         = PageData.OrderConfirmationData.SelectPaymentName,
            ShippingMethod      = PageData.OrderConfirmationData.SelectShippingName,
            CurrentCurrencyCode = CurrencyService.CurrentCurrency.Iso3,
            TotalPrice          = ord.Sum.ToString(),
            Comments            = ord.CustomerComment,
            Email      = email,
            OrderTable = htmlOrderTable,
            OrderID    = ord.OrderID.ToString(),
            Number     = ord.Number
        });

        if (!CustomerSession.CurrentCustomer.IsVirtual)
        {
            if (paymentMethod != null)
            {
                SendMail.SendMailNow(email, Resource.Client_OrderConfirmation_ReceivedOrder + " " + ord.OrderID,
                                     htmlMessage, true);
                SendMail.SendMailNow(SettingsMail.EmailForOrders,
                                     Resource.Client_OrderConfirmation_ReceivedOrder + " " + ord.OrderID, htmlMessage,
                                     true);
            }
            else
            {
                htmlMessage += " ERROR: \'" + "\'";
                SendMail.SendMailNow(SettingsMail.EmailForOrders,
                                     Resource.Client_OrderConfirmation_OrderError + " " + ord.OrderID, htmlMessage, true);
            }
        }

        var certificate = shoppingCart.Certificate;

        if (certificate != null)
        {
            certificate.OrderNumber = ord.Number;
            certificate.Used        = true;
            certificate.Enable      = true;

            GiftCertificateService.DeleteCustomerCertificate(certificate.CertificateId);
            GiftCertificateService.UpdateCertificateById(certificate);
        }

        var coupon = shoppingCart.Coupon;

        if (coupon != null && shoppingCart.TotalPrice >= coupon.MinimalOrderPrice)
        {
            coupon.ActualUses += 1;
            CouponService.UpdateCoupon(coupon);
            CouponService.DeleteCustomerCoupon(coupon.CouponID);
        }

        ShoppingCartService.ClearShoppingCart(ShoppingCartType.ShoppingCart, PageData.OrderConfirmationData.Customer.Id);
        ShoppingCartService.ClearShoppingCart(ShoppingCartType.ShoppingCart, CustomerSession.CustomerId);
        return(ord);
    }
 public OrdersController(ShoppingCartService cartService)
 {
     _cartService = cartService;
 }
    protected override async Task OnInitializedAsync()
    {
        _products = await InventoryService.GetAllProductsAsync();

        _cartItems = await ShoppingCartService.GetAllItemsAsync();
    }
Exemple #16
0
 public ShoppingCartsController(ComputerStoreDbContext context) : base(context)
 {
     service = new ShoppingCartService(context);
 }
 public ShoppingCartController(ShoppingCartService shoppingCartService, ProductService productService)
 {
     _productService      = productService;
     _shoppingCartService = shoppingCartService;
 }
 public HomeController()
 {
     db              = new KAIROS_SHOPEntities();
     watchService    = new WatchService(db);
     shoppingService = new ShoppingCartService(db);
 }
Exemple #19
0
 public OrderRepository(BakeryDbContext bakeryDbContext, ShoppingCartService shoppingCartService)
 {
     _bakeryDbContext     = bakeryDbContext;
     _shoppingCartService = shoppingCartService;
 }
 public void Setup()
 {
     _shoppingCartService = new ShoppingCartService();
 }
 public PayPalService()
 {
     _repositoryManager = new RepositoryManager();
     _shoppingCartService = new ShoppingCartService();
 }
 public ShoppingCartController(MainContext context, IOptions <EmailSettings> settings, IOptions <Urls> urlSettings) : base(context, settings, urlSettings)
 {
     this.shoppingCartService = new ShoppingCartService();
 }
 public ShopController()
 {
     _shoppingCartService = new ShoppingCartService(_db);
 }
 public ShoppingController(ShoppingCartService shoppingCartService, OrderService orderService)
 {
     this._shoppingCartService = shoppingCartService;
 }
 public ShoppingCartModel(IBooksRepository repository, ShoppingCartService chart)
 {
     repo         = repository;
     ChartService = chart;
     OrderedBooks = new List <Book>();
 }
        public IActionResult AddToCart(long id)
        {
            ShoppingCartService.AddItem(ShopingCartId, id);

            return(RedirectToAction("Index"));
        }
Exemple #27
0
 private void AssignDataSource(OrderService.OrderInfo orderInfo, OrderService.CreditCardInfo cardInfo)
 {
     OrderNoLiteral.Text        = orderInfo.OrderId.ToString();
     OrderDateLiteral.Text      = orderInfo.Date.ToShortDateString();
     PaymentDetailsLiteral.Text = cardInfo.Type.Name + " ," + "XXXX-XXXX-XXXX-" + cardInfo.Number.Substring(cardInfo.Number.Length - 4);
     BillingAddressLiteral.Text = cardInfo.Address.Address1 + ", ";
     if (cardInfo.Address.Address2 != string.Empty && cardInfo.Address.Address2 != null)
     {
         BillingAddressLiteral.Text += cardInfo.Address.Address2 + ", ";
     }
     BillingAddressLiteral.Text += cardInfo.Address.City + ", " + cardInfo.Address.State.Name + "-" + cardInfo.Address.Zip;
     if (orderInfo.RefundAmount != null && orderInfo.RefundAmount != 0)
     {
         RefundAmountLiteral.Text = orderInfo.RefundAmount.ToString();
         RefundPanel.Visible      = true;
     }
     else
     {
         RefundPanel.Visible = false;
     }
     if (orderInfo.Items.Length > 0)
     {
         ShoppingCartInfo            cartInfo1    = new ShoppingCartInfo();
         ShoppingCartItemInfo        cartItemInfo = new ShoppingCartItemInfo();
         List <ShoppingCartItemInfo> cartItems    = new List <ShoppingCartItemInfo>();
         foreach (OrderService.OrderItemInfo orderItem in orderInfo.Items)
         {
             cartItemInfo             = new ShoppingCartItemInfo();
             cartItemInfo.Description = orderItem.Title;
             cartItemInfo.Price       = orderItem.Rate;
             cartItemInfo.Quantity    = orderItem.Quantity;
             cartItemInfo.ProductId   = orderItem.ItemId;
             cartItemInfo.TotalPrice  = cartItemInfo.Quantity * cartItemInfo.Price;
             cartInfo1.SubTotal      += cartItemInfo.TotalPrice;
             cartInfo1.SubTotal       = Math.Round(cartInfo1.SubTotal, 2);
             cartItems.Add(cartItemInfo);
         }
         cartInfo1.CartItems = cartItems.ToArray();
         if (cardInfo.Address.State.Name.ToLower() == "colorado")
         {
             CommonService commonService = ServiceAccess.GetInstance().GetCommon();
             if (commonService.GetProperty("Tax") != null)
             {
                 cartInfo1.Tax = Convert.ToDecimal(commonService.GetProperty("Tax").Value);
             }
         }
         else
         {
             cartInfo1.Tax = 0;
         }
         ShoppingCartService cartService = ServiceAccess.GetInstance().GetShoppingCart();
         ShoppingCartInfo    cartInfo    = cartService.CalculateGrandTotal(cartInfo1);
         CartGridView.DataSource = cartInfo.CartItems;
         CartGridView.DataBind();
         SubTotalLiteral.Text   = cartInfo.SubTotal.ToString();
         ShippingLiteral.Text   = cartInfo.ShippingAndHandling.ToString();
         TaxLiteral.Text        = cartInfo.Tax.ToString();
         GrandTotalLiteral.Text = cartInfo.GrandTotal.ToString();
         DiscountLiteral.Text   = cartInfo.Discount.ToString();
     }
     else
     {
         ProductsPanel.Visible = false;
     }
 }
        public IActionResult RemoveFromCart(long id)
        {
            ShoppingCartService.RemoveItem(ShopingCartId, id);

            return(RedirectToAction("Index"));
        }
Exemple #29
0
        protected void Page_Load(object sender, EventArgs e)
        {
            lDemoWarning.Visible = Demo.IsDemoEnabled || TrialService.IsTrialEnabled;

            //BuyInOneClick.Visible = SettingsOrderConfirmation.BuyInOneClick;

            if (!IsPostBack)
            {
                if (Request["products"].IsNotEmpty())
                {
                    foreach (var item in Request["products"].Split(";"))
                    {
                        int offerId;
                        var newItem = new ShoppingCartItem()
                        {
                            ShoppingCartType = ShoppingCartType.ShoppingCart, CustomerId = CustomerContext.CustomerId
                        };

                        var parts = item.Split("-");
                        if (parts.Length > 0 && (offerId = parts[0].TryParseInt(0)) != 0 && OfferService.GetOffer(offerId) != null)
                        {
                            newItem.OfferId = offerId;
                        }
                        else
                        {
                            continue;
                        }

                        if (parts.Length > 1)
                        {
                            newItem.Amount = parts[1].TryParseFloat();
                        }
                        else
                        {
                            newItem.Amount = 1;
                        }

                        var currentItem = ShoppingCartService.CurrentShoppingCart.FirstOrDefault(shpCartitem => shpCartitem.OfferId == newItem.OfferId);

                        if (currentItem != null)
                        {
                            currentItem.Amount = newItem.Amount;
                            ShoppingCartService.UpdateShoppingCartItem(currentItem);
                        }
                        else
                        {
                            ShoppingCartService.AddShoppingCartItem(newItem);
                        }
                    }
                    Response.Redirect("shoppingcart.aspx");
                    return;
                }

                UpdateBasket();
                SetMeta(new MetaInfo(string.Format("{0} - {1}", SettingsMain.ShopName, Resource.Client_ShoppingCart_ShoppingCart)), string.Empty);

                if (GoogleTagManager.Enabled)
                {
                    var tagManager = ((AdvantShopMasterPage)Master).TagManager;
                    tagManager.PageType   = GoogleTagManager.ePageType.cart;
                    tagManager.ProdIds    = ShoppingCartService.CurrentShoppingCart.Select(item => item.Offer.ArtNo).ToList();
                    tagManager.TotalValue = ShoppingCartService.CurrentShoppingCart.TotalPrice;
                }
            }

            var showConfirmButtons = true;

            //подключение модуля
            foreach (var module in AttachedModules.GetModules <IRenderIntoShoppingCart>())
            {
                var moduleObject = (IRenderIntoShoppingCart)Activator.CreateInstance(module, null);

                ltrlBottomContent.Text = moduleObject.DoRenderToBottom();
                ltrlTopContent.Text    = moduleObject.DoRenderToTop();

                if (!string.IsNullOrEmpty(moduleObject.ClientSideControlNameBottom))
                {
                    var userControl =
                        (this).LoadControl(moduleObject.ClientSideControlNameBottom);

                    if (userControl != null)
                    {
                        ((IUserControlInSc)userControl).ProductIds =
                            ShoppingCartService.CurrentShoppingCart.Select(p => p.Offer.ProductId).ToList();
                        pnlBottomContent.Controls.Add(userControl);
                    }
                }
                if (!string.IsNullOrEmpty(moduleObject.ClientSideControlNameTop))
                {
                    var userControl =
                        (this).LoadControl(moduleObject.ClientSideControlNameTop);

                    if (userControl != null)
                    {
                        ((IUserControlInSc)userControl).ProductIds =
                            ShoppingCartService.CurrentShoppingCart.Select(p => p.Offer.ProductId).ToList();
                        pnlTopContent.Controls.Add(userControl);
                    }
                }
                showConfirmButtons &= moduleObject.ShowConfirmButtons;
            }

            BuyInOneClick.Visible = showConfirmButtons && SettingsOrderConfirmation.BuyInOneClick;
            aCheckOut.Visible     = showConfirmButtons;
        }
 public ShoppingCartController(IProductRepository productRepository, ShoppingCartService shoppingCart)
 {
     _productRepository = productRepository;
     _shoppingCart      = shoppingCart;
 }
        public void ProcessTotals(ShoppingCartOverviewModel model, User user)
        {
            if (model.Items.Count > 0)
            {
                var userdata = ShoppingCartService.GetCheckoutData();
                System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();


                foreach (var typDisc in _TotalProcessKeys)
                {
                    var discounts = LS.Get <Discount>(model.ShopID.ToString() + "_" + typDisc)

                    ;     // search discounts for shop and type
                    discounts.AddRange(LS.Get <Discount>("0_" + typDisc));
                    bool success = false;


                    if (typDisc == DiscountType.ForCartTotal.ToString())
                    {
                        //fix total after previous discounts
                        model.TotalWithoutShip = model.SubTotal + model.Fee;
                        model.Total            = model.SubTotal + model.ShippingCost + model.Fee;
                    }
                    if (discounts.Count > 0)
                    {
                        foreach (var curdiscount in discounts)
                        {
                            #region process discount for cart totals
                            bool breakmain = false;
                            if (curdiscount.IsCodeRequired)
                            {
                                if (string.IsNullOrEmpty(userdata.CouponCode) || userdata.CouponCode != curdiscount.DiscountCode)
                                {
                                    continue; // code doesn`t match
                                }
                            }
                            if (!DiscountService.ExpiriedCheck(curdiscount))
                            {
                                continue;
                            }
                            int curUsesNumber = GetCurrentLimitPosition(curdiscount, user, _UseCache);
                            if (LimitCheck(curUsesNumber, curdiscount.Limit, curdiscount.LimitType))
                            {
                                success = true;
                                foreach (var d in GetRules().Where(x =>
                                                                   // x.Value.Type == DiscountType.ForCartItem &&
                                                                   curdiscount.RuleList.Select(y => y.Name).Contains(x.Key)
                                                                   ))
                                {
                                    var confitem = d.Value.GetConfigItem();

                                    int i = 0;
                                    foreach (var r in curdiscount.RuleList.Where(x => x.Name == d.Key))
                                    {
                                        i++;

                                        //from cache :)
                                        var o = curdiscount.GetRuleConfigObject(i.ToString() + r.Name, () =>
                                        {
                                            return(js.Deserialize(r.Value, confitem.GetType()));
                                        });


                                        success = success && d.Value.Process(model, curdiscount, o, user, curUsesNumber);
                                    }
                                }
                                if (success)
                                {
                                    bool actual = false;
                                    #region subtotal
                                    if (curdiscount.DiscountType == DiscountType.ForCartSubTotal)
                                    {
                                        if (model.SubTotal > 0)
                                        {
                                            decimal minus = 0;
                                            if (curdiscount.IsPercent)
                                            {
                                                minus          = (model.SubTotal * curdiscount.Percent / 100);
                                                model.SubTotal = model.SubTotal - minus;
                                            }
                                            else
                                            {
                                                minus          = curdiscount.Amount;
                                                model.SubTotal = model.SubTotal - curdiscount.Amount;
                                            }
                                            if (model.SubTotal < 0)
                                            {
                                                model.SubTotal = 0;
                                            }
                                            model.TotalDiscount += minus;
                                            actual = true;
                                        }
                                    }
                                    #endregion
                                    #region ship
                                    else if (curdiscount.DiscountType == DiscountType.ForCartShip)
                                    {
                                        if (model.SubTotal < model.FreeShipFrom)
                                        {
                                            model.ShippingCost = model.ShopShipCost;
                                        }
                                        if (model.ShippingCost > 0)
                                        {
                                            decimal minus = 0;
                                            if (curdiscount.IsPercent)
                                            {
                                                minus = (model.ShippingCost * curdiscount.Percent / 100);
                                                model.ShippingCost = model.ShippingCost - minus;
                                            }
                                            else
                                            {
                                                minus = curdiscount.Amount;
                                                model.ShippingCost = model.ShippingCost - curdiscount.Amount;
                                            }
                                            if (model.ShippingCost < 0)
                                            {
                                                model.ShippingCost = 0;
                                            }
                                            model.TotalDiscount += minus;
                                            actual = true;
                                        }
                                    }
                                    #endregion
                                    #region payment fee
                                    //else if (curdiscount.DiscountType == DiscountType.ForCartFee)
                                    //{
                                    //    if (model.Fee > 0)
                                    //    {
                                    //        decimal minus = 0;
                                    //        if (curdiscount.IsPercent)
                                    //        {
                                    //            minus = (model.Fee * curdiscount.Percent / 100);
                                    //            model.Fee = model.Fee - minus;
                                    //        }
                                    //        else
                                    //        {
                                    //            minus = curdiscount.Amount;
                                    //            model.Fee = model.Fee - curdiscount.Amount;
                                    //        }
                                    //        if (model.Fee < 0) { model.Fee = 0; }
                                    //        model.TotalDiscount += minus;
                                    //        actual = true;
                                    //    }
                                    //}
                                    #endregion
                                    #region total
                                    else if (curdiscount.DiscountType == DiscountType.ForCartTotal)
                                    {
                                        if (model.Total > 0)
                                        {
                                            decimal minus = 0;
                                            if (curdiscount.IsPercent)
                                            {
                                                minus       = (model.Total * curdiscount.Percent / 100);
                                                model.Total = model.Total - minus;
                                            }
                                            else
                                            {
                                                minus       = curdiscount.Amount;
                                                model.Total = model.Total - curdiscount.Amount;
                                            }
                                            if (model.Total < 0)
                                            {
                                                model.Total = 0;
                                            }
                                            model.TotalDiscount += minus;
                                            actual = true;
                                        }
                                    }
                                    #endregion
                                    if (actual)//if actual
                                    {
                                        if (curdiscount.IsCodeRequired && curdiscount.DiscountCode == userdata.CouponCode)
                                        {
                                            model.DiscountByCouponeCodeText = curdiscount.Name;
                                        }
                                        curUsesNumber++;

                                        if (!string.IsNullOrEmpty(model.DiscountDescription))
                                        {
                                            model.DiscountDescription += ", " + curdiscount.Name;
                                        }
                                        else
                                        {
                                            model.DiscountDescription = curdiscount.Name;
                                        }
                                        if (curdiscount.LessShopFee)
                                        {
                                            model.IsLessMemberFee = true;
                                        }
                                        model.DiscountIDs.Add(curdiscount.ID);//for history save
                                        if (curdiscount.PreventNext)
                                        {
                                            breakmain = true;
                                        }
                                    }
                                }
                            }

                            if (breakmain)
                            {
                                break;
                            }
                            #endregion
                        }
                    }
                }
            }
        }
 public HomeController(ProductRepository productRepository, ShoppingCartService shoppingCartService)
 {
     this._productRepository   = productRepository;
     this._shoppingCartService = shoppingCartService;
 }