コード例 #1
0
        internal BasketItem GetBasketItem(int index, Basket basket)
        {
            WishlistItem item       = this[index];
            BasketItem   basketItem = BasketItemDataSource.CreateForProduct(item.ProductId, item.Desired, item.OptionList, item.KitList);

            basketItem.BasketId = basket.BasketId;
            if (item.Product.UseVariablePrice)
            {
                basketItem.Price = item.Price;
                if (basketItem.Price < item.Product.MinimumPrice)
                {
                    basketItem.Price = item.Product.MinimumPrice;
                }
                if (basketItem.Price > item.Product.MaximumPrice)
                {
                    basketItem.Price = item.Product.MaximumPrice;
                }
            }
            basketItem.WishlistItemId = item.WishlistItemId;
            basketItem.LineMessage    = item.LineMessage;
            //COPY OVER ITEM INPUTS
            foreach (WishlistItemInput input in item.Inputs)
            {
                BasketItemInput cloneInput = new BasketItemInput();
                cloneInput.InputFieldId = input.InputFieldId;
                cloneInput.InputValue   = input.InputValue;
                basketItem.Inputs.Add(cloneInput);
            }
            return(basketItem);
        }
コード例 #2
0
        protected BasketItem GetBasketItem(string optionList, GridViewCommandEventArgs e)
        {
            //GET THE QUANTITY
            GridViewRow row          = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
            int         tempQuantity = GetControlValue(row, "Quantity", 1);

            if (tempQuantity < 1)
            {
                return(null);
            }
            if (tempQuantity > System.Int16.MaxValue)
            {
                tempQuantity = System.Int16.MaxValue;
            }

            //CREATE THE BASKET ITEM WITH GIVEN OPTIONS
            BasketItem basketItem = BasketItemDataSource.CreateForProduct(_ProductId, (short)tempQuantity, optionList, AlwaysConvert.ToList(",", _SelectedKitProducts));

            if (basketItem != null)
            {
                basketItem.Basket = AbleContext.Current.User.Basket;

                //ADD IN VARIABLE PRICE
                //if (_Product.UseVariablePrice) basketItem.Price = AlwaysConvert.ToDecimal(VariablePrice.Text);
                // COLLECT ANY ADDITIONAL INPUTS
                AbleCommerce.Code.ProductHelper.CollectProductTemplateInput(basketItem, this);
            }
            return(basketItem);
        }
コード例 #3
0
        public void ProcessRequest(HttpContext context)
        {
            HttpResponse Response = context.Response;
            //GET THE ORDER ID FROM THE URL
            int   orderId = AlwaysConvert.ToInt(context.Request.QueryString["o"]);
            Order order   = OrderDataSource.Load(orderId);

            if (order != null)
            {
                //MAKE SURE ORDER IS FOR CURRENT USER
                User user = AbleContext.Current.User;
                if (order.User != null && order.User.Id == user.Id)
                {
                    //CLEAR THE EXISTING BASKET
                    List <string>  basketMessages = new List <string>();
                    Basket         basket         = user.Basket;
                    IBasketService basketService  = AbleContext.Resolve <IBasketService>();
                    basketService.Clear(basket);
                    foreach (OrderItem item in order.Items)
                    {
                        if ((item.OrderItemType == OrderItemType.Product) && (!item.IsChildItem))
                        {
                            Product product = item.Product;
                            if ((product != null) && (product.Visibility != CommerceBuilder.Catalog.CatalogVisibility.Private))
                            {
                                BasketItem basketItem;
                                try
                                {
                                    basketItem = BasketItemDataSource.CreateForProduct(item.Product.Id, item.Quantity, item.OptionList, item.KitList);
                                    basketItem.IsSubscription = item.IsSubscription;
                                    if (!item.IsSubscription && item.Product != null)
                                    {
                                        basketItem.IsSubscription = item.Product.IsSubscription;
                                    }
                                    basketItem.Frequency     = item.Frequency;
                                    basketItem.FrequencyUnit = item.FrequencyUnit;
                                }
                                catch
                                {
                                    string itemName = item.Name;
                                    if (!string.IsNullOrEmpty(item.VariantName))
                                    {
                                        itemName += " (" + item.VariantName + ")";
                                    }
                                    basketMessages.Add("The item " + itemName + " is no longer available.");
                                    basketItem = null;
                                }
                                if (basketItem != null)
                                {
                                    //SEE IF A PRODUCT TEMPLATE IS ASSOCIATED
                                    foreach (ProductTemplate template in product.ProductTemplates)
                                    {
                                        if (template != null)
                                        {
                                            foreach (InputField inputField in template.InputFields)
                                            {
                                                if (!inputField.IsMerchantField)
                                                {
                                                    //COPY OVER ANY CUSTOMER INPUTS
                                                    BasketItemInput itemInput = new BasketItemInput();
                                                    itemInput.BasketItem = basketItem;
                                                    itemInput.InputField = inputField;
                                                    itemInput.InputValue = GetItemInputValue(item, inputField.Name);
                                                    basketItem.Inputs.Add(itemInput);
                                                }
                                            }
                                        }
                                    }
                                    if ((basketItem.OrderItemType == OrderItemType.Product) && (basketItem.Product.UseVariablePrice))
                                    {
                                        basketItem.Price = item.Price;
                                    }
                                    basketItem.Basket = basket;
                                    basket.Items.Add(basketItem);
                                    //WE HAVE TO SAVE THE BASKET IN CASE IT IS NOT YET CREATED
                                    basket.Save();
                                }
                            }
                        }
                    }
                    if (context.Session != null)
                    {
                        context.Session["BasketMessage"] = basketMessages;
                    }
                    Response.Redirect(NavigationHelper.GetBasketUrl());
                }
            }
            Response.Redirect(NavigationHelper.GetHomeUrl());
        }
