Пример #1
0
        /// <summary>
        /// Add an item to the current order. This is a backup for the Ajax version of this
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAddToCurrentOrder_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in this.gvSearchResults.Rows)
            {
                //this.Page.Request.Url.GetLeftPart(UriPartial.Path)
                CheckBox checkBox    = row.FindControl("cbSelectEntry") as CheckBox;
                TextBox  quantityBox = row.FindControl("tbQuantity") as TextBox;

                CartHelper ch = new CartHelper(global::NWTD.Profile.ActiveCart);
                decimal    quantity;
                if (checkBox.Checked && decimal.TryParse(quantityBox.Text, out quantity))
                {
                    checkBox.Checked = false;
                    quantityBox.Text = string.Empty;

                    Entry itemToAdd = this.dsSearchResults.CatalogEntries[row.RowIndex];

                    //if this item is already in the cart, get it's quantity, then add it to the entered quantity
                    LineItem existingItem = ch.LineItems.SingleOrDefault(li => li.CatalogEntryId == itemToAdd.ID);
                    if (existingItem != null)
                    {
                        quantity += existingItem.Quantity;
                    }

                    ch.AddEntry(this.dsSearchResults.CatalogEntries[row.RowIndex], quantity);
                    //blSelectedItems.Items.Add(new ListItem(itemToAdd.Name, StoreHelper.GetEntryUrl(itemToAdd)));
                }
            }
            gvSearchResults.DataBind();
        }
Пример #2
0
        /// <summary>
        /// Handles the Click event of the AddWishList control. Add item to Wish List.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void AddWishList_Click(object sender, EventArgs e)
        {
            var cart     = new CartHelper(Cart.DefaultName);
            var wishList = new CartHelper(CartHelper.WishListName);

            if (Entry == null)
            {
                return;
            }

            var entry = CatalogContext.Current.GetCatalogEntry(Entry.CatalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

            if (entry == null)
            {
                return;
            }

            if (entry.Entries.Entry != null && entry.Entries.Entry.Any())
            {
                entry = entry.Entries.Entry.First();
            }

            if (!entry.EntryType.Equals(EntryType.Variation))
            {
                return;
            }

            wishList.AddEntry(entry, 1, true, new[] { cart });
            Context.RedirectFast(GetUrl(Settings.WishListPage));
        }
Пример #3
0
        private CartActionResult AddToCart(string name, LineItem lineItem)
        {
            CartHelper ch       = new CartHelper(name);
            string     messages = string.Empty;

            if (lineItem.Quantity < 1)
            {
                lineItem.Quantity = 1;
            }

            var entry = CatalogContext.Current.GetCatalogEntry(lineItem.Code);

            ch.AddEntry(entry, lineItem.Quantity, false, new CartHelper[] { });

            lineItem.Name = TryGetDisplayName(entry);
            //lineItem.IsInventoryAllocated = true; // Will this be enough?

            AddCustomProperties(lineItem, ch.Cart);

            messages = RunWorkflowAndReturnFormattedMessage(ch.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);
            ch.Cart.AcceptChanges();

            return(new CartActionResult()
            {
                Success = true, Message = messages
            });
        }
Пример #4
0
        /// <summary>
        /// Handles the Click event of the WishListLink control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
        protected void WishListButton_Click(object sender, EventArgs e)
        {
            CartHelper ch       = new CartHelper(Cart.DefaultName);
            CartHelper wishList = new CartHelper(CartHelper.WishListName);

            if (VariationContent != null)
            {
                if (VariationContent.GetPrices(_marketId, CustomerPricing.AllCustomers).Count > 0)
                {
                    var entry          = VariationContent.LoadEntry();
                    var warehouseField = FindControlRecursive(this.Parent, "hidWarehouseCode") as HiddenField;
                    var warehouseCode  = Constants.DefaultWarehouseCode;
                    if (warehouseField != null && !string.IsNullOrEmpty(warehouseField.Value))
                    {
                        warehouseCode = warehouseField.Value;
                    }
                    wishList.AddEntry(entry, 1, true, warehouseCode, new[] { ch });
                    Response.Redirect(GetUrl(Settings.WishListPage));
                }
                else
                {
                    ErrorMessage.Text = "No Price.";
                    divErrorMsg.Style.Add("display", "block");
                }
            }
        }
Пример #5
0
    /// <summary>
    /// Handles the Click event of the AddToCartLinkButton control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void AddToCartLinkButton_Click(object sender, EventArgs e)
    {
        CartHelper ch = new CartHelper(Cart.DefaultName);

        EntryAssociation[] youMayAlsoLikeAssociations = this.YouMayAlsoLikeRepeater.DataSource as EntryAssociation[];
        if (youMayAlsoLikeAssociations != null)
        {
            // Be careful with array bounds.
            for (int i = 0; i <= this.YouMayAlsoLikeRepeater.Items.Count - 1; i++)
            {
                LinkButton lb = this.YouMayAlsoLikeRepeater.Items[i].FindControl("AddToCartLinkButton") as LinkButton;
                if (lb != null)
                {
                    // Check for a match between the sender and the RepeaterItem.
                    if ((LinkButton)sender == lb)
                    {
                        ch.AddEntry(youMayAlsoLikeAssociations[i].Entry, 1); // Add just one.
                    }
                }
            }
        }

        // Redirect to shopping cart.
        Response.Redirect(ResolveUrl(Mediachase.Cms.NavigationManager.GetUrl("ShoppingCart")));
    }
Пример #6
0
        public bool AddToCart(string code, out string warningMessage)
        {
            var entry = CatalogContext.Current.GetCatalogEntry(code);

            CartHelper.AddEntry(entry);
            CartHelper.Cart.ProviderId = "frontend"; // if this is not set explicitly, place price does not get updated by workflow
            ValidateCart(out warningMessage);

            return(CartHelper.LineItems.Select(x => x.Code).Contains(code));
        }
Пример #7
0
        /// <summary>
        /// Handles the Click event of the BuyButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
        protected void BuyButton_Click(object sender, EventArgs e, Entry entry, ref bool reject)
        {
            CartHelper ch = new CartHelper(Cart.DefaultName);

            // Check if Entry Object is null.
            if (entry != null)
            {
                // Add item to a cart.
                ch.AddEntry(entry);
            }
        }
Пример #8
0
        public ActionResult AddToWishList(WishListPage currentPage, string code, decimal quantity)
        {
            Entry entry = CatalogContext.Current.GetCatalogEntry(code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));

            CartHelper ch = new CartHelper(CartHelper.WishListName);

            ch.AddEntry(entry, quantity, false);
            ch.Cart.AcceptChanges();

            return(RedirectToAction("Index"));
        }
