コード例 #1
0
        protected int GetNotificationsCount(object dataItem)
        {
            ProductInventoryDetail detail = (ProductInventoryDetail)dataItem;

            if (detail.ProductVariantId > 0)
            {
                return(RestockNotifyDataSource.CountForProductVariant(detail.ProductVariantId));
            }
            else
            {
                return(RestockNotifyDataSource.CountForProduct(detail.ProductId));
            }
        }
コード例 #2
0
        /// <summary>
        /// Load product variants in the id list
        /// </summary>
        /// <param name="idList">List of product variant ids</param>
        private void ParseProductVariantIdList(string idList)
        {
            // VALIDATE THE INPUT
            if (string.IsNullOrEmpty(idList))
            {
                throw new ArgumentNullException("idList");
            }
            if (!Regex.IsMatch(idList, "^\\d+(,\\d+)*$"))
            {
                throw new ArgumentException("Id list can only be a comma delimited list of integer.", "idList");
            }


            // there should be a single id
            _RestockNotifyList = RestockNotifyDataSource.LoadForProductVariant(AlwaysConvert.ToInt(idList));
        }
コード例 #3
0
        private static void RestockNotify(bool sendEmails, Product product, ProductVariant variant)
        {
            // send emails
            try
            {
                IList <RestockNotify> list = null;
                if (variant != null)
                {
                    list = RestockNotifyDataSource.LoadForProductVariant(variant.Id);
                }
                else
                {
                    list = RestockNotifyDataSource.LoadForProduct(product.Id);
                }

                foreach (RestockNotify notification in list)
                {
                    // load email template and send
                    EmailTemplate emailTemplate = EmailTemplateDataSource.Load(AbleContext.Current.Store.Settings.InventoryRestockNotificationEmailTemplateId);
                    if (emailTemplate != null)
                    {
                        emailTemplate.Parameters["recipient"] = notification.Email;
                        emailTemplate.Parameters["product"]   = product;
                        emailTemplate.Parameters["variant"]   = variant;
                        emailTemplate.Parameters["store"]     = AbleContext.Current.Store;

                        emailTemplate.Send(true);
                    }
                }

                // remove records
                list.DeleteAll();
            }
            catch (Exception ex)
            {
                Logger.Error("Error sending restock notification email", ex);
            }
        }
コード例 #4
0
        protected string GetLastSent(object dataItem)
        {
            ProductInventoryDetail detail = (ProductInventoryDetail)dataItem;
            IList <RestockNotify>  list   = RestockNotifyDataSource.LoadForProduct(detail.ProductId);

            if (list != null)
            {
                DateTime lastDate = DateTime.MinValue;
                foreach (RestockNotify notify in list)
                {
                    if (notify.LastSentDate > DateTime.MinValue && notify.LastSentDate > lastDate)
                    {
                        lastDate = notify.LastSentDate;
                    }
                }

                if (lastDate > DateTime.MinValue)
                {
                    return(lastDate.ToShortDateString());
                }
            }

            return(string.Empty);
        }
