示例#1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(Code))
        {
            RedirectToMainPage();
            return;
        }

        // Если код правильный, и такого же товара нет в корзине - то всё ок.
        var orderByRequest = OrderByRequestService.GetOrderByRequest(Code);

        if (orderByRequest != null && orderByRequest.IsValidCode && ProductService.IsExists(orderByRequest.ProductId) &&
            ShoppingCartService.CurrentShoppingCart.Count(p => p.ItemType == EnumItemType.Product && p.EntityId == orderByRequest.ProductId) == 0)
        {
            ShoppingCartService.AddShoppingCartItem(new ShoppingCartItem
            {
                EntityId         = orderByRequest.ProductId,
                Amount           = orderByRequest.Quantity,
                ShoppingCartType = ShoppingCartType.ShoppingCart
            });

            Response.Redirect(UrlService.GetAbsoluteLink("/shoppingcart.aspx"));
            return;
        }

        lblMessage.Text      = Resources.Resource.Client_OrderProduct_Message;
        lblMessage.ForeColor = Color.Red;
    }
示例#2
0
 public static void MergeShoppingCarts(Guid oldCustomerId, Guid currentCustomerId)
 {
     if (oldCustomerId != currentCustomerId)
     {
         foreach (var item in ShoppingCartService.GetAllShoppingCarts(oldCustomerId))
         {
             ShoppingCartService.AddShoppingCartItem(item, currentCustomerId);
         }
     }
 }
示例#3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        customerGroup        = CustomerSession.CurrentCustomer.CustomerGroup;
        lDemoWarning.Visible = Demo.IsDemoEnabled || Trial.IsTrialEnabled;

        if (!IsPostBack)
        {
            if (Request["productid"].IsNotEmpty())
            {
                int productId = Request["productid"].TryParseInt();
                int amount    = Request["amount"].TryParseInt(1);
                if (productId != 0 && ProductService.IsProductEnabled(productId))
                {
                    IList <EvaluatedCustomOptions> listOptions = null;
                    string selectedOptions = HttpUtility.UrlDecode(Request["AttributesXml"]);
                    try
                    {
                        listOptions = CustomOptionsService.DeserializeFromXml(selectedOptions);
                    }
                    catch (Exception)
                    {
                        listOptions = null;
                    }

                    if (CustomOptionsService.DoesProductHaveRequiredCustomOptions(productId) && listOptions == null)
                    {
                        Response.Redirect(SettingsMain.SiteUrl + UrlService.GetLinkDB(ParamType.Product, productId));
                        return;
                    }

                    ShoppingCartService.AddShoppingCartItem(new ShoppingCartItem
                    {
                        EntityId         = productId,
                        Amount           = amount,
                        ShoppingCartType = ShoppingCartType.ShoppingCart,
                        AttributesXml    = listOptions != null ? selectedOptions : string.Empty,
                        ItemType         = EnumItemType.Product
                    });

                    Response.Redirect("shoppingcart.aspx");
                }
            }

            UpdateBasket();
            SetMeta(new MetaInfo(string.Format("{0} - {1}", SettingsMain.ShopName, Resource.Client_ShoppingCart_ShoppingCart)), string.Empty);
        }
        //relatedProducts.ProductIds = ShoppingCartService.CurrentShoppingCart.Where(p => p.ItemType == ShoppingCartItem.EnumItemType.Product).Select(p => p.EntityId).ToList();
    }
 public RedirectToActionResult AddToShoppingCart(int productModellNumber)
 {
     // Ha van belépett felhasználó
     if (User.Identity.IsAuthenticated)
     {
         var selectedProduct = storeService.GetProduct(productModellNumber);
         if (selectedProduct != null)
         {
             shoppingCartService.AddShoppingCartItem(productModellNumber);
         }
         return(RedirectToAction("Index"));
     }
     else
     {
         return(RedirectToAction("Index", "Account"));
     }
 }
示例#5
0
    protected void btnBuy_Click(object sender, EventArgs e)
    {
        var id = CreateCertificate();

        if (id != 0)
        {
            ShoppingCartService.AddShoppingCartItem(new ShoppingCartItem
            {
                EntityId         = id,
                Amount           = 1,
                ShoppingCartType = ShoppingCartType.ShoppingCart,
                AttributesXml    = null,
                ItemType         = EnumItemType.Certificate
            });
            Page.Response.Redirect("~/shoppingcart.aspx");
        }
    }
示例#6
0
        protected void btnAddToCartClick(object sender, EventArgs e)
        {
            int itemId       = hfWishListItemID.Value.TryParseInt();
            var wishListItem = ShoppingCartService.CurrentWishlist.Find(item => item.ShoppingCartItemId == itemId);

            if (wishListItem != null)
            {
                ShoppingCartService.AddShoppingCartItem(new ShoppingCartItem
                {
                    OfferId          = wishListItem.OfferId,
                    Amount           = 1,
                    ShoppingCartType = ShoppingCartType.ShoppingCart,
                    AttributesXml    = wishListItem.AttributesXml,
                });
                Response.Redirect("shoppingcart.aspx");
            }
        }