Пример #9
0
        public void AddLineItem()
        {
            var entry = _catalogSystem.GetCatalogEntry(Constants.VariationCode);

            _helper.AddEntry(entry);
            var lineItem = _helper.LineItems.First();

            lineItem.IsInventoryAllocated = true;
            lineItem.Quantity             = 1;
            lineItem["Custom"]            = true;
            _helper.Cart.AcceptChanges();
        }
Пример #10
0
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]         //the entire parameter must be serialized to a string (no individual raw POST values)
        public CartResponse AddItem(CartItem item, string cartname)
        {
            NWTD.Profile.EnsureCustomerCart();

            CartResponse response = new CartResponse();

            if (string.IsNullOrEmpty(cartname))
            {
                cartname = global::NWTD.Profile.ActiveCart;
            }
            CartHelper ch        = new CartHelper(cartname);
            Entry      itemToAdd = CatalogContext.Current.GetCatalogEntry(item.Code, new Mediachase.Commerce.Catalog.Managers.CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

            if (itemToAdd == null)
            {
                response.Status  = CartResponseStatus.ERROR;
                response.Message = String.Format("The item with ISBN number {0} does not exist.", item.Code);
                return(response);
            }

            //if this item is already in the cart, get it's quantity, then add it to the entered quantity
            decimal  addedQuantity = item.Quantity;
            LineItem existingItem  = ch.LineItems.SingleOrDefault(li => li.CatalogEntryId == itemToAdd.ID);

            //this is from back when we used let people select quantities when adding to the cart
            //if (existingItem != null) item.Quantity += existingItem.Quantity;

            if (existingItem != null)
            {
                response.Message = string.Format("{0} is already in your Wish List and cannot be added a second time.  If you need more, please return to your Wish List and increase the quantity of the existing item.", item.Code);
                response.Status  = CartResponseStatus.WARNING;
                return(response);
            }

            try {
                ch.AddEntry(itemToAdd, item.Quantity);
                response.Message = String.Format("Added {0} item(s) with ISBN number {1} to the Wish List ({2}).", addedQuantity.ToString(), item.Code, cartname);
                var addedItem = new CartItem();
                addedItem.Code     = item.Code;
                addedItem.Quantity = item.Quantity;
                response.ItemsAdded.Add(addedItem);

                //too bad this doesn't work...
                //ch.Cart.Modified = DateTime.Now;
                //ch.Cart.AcceptChanges();

                return(response);
            } catch (Exception ex) {
                response.Status  = CartResponseStatus.ERROR;
                response.Message = ex.Message;
                return(response);
            }
        }
        protected void AddToCart_Click(object sender, EventArgs e)
        {
            CartHelper ch       = new CartHelper(Cart.DefaultName);
            int        quantity = int.Parse(txtQuantity.Text);

            ch.AddEntry(entry, quantity, false, new CartHelper[] { });

            StartPageType home     = (StartPageType)GetPage(ContentReference.StartPage);
            var           cartPage = home.Settings.CartPage;

            string cartPageUrl = UrlResolver.Current.GetUrl(cartPage);

            Response.Redirect(cartPageUrl);
        }
Пример #12
0
        /// <summary>
        /// Handles the ItemCommand event of the lvCartItems control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ListViewCommandEventArgs"/> instance containing the event data.</param>
        protected void lvCartItems_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName != "Wishlist")
            {
                return;
            }

            int lineItemId;

            if (!Int32.TryParse(lvCartItems.DataKeys[e.Item.DataItemIndex].Value.ToString(), out lineItemId))
            {
                return;
            }

            var cart = new CartHelper(Cart.DefaultName);

            foreach (var item in cart.LineItems)
            {
                if (item.LineItemId != lineItemId)
                {
                    continue;
                }

                var qty    = item.Quantity;
                var helper = new CartHelper(CartHelper.WishListName);
                var entry  = CatalogContext.Current.GetCatalogEntry(item.CatalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));
                if (entry == null)
                {
                    continue;
                }

                helper.AddEntry(entry, qty, true);
                item.Delete();
            }

            // If cart is empty, remove it from the database
            if (CartHelper.IsEmpty)
            {
                CartHelper.Delete();
            }

            // Save changes
            cart.Cart.AcceptChanges();

            BindData();

            //Move to Wish-List
            Context.RedirectFast(GetUrl(Settings.WishListPage));
        }
