private void AddItemToShoppingCart()
    {
        OptionItemValueCollection     selectedOptions = uxOptionGroupDetails.GetSelectedOptions();
        ProductKitItemValueCollection selectedKits    = uxProductKitGroupDetails.GetSelectedProductKitItems();
        CartItemGiftDetails           giftDetails     = CreateGiftDetails();

        decimal customPrice = decimal.Parse(uxEnterAmountText.Text);

        customPrice = decimal.Divide(customPrice, Convert.ToDecimal(StoreContext.Currency.ConversionRate));


        CartAddItemService addToCartService = new CartAddItemService(
            StoreContext.Culture, StoreContext.ShoppingCart);
        int    currentStock;
        string errorOptionName;
        bool   stockOK = addToCartService.AddToCart(
            CurrentProduct,
            selectedOptions,
            selectedKits,
            ConvertUtilities.ToInt32(uxQuantityText.Text),
            giftDetails,
            customPrice,
            out errorOptionName,
            out currentStock);


        if (stockOK)
        {
            Response.Redirect("ShoppingCart.aspx");
        }
        else
        {
            DisplayOutOfStockError(currentStock, errorOptionName);
        }
    }
Example #2
0
    private void AddItemToShoppingCart(DataListItem item, out string errorMessage)
    {
        Components_OptionGroupDetails uxOptionGroupDetails =
            (Components_OptionGroupDetails)item.FindControl("uxOptionGroupDetails");
        Components_GiftCertificateDetails uxGiftCertificateDetails =
            (Components_GiftCertificateDetails)item.FindControl("uxGiftCertificateDetails");

        TextBox uxEnterAmountText = (TextBox)item.FindControl("uxEnterAmountText");
        TextBox uxQuantityText    = (TextBox)item.FindControl("uxQuantityText");
        decimal customPrice       = decimal.Divide(decimal.Parse(uxEnterAmountText.Text), Convert.ToDecimal(StoreContext.Currency.ConversionRate));


        CartAddItemService addToCartService = new CartAddItemService(
            StoreContext.Culture, StoreContext.ShoppingCart);

        int    currentStock;
        string errorOptionName;
        bool   stockOK = addToCartService.AddToCart(
            CurrentProduct,
            uxOptionGroupDetails.GetSelectedOptions(),
            ProductKitItemValueCollection.Null,
            ConvertUtilities.ToInt32(uxQuantityText.Text),
            uxGiftCertificateDetails.GetCartItemGiftDetails(),
            customPrice,
            out errorOptionName,
            out currentStock);


        if (stockOK)
        {
            errorMessage = String.Empty;

            bool enableNotification = ConvertUtilities.ToBoolean(DataAccessContext.Configurations.GetValue("EnableAddToCartNotification", StoreContext.CurrentStore));
            if (UrlManager.IsMobileDevice(Request))
            {
                enableNotification = false;
            }
            if (enableNotification)
            {
                uxAddToCartNotification.Show(CurrentProduct, ConvertUtilities.ToInt32(uxQuantityText.Text), customPrice, uxGiftCertificateDetails.GetCartItemGiftDetails(), uxOptionGroupDetails.GetSelectedOptions(), ProductKitItemValueCollection.Null);
                uxAddtoCartUpdate.Update();
            }
            else
            {
                Response.Redirect("ShoppingCart.aspx");
            }
        }
        else
        {
            DisplayOutOfStockError(currentStock, errorOptionName, out errorMessage);
        }
    }