示例#7
0
    protected void btnAddToBasket_Click(object sender, EventArgs e)
    {
        if (!productCustomOptions.IsValid)
        {
            productCustomOptions.ShowValidation = true;
            return;
        }

        if (IsEditItem)
        {
            var returnUrl = "";
            var item      = ShoppingCartService.GetShoppingCart(ItemType)[ItemIndex];
            item.AttributesXml = CustomOptionsService.SerializeToXml(productCustomOptions.CustomOptions, productCustomOptions.SelectedOptions);

            switch (ItemType)
            {
            case ShoppingCartType.ShoppingCart:
                //item.Amount = Int32.Parse(txtAmount.Text);
                returnUrl = "/shoppingcart.aspx";
                break;

            case ShoppingCartType.Wishlist:
                item.Amount = 1;
                returnUrl   = "/wishlist.aspx";
                break;
            }

            ShoppingCartService.UpdateShoppingCartItem(item);
            Redirect(returnUrl);
        }
        else
        {
            ShoppingCartService.AddShoppingCartItem(new ShoppingCartItem
            {
                EntityId = ProductId,
                //Amount = Convert.ToInt32(txtAmount.Text),
                ShoppingCartType = ShoppingCartType.ShoppingCart,
                AttributesXml    = CustomOptionsService.SerializeToXml(productCustomOptions.CustomOptions, productCustomOptions.SelectedOptions),
                ItemType         = EnumItemType.Product
            });

            Redirect("/shoppingcart.aspx");
        }
    }
示例#8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Code))
            {
                Response.Redirect("~/");
                return;
            }

            // Если код правильный, и такого же товара нет в корзине - то всё ок.
            var orderByRequest = OrderByRequestService.GetOrderByRequest(Code);

            if (orderByRequest == null)
            {
                lblMessage.Text      = Resources.Resource.Client_OrderProduct_Message;
                lblMessage.ForeColor = System.Drawing.Color.Red;
                return;
            }

            if (ShoppingCartService.CurrentShoppingCart.Any(p => p.Offer.OfferId == orderByRequest.OfferId))
            {
                Response.Redirect("shoppingcart.aspx");
            }

            var offer = OfferService.GetOffer(orderByRequest.OfferId);

            if (orderByRequest != null && orderByRequest.IsValidCode && ProductService.IsExists(orderByRequest.ProductId) && offer != null && offer.Price > 0)
            {
                ShoppingCartService.AddShoppingCartItem(new ShoppingCartItem
                {
                    OfferId          = orderByRequest.OfferId,
                    Amount           = orderByRequest.Quantity,
                    ShoppingCartType = ShoppingCartType.ShoppingCart,
                    AttributesXml    = orderByRequest.Options
                });
                Response.Redirect("shoppingcart.aspx");
            }
            else
            {
                lblMessage.Text      = Resources.Resource.Client_OrderProduct_Message;
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
        public async Task AddShoppingCartItemShouldWorkProperly()
        {
            var shoppingCartRepository     = new Mock <IRepository <ShoppingCart> >();
            var shoppingCartItemRepository = new Mock <IRepository <ShoppingCartItem> >();

            shoppingCartRepository.Setup(x => x.All())
            .Returns(new List <ShoppingCart> {
                new ShoppingCart {
                    ApplicationUserId = "1"
                }
            }.AsQueryable());
            var service = new ShoppingCartService(shoppingCartRepository.Object, shoppingCartItemRepository.Object);

            var actualResult = await service.AddShoppingCartItem("1", 1);

            Assert.True(actualResult == true, "Add ShoppingCartItem should return true upon successfully adding shopping cart item.");
            shoppingCartRepository.Verify(x => x.All(), Times.Once, "All method of ShoppingCartRepository should be called once.");
            shoppingCartItemRepository.Verify(x => x.AddAsync(It.IsAny <ShoppingCartItem>()), Times.Once, "AddAsync method of ShoppingCartItemRepository should be called once.");
            shoppingCartItemRepository.Verify(x => x.SaveChangesAsync(), Times.Once, "SaveChangesAsync method of ShoppingCartItemRepository should be called once.");
        }
示例#10
0
    protected void AddToWishList_Click(object sender, EventArgs e)
    {
        if (!productCustomOptions.IsValid)
        {
            productCustomOptions.ShowValidation = true;
            return;
        }

        ShoppingCartService.AddShoppingCartItem(new ShoppingCartItem
        {
            EntityId = ProductId,
            //Amount = Convert.ToInt32(txtAmount.Text),
            ShoppingCartType = ShoppingCartType.Wishlist,
            AttributesXml    = CustomOptionsService.SerializeToXml(productCustomOptions.CustomOptions, productCustomOptions.SelectedOptions)
        });
        lbtnWishlist.Visible    = false;
        alreadyWishList.Visible = true;

        Redirect("wishlist.aspx");
    }
示例#11
0
    protected void btnBuyProduct_Click(object sender, EventArgs e)
    {
        try
        {
            int productId = 0;
            Int32.TryParse(hiddenProductID.Value, out productId);

            if (CustomOptionsService.DoesProductHaveRequiredCustomOptions(productId))
            {
                Response.Redirect(GetProductLink(ProductItems.First(p => p.ProductId == productId)));
            }


            List <CustomOption> customOptions = CustomOptionsService.GetCustomOptionsByProductId(Convert.ToInt32(productId));
            if ((customOptions != null) && (customOptions.Count != 0))
            {
                Page.Response.Redirect(UrlService.GetLinkDB(ParamType.Product, productId));
            }

            ShoppingCartService.AddShoppingCartItem(new ShoppingCartItem
            {
                EntityId         = productId,
                Amount           = 1,
                ShoppingCartType = ShoppingCartType.ShoppingCart,
                AttributesXml    = string.Empty,
                ItemType         = EnumItemType.Product
            });
        }
        catch (ThreadAbortException) { }
        catch (Exception ex)
        {
            Debug.LogError(ex);
        }

        Page.Response.Redirect(GetAbsoluteLink("/shoppingcart.aspx"), true);
    }
示例#12
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;
        }