コード例 #4
0
        private void DoAddToCart(int productId)
        {
            //GET THE PRODUCT ID FROM THE URL
            Product product = ProductDataSource.Load(productId);

            if (product != null)
            {
                string lastShoppingUrl = AbleCommerce.Code.NavigationHelper.GetLastShoppingUrl();
                if (product.HasChoices || product.UseVariablePrice)
                {
                    //CANT ADD DIRECTLY TO BASKET, SEND TO MORE INFO
                    Response.Redirect(product.NavigateUrl);
                }
                BasketItem basketItem = BasketItemDataSource.CreateForProduct(productId, 1);
                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;
                    basketItem.Basket = basket;
                    basket.Items.Add(basketItem);
                    basket.Save();

                    //Determine if there are associated Upsell products
                    if (AbleContext.Current.StoreMode == StoreMode.Standard && 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(Page))
                    {
                        Response.Redirect(AbleCommerce.Code.NavigationHelper.GetBasketUrl());
                    }
                }
            }
        }
コード例 #5
0
        private BasketItem GetBasketItem(int productId, short quantity)
        {
            BasketItem basketItem = BasketItemDataSource.CreateForProduct(productId, quantity);

            return(basketItem);
        }
コード例 #6
0
        protected BasketItem CreateBasketItem()
        {
            //GET THE PRODUCT ID
            int     productId = AlwaysConvert.ToInt(AddProductId.Value);
            Product product   = ProductDataSource.Load(productId);

            if (product == null)
            {
                return(null);
            }
            //GET THE QUANTITY
            short tempQuantity = AlwaysConvert.ToInt16(AddProductQuantity.Text);

            if (tempQuantity < 1)
            {
                return(null);
            }
            //RECALCULATE SELECTED KIT OPTIONS
            GetSelectedKitOptions(product);
            // DETERMINE THE OPTION LIST
            string optionList = ProductVariantDataSource.GetOptionList(productId, _SelectedOptions, false);

            //CREATE THE BASKET ITEM WITH GIVEN OPTIONS
            bool       calculateOneTimePrice = AlwaysConvert.ToBool(OptionalSubscription.SelectedValue, false);
            BasketItem basketItem            = BasketItemDataSource.CreateForProduct(productId, tempQuantity, optionList, AlwaysConvert.ToList(",", _SelectedKitProducts), _UserId, calculateOneTimePrice);

            if (basketItem != null)
            {
                //BASKET ID
                basketItem.BasketId = _Basket.Id;

                // PRODUCT PRICE FOR VARIABLE PRICE PRODUCT
                if (product.UseVariablePrice && !product.IsSubscription && !product.IsKit)
                {
                    basketItem.Price = AlwaysConvert.ToDecimal(AddProductVariablePrice.Text);
                }
                else
                {
                    basketItem.Price = AlwaysConvert.ToDecimal(AddProductPrice.Text);
                }

                if (product.IsSubscription)
                {
                    if (product.SubscriptionPlan.IsOptional)
                    {
                        basketItem.IsSubscription = !calculateOneTimePrice;
                    }
                    else
                    {
                        basketItem.IsSubscription = true;
                    }

                    if (basketItem.IsSubscription && product.SubscriptionPlan.IsRecurring)
                    {
                        basketItem.Frequency     = product.SubscriptionPlan.PaymentFrequencyType == PaymentFrequencyType.Optional ? AlwaysConvert.ToInt16(AutoDeliveryInterval.SelectedValue) : product.SubscriptionPlan.PaymentFrequency;
                        basketItem.FrequencyUnit = product.SubscriptionPlan.PaymentFrequencyUnit;
                    }
                    else if (basketItem.IsSubscription)
                    {
                        basketItem.Frequency     = product.SubscriptionPlan.PaymentFrequency;
                        basketItem.FrequencyUnit = product.SubscriptionPlan.PaymentFrequencyUnit;
                    }
                }


                // COLLECT ANY ADDITIONAL INPUTS
                AbleCommerce.Code.ProductHelper.CollectProductTemplateInput(basketItem, this);
            }
            return(basketItem);
        }