コード例 #5
0
        protected void VariantGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string optionList;

            if (e.CommandName.Equals("AddToBasket"))
            {
                optionList = e.CommandArgument.ToString();
                ProductVariant variant = _VariantManager.GetVariantFromOptions(optionList);
                if (variant != null)
                {
                    BasketItem basketItem = GetBasketItem(optionList, e);
                    if (basketItem != null)
                    {
                        // DETERMINE IF THE LICENSE AGREEMENT MUST BE REQUESTED
                        IList <LicenseAgreement> basketItemLicenseAgreements = new List <LicenseAgreement>();
                        basketItemLicenseAgreements.BuildCollection(basketItem, LicenseAgreementMode.OnAddToBasket);
                        if ((basketItemLicenseAgreements.Count > 0))
                        {
                            // THESE AGREEMENTS MUST BE ACCEPTED TO ADD TO CART
                            List <BasketItem> basketItems = new List <BasketItem>();
                            basketItems.Add(basketItem);
                            string guidKey = Guid.NewGuid().ToString("N");
                            Cache.Add(guidKey, basketItems, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0), System.Web.Caching.CacheItemPriority.NotRemovable, null);
                            string acceptUrl  = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("~/Basket.aspx"));
                            string declineUrl = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Page.ResolveUrl(_Product.NavigateUrl)));
                            Response.Redirect("~/BuyWithAgreement.aspx?Items=" + guidKey + "&AcceptUrl=" + acceptUrl + "&DeclineUrl=" + declineUrl);
                        }

                        //ADD ITEM TO BASKET
                        Basket basket = AbleContext.Current.User.Basket;
                        basket.Items.Add(basketItem);
                        basket.Save();

                        //Determine if there are associated Upsell products
                        if (basketItem.Product.GetUpsellProducts(basket).Count > 0)
                        {
                            //redirect to upsell page
                            string returnUrl = AbleCommerce.Code.NavigationHelper.GetEncodedReturnUrl();
                            Response.Redirect("~/ProductAccessories.aspx?ProductId=" + basketItem.Product.Id + "&ReturnUrl=" + returnUrl);
                        }

                        // IF BASKET HAVE SOME VALIDATION PROBLEMS MOVE TO BASKET PAGE
                        IBasketService     service  = AbleContext.Resolve <IBasketService>();
                        ValidationResponse response = service.Validate(basket);
                        if (!response.Success)
                        {
                            Session["BasketMessage"] = response.WarningMessages;
                            Response.Redirect(AbleCommerce.Code.NavigationHelper.GetBasketUrl());
                        }

                        //IF THERE IS NO REGISTERED BASKET CONTROL, WE MUST GO TO BASKET PAGE
                        if (!AbleCommerce.Code.PageHelper.HasBasketControl(this.Page))
                        {
                            Response.Redirect(AbleCommerce.Code.NavigationHelper.GetBasketUrl());
                        }
                    }
                }
            }
            if (e.CommandName.Equals("AddToWishlist"))
            {
                optionList = e.CommandArgument.ToString();
                ProductVariant variant = _VariantManager.GetVariantFromOptions(optionList);
                if (variant != null)
                {
                    BasketItem wishlistItem = GetBasketItem(optionList, e);
                    if (wishlistItem != null)
                    {
                        Wishlist wishlist = AbleContext.Current.User.PrimaryWishlist;
                        wishlist.WishlistItems.Add(wishlistItem);
                        wishlist.Save();
                        Response.Redirect("~/Members/MyWishlist.aspx");
                    }
                }
            }

            else if (e.CommandName.Equals("NotifyMe"))
            {
                HtmlTableRow row = (HtmlTableRow)((Control)e.CommandSource).Parent.Parent;
                optionList = e.CommandArgument.ToString();
                string         email             = GetInputControlValue(row, "EmailText");
                Label          subscribedMessage = (Label)PageHelper.RecursiveFindControl(row, "messageLabel");
                LinkButton     notifyLink        = (LinkButton)PageHelper.RecursiveFindControl(row, "NotificationLink");
                ProductVariant variant           = _VariantManager.GetVariantFromOptions(optionList);

                if (RestockNotifyDataSource.LoadVariantForEmail(variant.Id, email) == null)
                {
                    RestockNotify notification = new RestockNotify(_Product, variant, email);
                    notification.Save();

                    subscribedMessage.Text    = string.Format(subscribedMessage.Text, email);
                    subscribedMessage.Visible = true;
                    notifyLink.Visible        = false;
                }
                else if (!string.IsNullOrEmpty(email))
                {
                    subscribedMessage.Text    = string.Format(subscribedMessage.Text, email);
                    subscribedMessage.Visible = true;
                    notifyLink.Visible        = false;
                }
            }
        }