Пример #13
0
        /// <summary>
        /// Handles the Click event of the PurchaseLink control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
        protected void BuyButton_Click(object sender, EventArgs e)
        {
            CartHelper ch       = new CartHelper(Cart.DefaultName);
            CartHelper wishList = new CartHelper(CartHelper.WishListName);

            if (VariationContent != null)
            {
                //get quantity when use AddToCart into Repeater (case: Relate Product)
                var linkButtonControl  = (sender as System.Web.UI.Control);
                var addToCartControl   = linkButtonControl.Parent;
                var txtQuantityControl = addToCartControl.FindControl("txtQuantity");

                var entry          = VariationContent.LoadEntry(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo | CatalogEntryResponseGroup.ResponseGroup.Inventory);
                var warehouseField = FindControlRecursive(this.Parent, "hidWarehouseCode") as HiddenField;
                var warehouseCode  = String.Empty;
                if (warehouseField != null && !string.IsNullOrEmpty(warehouseField.Value))
                {
                    warehouseCode = warehouseField.Value;
                }

                decimal quantity = decimal.Parse(System.Web.HttpContext.Current.Request.Form[txtQuantityControl.UniqueID].ToString());
                string  errorMessage;
                if (!SampleStoreHelper.AllowAddToCart(
                        ch.Cart,
                        entry,
                        false,
                        quantity,
                        String.IsNullOrEmpty(warehouseCode) ? Constants.DefaultWarehouseCode : warehouseCode,
                        out errorMessage))
                {
                    ErrorMessage.Text = errorMessage;
                    divErrorMsg.Style.Add("display", "block");
                    //We will do a postback here, reset the warehouse code to empty
                    if (warehouseField != null)
                    {
                        warehouseField.Value = string.Empty;
                    }
                    return;
                }

                if (entry.IsAvailableInMarket(_marketId))
                {
                    ch.AddEntry(entry, quantity, false, warehouseCode, new CartHelper[] { wishList });
                    Response.Redirect(GetUrl(Settings.CartPage));
                }
            }
        }
