コード例 #1
0
        CartActionResponse UpdateCartFromViewModel(MinicartViewModel cartViewModel, Customer customer, CartTypeEnum cartType)
        {
            if (cartViewModel.CartItems == null)
            {
                return(null);
            }

            var messages = new List <CartActionMessage>();
            CartActionResponse response = null;

            foreach (var cartItem in cartViewModel.CartItems)
            {
                // Is this a Recurring Interval (Variant) change only?
                if (cartItem.RecurringVariantId != 0 &&
                    cartItem.VariantId != cartItem.RecurringVariantId &&
                    AppLogic.AppConfigBool("AllowRecurringFrequencyChangeInCart"))                        // Update Recurring Interval (Variant)
                {
                    response = CartActionProvider.ReplaceRecurringIntervalVariantInCart(
                        customer: customer,
                        cartType: cartType,
                        shoppingCartRecId: cartItem.Id,
                        oldVariantId: cartItem.VariantId,
                        newVariantId: cartItem.RecurringVariantId);
                }
                else                 // Perform regular Qty Update
                {
                    response = CartActionProvider.UpdateItemQuantityInCart(new UpdateQuantityContext()
                    {
                        Customer          = customer,
                        CartType          = cartType,
                        ShoppingCartRecId = cartItem.Id,
                        Quantity          = cartItem.Quantity
                    });
                }

                if (response.Status != CartActionStatus.Success)
                {
                    return(response);
                }

                messages.AddRange(response.Messages.ToList());
            }

            return(new CartActionResponse(
                       updatedCart: response.UpdatedCart
                       ?? CachedShoppingCartProvider.Get(customer, cartType, AppLogic.StoreID()),
                       status: CartActionStatus.Success,
                       messages: messages));
        }
コード例 #2
0
        AjaxAddToCartData GetAddToCartData(CartActionResponse response)
        {
            switch (response.Status)
            {
            case CartActionStatus.NotAllowed:
                return(new AjaxAddToCartData(
                           status: AjaxNoticeType.failure.ToString()
                           ));

            case CartActionStatus.RequiresLogin:
                return(new AjaxAddToCartData(
                           status: AjaxNoticeType.failure.ToString(),
                           messages: new[]
                {
                    new AjaxNotice(
                        message: "In order to create a wishlist, you will need to register now and create an account on the site.",
                        type: AjaxNoticeType.failure)
                }));

            case CartActionStatus.ValidationErrors:
                return(new AjaxAddToCartData(
                           status: AjaxNoticeType.failure.ToString(),
                           messages: response.Messages
                           .Select(n => n.ConvertToAjaxNotice())
                           ));

            default:
                return(new AjaxAddToCartData(
                           status: AjaxNoticeType.failure.ToString(),
                           messages: new[]
                {
                    new AjaxNotice(
                        message: "An error occurred attempting to add an item to the cart.",
                        type: AjaxNoticeType.failure)
                }
                           ));
            }
        }
コード例 #3
0
        AjaxAddToCartData GetAddToCartData(CartActionResponse response)
        {
            switch (response.Status)
            {
            case CartActionStatus.NotAllowed:
                return(new AjaxAddToCartData(
                           status: AjaxNoticeType.failure.ToString()
                           ));

            case CartActionStatus.RequiresLogin:
                return(new AjaxAddToCartData(
                           status: AjaxNoticeType.failure.ToString(),
                           messages: new[]
                {
                    new AjaxNotice(
                        message: AppLogic.GetString("signin.aspx.27"),
                        type: AjaxNoticeType.failure)
                }));

            case CartActionStatus.ValidationErrors:
                return(new AjaxAddToCartData(
                           status: AjaxNoticeType.failure.ToString(),
                           messages: response.Messages
                           .Select(n => n.ConvertToAjaxNotice())
                           ));

            default:
                return(new AjaxAddToCartData(
                           status: AjaxNoticeType.failure.ToString(),
                           messages: new[]
                {
                    new AjaxNotice(
                        message: "An error occurred attempting to add an item to the cart.",
                        type: AjaxNoticeType.failure)
                }
                           ));
            }
        }