Example #3
0
    private void AddItemToShoppingCart()
    {
        OptionItemValueCollection     selectedOptions = uxOptionGroupDetails.GetSelectedOptions();
        ProductKitItemValueCollection selectedKits    = uxProductKitGroupDetails.GetSelectedProductKitItems();
        CartItemGiftDetails           giftDetails     = CreateGiftDetails();

        decimal customPrice = decimal.Parse(uxEnterAmountText.Text);

        customPrice = decimal.Divide(customPrice, Convert.ToDecimal(StoreContext.Currency.ConversionRate));

        CartAddItemService addToCartService = new CartAddItemService(
            StoreContext.Culture, StoreContext.ShoppingCart);
        int    currentStock;
        string errorOptionName;
        bool   stockOK = addToCartService.AddToCart(
            CurrentProduct,
            selectedOptions,
            selectedKits,
            ConvertUtilities.ToInt32(uxQuantityText.Text),
            giftDetails,
            customPrice,
            out errorOptionName,
            out currentStock);


        if (stockOK)
        {
            bool enableNotification = ConvertUtilities.ToBoolean(DataAccessContext.Configurations.GetValue("EnableAddToCartNotification", StoreContext.CurrentStore));
            if (UrlManager.IsMobileDevice(Request))
            {
                enableNotification = false;
            }
            if (enableNotification)
            {
                uxAddToCartNotification.Show(CurrentProduct, ConvertUtilities.ToInt32(uxQuantityText.Text), customPrice, giftDetails, selectedOptions, selectedKits);
            }
            else
            {
                Response.Redirect("ShoppingCart.aspx");
            }
        }
        else
        {
            DisplayOutOfStockError(currentStock, errorOptionName);
        }
    }
    public bool UpdateCartItem(bool isSubscriptionable, out string errMsg)
    {
        errMsg = String.Empty;
        if (!VerifyValidInput(out errMsg))
        {
            if (!String.IsNullOrEmpty(errMsg))
            {
                DisplayErrorMessage(errMsg);
                return(false);
            }
        }

        //string errMsg;
        if (!VerifyQuantity(out errMsg))
        {
            DisplayErrorMessage(errMsg);
            return(false);
        }
        if (!IsMatchQuantity())
        {
            return(false);
        }

        ICartItem item = StoreContext.ShoppingCart.FindCartItemByID(CartItemID);
        OptionItemValueCollection selectedOptions = uxProductOptionGroupDetails.GetSelectedOptions();
        CartItemGiftDetails       giftDetails     = CreateGiftDetails();

        Currency currency   = DataAccessContext.CurrencyRepository.GetOne(CurrencyCode);
        decimal  enterPrice = ConvertUtilities.ToDecimal(currency.FormatPriceWithOutSymbolInvert(ConvertUtilities.ToDecimal(uxEnterAmountText.Text)));

        if (enterPrice == item.Product.GetProductPrice(StoreID).Price)
        {
            enterPrice = 0;
        }

        decimal customPrice = 0;

        if (item.Product.IsCustomPrice)
        {
            customPrice = ConvertUtilities.ToDecimal(currency.FormatPriceWithOutSymbolInvert(ConvertUtilities.ToDecimal(uxEnterAmountText.Text)));
        }

        int    currentStock;
        string errorOptionName;

        StoreContext.ShoppingCart.DeleteItem(CartItemID);

        CartAddItemService addToCartService = new CartAddItemService(
            StoreContext.Culture, StoreContext.ShoppingCart);
        bool stockOK = addToCartService.AddToCartByAdmin(
            item.Product,
            selectedOptions,
            ConvertUtilities.ToInt32(uxQuantityText.Text),
            giftDetails,
            customPrice,
            enterPrice,
            StoreID,
            out errorOptionName,
            out currentStock,
            isSubscriptionable);

        if (stockOK)
        {
            return(true);
        }
        else
        {
            errMsg = DisplayOutOfStockError(currentStock, errorOptionName);

            return(false);
        }
    }
    private bool ReOrderToCart(Product product, OrderItem orderItem, string optionItemIDs, ProductKitItemValueCollection itemCollection)
    {
        string errorCurrentStock  = string.Empty;
        int    currentStock       = 0;
        bool   isAddToCartSuccess = false;

        OptionItemValueCollection optionCollection = new OptionItemValueCollection(StoreContext.Culture, optionItemIDs, product.ProductID);
        CartItemGiftDetails       giftDetails      = new CartItemGiftDetails();

        if (product.IsGiftCertificate)
        {
            GiftCertificateProduct giftProduct = (GiftCertificateProduct)product;

            IList <GiftCertificate> giftCertificateList = DataAccessContext.GiftCertificateRepository.GetAllByOrderID(orderItem.OrderID);

            foreach (GiftCertificate giftCertificate in giftCertificateList)
            {
                if (orderItem.OrderItemID == giftCertificate.OrderItemID)
                {
                    giftDetails = new CartItemGiftDetails(
                        giftCertificate.Recipient,
                        giftCertificate.PersonalNote,
                        giftCertificate.NeedPhysical,
                        giftCertificate.GiftValue);
                }
            }

            if (giftProduct.GiftAmount == 0)
            {
                giftProduct.GiftAmount = orderItem.UnitPrice;
            }

            product = (Product)giftProduct;

            CartAddItemService addToCartService = new CartAddItemService(
                StoreContext.Culture, StoreContext.ShoppingCart);
            isAddToCartSuccess = addToCartService.AddToCart(
                product,
                optionCollection,
                itemCollection,
                orderItem.Quantity,
                giftDetails,
                0,
                out errorCurrentStock,
                out currentStock);
        }
        else if (product.IsCustomPrice)
        {
            CartAddItemService addToCartService = new CartAddItemService(
                StoreContext.Culture, StoreContext.ShoppingCart);
            isAddToCartSuccess = addToCartService.AddToCart(
                product,
                optionCollection,
                itemCollection,
                GetProductQuantity(product, orderItem),
                giftDetails,
                orderItem.UnitPrice,
                out errorCurrentStock,
                out currentStock);
        }
        else
        {
            CartAddItemService addToCartService = new CartAddItemService(
                StoreContext.Culture, StoreContext.ShoppingCart);
            isAddToCartSuccess = addToCartService.AddToCart(
                product,
                optionCollection,
                itemCollection,
                GetProductQuantity(product, orderItem),
                giftDetails,
                0,
                out errorCurrentStock,
                out currentStock);
        }

        if (!isAddToCartSuccess)
        {
            StoreContext.ClearCheckoutSession();
            string message = "<p class=\"ErrorHeader\">[$StockError]</p>";

            ErrorMessage(message);
            return(false);
        }

        return(true);
    }