Пример #14
0
        /// <summary>
        /// When a users click finish, loop through the entries (one per line) and try to find one in the catalog.
        /// If one is found, add it.
        /// At the end, show a list of successful and failed entries.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void wzImportISBNS_FinishButtonClick(object sender, WizardNavigationEventArgs e)
        {
            string[]             ISBNs  = tbISNBS.Text.Split(System.Environment.NewLine.ToCharArray());
            IEnumerable <string> values = ISBNs.Where(isbn => !string.IsNullOrEmpty(isbn));

            foreach (string code in values)
            {
                //clean it up, removing spaces from ends and hypens
                string cleanCode = code.Trim().Replace("-", string.Empty);

                Entry entry = CatalogContext.Current.GetCatalogEntry(cleanCode, new Mediachase.Commerce.Catalog.Managers.CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                if (entry != null && NWTD.Catalog.IsEntryAvailable(entry))
                {
                    CartHelper ch = this.SelectedCartHelper;

                    LineItem existingItem = ch.LineItems.SingleOrDefault(li => li.CatalogEntryId == entry.ID);
                    if (existingItem != null)
                    {
                        this.FailedEntries.Add(string.Format("{0} - This item is already in your Wish List and cannot be added a second time.  If you need more, please return to your Wish List and increase the quantity of the existing item.", code));
                    }
                    else
                    {
                        ch.AddEntry(entry, 0);
                        this.SuccessfulEntries.Add(entry);
                    }
                }
                else
                {
                    this.FailedEntries.Add(string.Format("{0} - The item with this ISBN does not exist.", code));
                }
            }

            this.blFailedISBNS.DataSource = this.FailedEntries;
            this.blFailedISBNS.DataBind();

            this.gvImportedEntries.DataSource = this.SuccessfulEntries;
            this.gvImportedEntries.DataBind();

            if (this.SuccessfulEntries.Count > 0)
            {
                this.pnlImportSuccess.Visible = true;
            }
            if (this.FailedEntries.Count > 0)
            {
                this.pnlImportFailure.Visible = true;
            }
        }
Пример #15
0
        private CartActionResult AddToCart(string name, LineItem lineItem)
        {
            CartHelper ch       = new CartHelper(name);
            string     messages = string.Empty;

            if (lineItem.Quantity < 1)
            {
                lineItem.Quantity = 1;
            }

            // Need entry for adding to cart
            var entry = CatalogContext.Current.GetCatalogEntry(lineItem.Code);

            ch.AddEntry(entry, lineItem.Quantity, false, new CartHelper[] { });

            // Need content for easier access to more information
            ContentReference itemLink = _referenceConverter.GetContentLink(entry.CatalogEntryId,
                                                                           CatalogContentType.CatalogEntry, 0);
            EntryContentBase entryContent = _contentLoader.Get <EntryContentBase>(itemLink);

            // Populate line item with as much as we can find
            if (string.IsNullOrEmpty(lineItem.ImageUrl))
            {
                lineItem.ImageUrl = entryContent.GetDefaultImage();
            }

            if (string.IsNullOrEmpty(lineItem.ArticleNumber))
            {
                lineItem.ArticleNumber = entry.ID;
            }

            lineItem.Name = TryGetDisplayName(entry);
            //lineItem.IsInventoryAllocated = true; // Will this be enough?

            AddCustomProperties(lineItem, ch.Cart);


            messages = RunWorkflowAndReturnFormattedMessage(ch.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);
            ch.Cart.AcceptChanges();

            // TODO: Always returns success, if we get warnings, we need to show them
            return(new CartActionResult()
            {
                Success = true, Message = messages
            });
        }
Пример #16
0
    /// <summary>
    /// Adds to wish list.
    /// </summary>
    /// <param name="helper">The helper.</param>
    /// <param name="entry">The entry.</param>
    private void AddToWishList(CartHelper helper, Entry entry)
    {
        bool alreadyExists = false;

        // Check if item exists
        foreach (LineItem item in helper.LineItems)
        {
            if (item.CatalogEntryId.Equals(entry.ID))
            {
                alreadyExists = true;
            }
        }

        if (!alreadyExists)
        {
            helper.AddEntry(entry);
        }
    }
Пример #17
0
        protected int DoOneClickBuy(PlaceOrderInfo orderInfo)
        {
            if (orderInfo == null)
            {
                throw new ArgumentNullException("orderInfo");
            }
            if (orderInfo.Products.Count == 0)
            {
                throw new ArgumentNullException("orderInfo.Products");
            }

            CartHelper ch = new CartHelper("OneClickBuy", orderInfo.CustomerId);

            foreach (PlaceOrderLineItemInfo lineItemInfo in orderInfo.Products)
            {
                Entry ownerProduct = CatalogContext.Current.GetCatalogEntry(lineItemInfo.ProductEntryCode,
                                                                            new CatalogEntryResponseGroup(
                                                                                CatalogEntryResponseGroup.ResponseGroup
                                                                                .CatalogEntryFull));
                if (ownerProduct == null)
                {
                    throw new ArgumentNullException("Cannot load Product with code: " +
                                                    lineItemInfo.ProductEntryCode);
                }

                Entry sku = CatalogContext.Current.GetCatalogEntry(lineItemInfo.VariationEntryCode,
                                                                   new CatalogEntryResponseGroup(
                                                                       CatalogEntryResponseGroup.ResponseGroup
                                                                       .CatalogEntryFull));
                if (sku == null)
                {
                    throw new ArgumentNullException("Cannot load Variation with code: " +
                                                    lineItemInfo.VariationEntryCode);
                }

                sku.ParentEntry = ownerProduct;

                ch.AddEntry(sku, lineItemInfo.Count, fixedQuantity: true);
            }

            int orderId = PlaceOneClickOrder(ch, orderInfo);

            return(orderId);
        }
Пример #18
0
        public ActionResult AddToCart(FashionVariation currentContent, decimal Quantity, string Monogram)
        {
            // ToDo: (lab D1)
            CartHelper ch       = new CartHelper(Cart.DefaultName);
            LineItem   lineitem = ch.AddEntry(currentContent.LoadEntry(), Quantity, false);

            // could have a bool-check for "monogrammable"
            lineitem["Monogram"] = Monogram;

            // Maybe would like to set expiration-date on the cart ... that is custom, but exists on PO
            ch.Cart.ProviderId = "frontend"; // needs to be set for WF
            ch.Cart.AcceptChanges();         // Persist

            StartPage        home   = _contentLoader.Get <StartPage>(ContentReference.StartPage);
            ContentReference theRef = home.Settings.checkoutPage;

            string passingValue = String.Empty; // if needed, the cart for example

            return(RedirectToAction("Index", new { node = theRef, passedAlong = passingValue }));
        }
        // Optional lab in Fund. Mod. D - create a WishList and inspection in CM + config -alteration
        public void AddToWishList(ShirtVariation currentContent)
        {
            CartHelper wishList = new CartHelper(CartHelper.WishListName); // note the arg.

            wishList.AddEntry(currentContent.LoadEntry());
            wishList.Cart.AcceptChanges();

            string           passingValue = currentContent.Code;
            ContentReference theRef       = currentContent.ParentLink; // maybe go here when done

            // just testing
            Response.Redirect(_urlResolver.GetUrl(theRef));
            //RedirectToRoute()

            #region Chwcking links

            //var startPage = _contentLoader.Get<StartPage>(ContentReference.StartPage);
            //var cartUrl = ServiceLocator.Current.GetInstance<UrlResolver>().GetUrl(startPage.Settings.cartPage, currentContent.Language.Name);

            ////return RedirectToAction("Index","CartController", new { node = theRef, passedAlong = passingValue });

            //var lang = ContentLanguage.Instance.FinalFallbackCulture.ToString();  // gets "en"

            //return RedirectToAction("Index", "en/Cart", new { passedAlong = passingValue }); // works
            //return RedirectToAction("Index", CultureInfo.CurrentCulture.TwoLetterISOLanguageName + "/Cart"
            //    , new { passedAlong = passingValue }); // works
            //// would you do like the above?

            //// Cut´n paste from Cart
            //StartPage home = _contentLoader.Get<StartPage>(ContentReference.StartPage);
            //ContentReference theRef = home.Settings.checkoutPage;
            //string passingValue = "This is fun"; // could pass the cart instead

            // kolla Url.Action
            //Server.Transfer / Server.TransferRequest
            //Httputility
            #endregion
        }
Пример #20
0
        /// <summary>
        /// Handles the Click event of the AddToCart control. Add item to Cart.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void AddToCart_Click(object sender, EventArgs e)
        {
            var cart     = new CartHelper(Cart.DefaultName);
            var wishList = new CartHelper(CartHelper.WishListName);

            if (Entry == null)
            {
                return;
            }

            if (Entry.Entries.Entry != null && Entry.Entries.Entry.Any())
            {
                Entry = Entry.Entries.Entry.First();
            }

            if (!Entry.EntryType.Equals(EntryType.Variation))
            {
                return;
            }

            cart.AddEntry(Entry, 1, false, new[] { wishList });
            Context.RedirectFast(GetUrl(Settings.CartPage));
        }
Пример #21
0
    /// <summary>
    /// Adds to cart.
    /// </summary>
    /// <param name="helper">The helper.</param>
    /// <param name="entry">The entry.</param>
    /// <param name="qty">The qty.</param>
    private void AddToCart(CartHelper helper, Entry entry, decimal qty)
    {
        bool alreadyExists = false;

        // Check if item exists
        foreach (LineItem item in helper.LineItems)
        {
            if (item.CatalogEntryId.Equals(entry.ID))
            {
                item.Quantity += qty;
                alreadyExists  = true;
            }
        }

        if (!alreadyExists)
        {
            helper.AddEntry(entry, qty);
        }
        else
        {
            helper.Cart.AcceptChanges();
        }
    }
Пример #22
0
        // Optional lab in Mod. D - create a WishList and inspection in CM + config -alteration
        public void AddToWishList(FashionVariation currentContent)
        {
            CartHelper wishList = new CartHelper(CartHelper.WishListName); // note the arg.

            wishList.AddEntry(currentContent.LoadEntry());
        }
Пример #23
0
    /// <summary>
    /// Handles the Click event of the PurchaseLink control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Web.UI.ImageClickEventArgs"/> instance containing the event data.</param>
    protected void BuyButton_Click(object sender, EventArgs e, Entry entry, ref bool reject)
    {
        CartHelper ch = new CartHelper(Cart.DefaultName);

        // Check if Entry Object is null.
        if (Entry != null)
        {
            // Add item to a cart.
            ch.AddEntry(this.Entry, Int32.Parse(QuantityList.Text));
        }

        // Get the checked related products and additional options.

        // Go through the list of Related Products.
        EntryAssociation[] RelatedProductsAssociations = this.RelatedProductsRepeater.DataSource as EntryAssociation[];
        if (RelatedProductsAssociations != null)
        {
            foreach (RepeaterItem item in this.RelatedProductsRepeater.Items)
            {
                CheckBox rpc = item.FindControl("RelatedProductsCheckbox") as CheckBox;
                if (rpc != null)
                {
                    if (rpc.Checked == true)
                    {
                        foreach (EntryAssociation rpa in RelatedProductsAssociations)
                        {
                            // Match against the Entry.ID set at data binding.
                            if (rpa.Entry.ID == rpc.Text)
                            {
                                ch.AddEntry(rpa.Entry, Int32.Parse(QuantityList.Text)); // Add just one.
                            }
                        }
                    }
                }
            }
        }

        // Go through the list of Additional Options.
        EntryAssociation[] AdditionalOptionsAssociations = this.AdditionalOptionsRepeater.DataSource as EntryAssociation[];
        if (AdditionalOptionsAssociations != null)
        {
            foreach (RepeaterItem item in this.AdditionalOptionsRepeater.Items)
            {
                CheckBox aoc = item.FindControl("AdditionalOptionsCheckbox") as CheckBox;
                if (aoc != null)
                {
                    if (aoc.Checked == true)
                    {
                        foreach (EntryAssociation aoa in AdditionalOptionsAssociations)
                        {
                            // Match against the Entry.ID set at data binding.
                            if (aoa.Entry.ID == aoc.Text)
                            {
                                ch.AddEntry(aoa.Entry, Int32.Parse(QuantityList.Text)); // Add as many as main product.
                            }
                        }
                    }
                }
            }
        }

        // Redirect to shopping cart.
        //Response.Redirect(NavigationManager.GetUrl("ShoppingCart"));
    }
Пример #24
0
    /// <summary>
    /// Handles the Command event of the WishListLink control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Web.UI.WebControls.CommandEventArgs"/> instance containing the event data.</param>
    public void WishlistLink_Command(object sender, CommandEventArgs e)
    {
        Entry variation = null;
        Entry product   = null;
        int   productId;

        if (String.Compare(e.CommandName, "AddToWishList") == 0)
        {
            string arg = e.CommandArgument as string;
            if (String.IsNullOrEmpty(arg))
            {
                Response.Redirect(Request.RawUrl);
                return;
            }

            CartHelper helper = new CartHelper(CartHelper.WishListName);

            bool alreadyExists = false;
            productId = Int32.Parse(arg);

            // Check if item exists
            foreach (LineItem item in helper.LineItems)
            {
                if (item.CatalogEntryId.Equals(productId))
                {
                    alreadyExists = true;
                    Response.Redirect(Request.RawUrl);
                    return;
                }
            }

            if (_ProductsToCompare != null && _ProductsToCompare.Length > 0)
            {
                foreach (Entry productTemp in _ProductsToCompare)
                {
                    if (productTemp.CatalogEntryId == productId)
                    {
                        product = productTemp;

                        if (product.EntryType.Equals("Variation") || product.EntryType.Equals("Package"))
                        {
                            variation = product;
                        }
                        else if (product.Entries.Entry != null && product.Entries.Entry.Length > 0)
                        {
                            variation = product.Entries.Entry[0];
                            break;
                        }
                    }
                }

                // if variation is found, add it to cart and redirect to product view page
                if (variation != null)
                {
                    if (!alreadyExists)
                    {
                        helper.AddEntry(variation);
                    }

                    Response.Redirect(Request.RawUrl);
                }
            }
            else
            {
                Response.Redirect(Request.RawUrl);
                return;
            }
        }
    }
Пример #25
0
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]         //the entire parameter must be serialized to a string (no individual raw POST values)
        public CartResponse Copy(string cartName, string newName, bool activate)
        {
            var response = new CartResponse();             //the response for the operation

            if (string.IsNullOrEmpty(newName))
            {
                newName = string.Format("Copy of {0}", cartName);
            }

            Guid userId = ProfileContext.Current.UserId;

            //make sure there isn't already a cart with the same name
            if (!CartNameIsValid(newName))
            {
                response.Message = "Invalid Wish List name! The Wish List name may only contain letters, numbers, spaces, and underscores";
                response.Status  = CartResponseStatus.ERROR;
            }
            else if (CartNameIsDuplicate(userId, newName))
            {
                response.Message = "Invalid Wish List name! There is already a Wish List with this name";
                response.Status  = CartResponseStatus.ERROR;
            }
            else
            {
                CartHelper originalCartHelper = new CartHelper(cartName, userId);

                //create the new cart
                Mediachase.Commerce.Orders.Cart cartToAdd = NWTD.Orders.Cart.CreateCart(ProfileContext.Current.Profile.Account, newName);

                //now, we'll need a CartHelper to start adding the lines
                CartHelper newCartHelper = new CartHelper(cartToAdd);

                //now add all the same line items to the new cart, copying any relevant metadata (gratis and quantity)
                foreach (LineItem lineItem in originalCartHelper.LineItems)
                {
                    //get the entry
                    Entry entry = CatalogContext.Current.GetCatalogEntry(lineItem.CatalogEntryId, new Mediachase.Commerce.Catalog.Managers.CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                    if (entry != null)
                    {
                        newCartHelper.AddEntry(entry, lineItem.Quantity);
                    }

                    //get the item we just added and set its gratis
                    LineItem addedItem = newCartHelper.LineItems.Single(li => li.CatalogEntryId == entry.ID);
                    addedItem["Gratis"] = lineItem["Gratis"];
                    //addedItem.ShippingAddressId = lineItem.ShippingAddressId;
                    newCartHelper.RunWorkflow("CartValidate");
                    cartToAdd.AcceptChanges();
                }

                //save the changes
                cartToAdd.AcceptChanges();

                if (activate)
                {
                    NWTD.Profile.ActiveCart = cartToAdd.Name;
                    response.Message        = "Wish List succesfully copied and made active";
                }
                else
                {
                    response.Message = "Wish List succesfully copied";
                }
            }
            return(response);
        }
Пример #26
0
        /// <summary>
        /// Handles the ItemCommand event of the CartItemsList control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param>
        protected void CartItemsList_ItemCommand(object sender, RepeaterCommandEventArgs e)
        {
            var lineItemId = int.Parse(e.CommandArgument.ToString());
            var lineItem   = WishListHelper.LineItems.FirstOrDefault(l => l.LineItemId == lineItemId);

            switch (e.CommandName)
            {
            case "AddToCart":
                var cart = new CartHelper(Cart.DefaultName);
                if (lineItem != null)
                {
                    var entry = CatalogContext.Current.GetCatalogEntry(lineItem.CatalogEntryId,
                                                                       new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo |
                                                                                                     CatalogEntryResponseGroup.ResponseGroup.Inventory));

                    if (entry != null)
                    {
                        string errorMessage;
                        if (!SampleStoreHelper.AllowAddToCart(cart.Cart, entry, false, lineItem.Quantity,
                                                              lineItem.WarehouseCode, out errorMessage))
                        {
                            return;
                        }

                        cart.AddEntry(entry, lineItem.Quantity, false, lineItem.WarehouseCode,
                                      new CartHelper[] { });
                        lineItem.Delete();
                    }
                }
                // If cart is empty, remove it from the database
                if (WishListHelper.IsEmpty)
                {
                    WishListHelper.Delete();
                }
                // Save changes to a wish list
                WishListHelper.Cart.AcceptChanges();
                cart.Cart.AcceptChanges();

                // Redirect to shopping cart
                Context.RedirectFast(GetUrl(Settings.CartPage));
                break;

            case "Remove":
                if (lineItem != null)
                {
                    // remove from wishlist
                    lineItem.Delete();
                }

                // If cart is empty, remove it from the database
                if (WishListHelper.IsEmpty)
                {
                    WishListHelper.Delete();
                }

                // Save changes to a wish list
                WishListHelper.Cart.AcceptChanges();

                BindData();
                break;
            }
        }
Пример #27
0
        private CartActionResult AddToCart(string name, LineItem lineItem)
        {
            CartHelper ch = new CartHelper(name);
            string messages = string.Empty;

            if (lineItem.Quantity < 1)
            {
                lineItem.Quantity = 1;
            }

            // Need entry for adding to cart
            var entry = CatalogContext.Current.GetCatalogEntry(lineItem.Code);
            ch.AddEntry(entry, lineItem.Quantity, false, new CartHelper[] { });

            // Need content for easier access to more information
            ContentReference itemLink = _referenceConverter.GetContentLink(entry.CatalogEntryId,
                CatalogContentType.CatalogEntry, 0);
            EntryContentBase entryContent = _contentLoader.Get<EntryContentBase>(itemLink);

            // Populate line item with as much as we can find
            if (string.IsNullOrEmpty(lineItem.ImageUrl))
            {
                lineItem.ImageUrl = entryContent.GetDefaultImage();
            }

            if (string.IsNullOrEmpty(lineItem.ArticleNumber))
            {
                lineItem.ArticleNumber = entry.ID;
            }

            lineItem.Name = TryGetDisplayName(entry);
            //lineItem.IsInventoryAllocated = true; // Will this be enough?

            AddCustomProperties(lineItem, ch.Cart);

            messages = RunWorkflowAndReturnFormattedMessage(ch.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);
            ch.Cart.AcceptChanges();

            // TODO: Always returns success, if we get warnings, we need to show them
            return new CartActionResult() { Success = true, Message = messages };
        }