Ejemplo n.º 1
0
    protected void uxAddToCartButton_Click(object sender, EventArgs e)
    {
        PromotionSelected promotion = new PromotionSelected(StoreContext.Culture, new StoreRetriever().GetCurrentStoreID());

        promotion.SetPromotionGroupID = PromotionGroupID;
        bool isSuccess = true;

        foreach (DataListItem item in uxList.Items)
        {
            if (item.FindControl("uxGroup") != null)
            {
                Mobile_Components_PromotionProductGroup group = (Mobile_Components_PromotionProductGroup)item.FindControl("uxGroup");
                if (group.IsSelectedProduct)
                {
                    string   productGroup = group.GetSelectedOption;
                    string[] groupInfo    = productGroup.Split(':');

                    IList <string> options = new List <string>();
                    foreach (string option in groupInfo[1].Split(','))
                    {
                        if (option.Trim() == "")
                        {
                            continue;
                        }
                        options.Add(option);
                    }
                    Product product = DataAccessContext.ProductRepository.GetOne(StoreContext.Culture, groupInfo[0], new StoreRetriever().GetCurrentStoreID());
                    promotion.AddSelectedPromotionItem(group.PromotionSubGroupID, product, options);
                }
                else
                {
                    isSuccess = false;
                }
            }
        }
        if (!isSuccess)
        {
            return;
        }

        // Check Inventory
        isSuccess = CheckOutOfStock(promotion.PromotionSelectedItems);
        if (!isSuccess)
        {
            return;
        }
        // Check Free Shipping
        isSuccess = PromotionSelected.CheckCanAddItemToCart(StoreContext.ShoppingCart, promotion);
        if (isSuccess)
        {
            PromotionSelected.AddPromotionItem(StoreContext.ShoppingCart, promotion, 1);
            Response.Redirect("ShoppingCart.aspx");
        }
        else
        {
            Response.Redirect("AddShoppingCartNotComplete.aspx?ProductID=" + promotion.GetPromotionGroup().PromotionGroupID);
        }
    }
    public void Show(PromotionSelected promotion, int quantity)
    {
        PromotionGroup promotionGroupSelected = promotion.GetPromotionGroup();
        Culture        culture         = StoreContext.Culture;
        string         productListText = "";

        foreach (PromotionSelectedItem item in promotion.PromotionSelectedItems)
        {
            productListText += "&nbsp;&nbsp;&ndash;&nbsp;&nbsp;" + item.Product.Locales[culture].Name + GenerateOptionName(culture, StoreContext.Currency, item) + " x " + item.GetPromotionProduct.Quantity.ToString() + "<BR>";
        }
        string name = promotionGroupSelected.Locales[culture].Name + "<BR>" + productListText;

        uxProductImage.ImageUrl       = "~/" + promotionGroupSelected.ImageFile;
        uxProductNameLink.NavigateUrl = UrlManager.GetPromotionUrl(promotionGroupSelected.PromotionGroupID, promotionGroupSelected.Locales[StoreContext.Culture].UrlName);
        uxProductNameLink.Text        = "<div class='ProductName'>" + name + "</div>";
        uxQuantityLabel.Text          = quantity.ToString();
        uxPriceLabel.Text             = StoreContext.Currency.FormatPrice(promotionGroupSelected.Price);
        uxMessage.Text = promotionGroupSelected.Name + "[$AddSuccess]";
        uxAddToCartPopup.Show();
    }
Ejemplo n.º 3
0
    private bool IsEnoughStock(out string message)
    {
        message = String.Empty;

        foreach (ICartItem item in StoreContext.ShoppingCart.GetCartItems())
        {
            if (!item.IsPromotion)
            {
                int productStock = item.Product.GetStock(item.Options.GetUseStockOptionItemIDs());
                int currentStock = productStock - item.Quantity;

                if (currentStock != DataAccessContext.Configurations.GetIntValue("OutOfStockValue"))
                {
                    if (CatalogUtilities.IsOutOfStock(currentStock, CheckUseInventory(item.ProductID)))
                    {
                        message += "<li>" + item.GetName(StoreContext.Culture, StoreContext.Currency);
                        if (DataAccessContext.Configurations.GetBoolValue("ShowQuantity"))
                        {
                            int displayStock = productStock - DataAccessContext.Configurations.GetIntValue("OutOfStockValue");
                            if (displayStock < 0)
                            {
                                displayStock = 0;
                            }

                            message += " ( available " + displayStock + " items )";
                        }
                        else
                        {
                            message += "</li>";
                        }
                    }
                }
            }
            else
            {
                CartItemPromotion cartItemPromotion = (CartItemPromotion)item;
                PromotionSelected promotionSelected = cartItemPromotion.PromotionSelected;
                foreach (PromotionSelectedItem selectedItem in promotionSelected.PromotionSelectedItems)
                {
                    Product  product         = selectedItem.Product;
                    string[] optionsUseStock = selectedItem.GetUseStockOptionItems().ToArray(typeof(string)) as string[];
                    int      productStock    = product.GetStock(optionsUseStock);
                    int      currentStock    = productStock - item.Quantity;
                    if (currentStock != DataAccessContext.Configurations.GetIntValue("OutOfStockValue"))
                    {
                        if (CatalogUtilities.IsOutOfStock(currentStock, CheckUseInventory(product.ProductID)))
                        {
                            message += "<li>" + item.GetName(StoreContext.Culture, StoreContext.Currency);
                            message += "</li>";
                        }
                    }
                }
            }
        }

        if (!String.IsNullOrEmpty(message))
        {
            message =
                "<p class=\"ErrorHeader\">[$StockError]</p>" +
                "<ul class=\"ErrorBody\">" + message + "</ul>";

            return(false);
        }
        else
        {
            return(true);
        }
    }
Ejemplo n.º 4
0
    private bool IsEnoughStock(out string message)
    {
        message = String.Empty;

        int rowIndex;

        for (rowIndex = 0; rowIndex < uxGrid.Rows.Count; rowIndex++)
        {
            GridViewRow row = uxGrid.Rows[rowIndex];
            if (row.RowType == DataControlRowType.DataRow)
            {
                ICartItem cartItem    = (ICartItem)StoreContext.ShoppingCart.FindCartItemByID((string)uxGrid.DataKeys[rowIndex]["CartItemID"]);
                bool      isPromotion = (bool)uxGrid.DataKeys[rowIndex]["IsPromotion"];
                string    productID   = uxGrid.DataKeys[rowIndex]["ProductID"].ToString();
                string    productName = ((Label)row.FindControl("uxNameLabel")).Text;
                int       quantity    = ConvertUtilities.ToInt32(((TextBox)row.FindControl("uxQuantityText")).Text);
                if (!isPromotion)
                {
                    Product product = DataAccessContext.ProductRepository.GetOne(StoreContext.Culture, productID, new StoreRetriever().GetCurrentStoreID());

                    OptionItemValueCollection options = (OptionItemValueCollection)uxGrid.DataKeys[rowIndex]["Options"];
                    int productStock = product.GetStock(options.GetUseStockOptionItemIDs());
                    int currentStock = productStock - quantity;
                    if (currentStock != DataAccessContext.Configurations.GetIntValue("OutOfStockValue"))
                    {
                        if (CatalogUtilities.IsOutOfStock(currentStock, CheckUseInventory(productID)))
                        {
                            message += "<li>" + productName;
                            if (DataAccessContext.Configurations.GetBoolValue("ShowQuantity"))
                            {
                                int displayStock = productStock - DataAccessContext.Configurations.GetIntValue("OutOfStockValue");
                                if (displayStock < 0)
                                {
                                    displayStock = 0;
                                }
                                message += " ( available " + displayStock + " items )";
                            }
                            else
                            {
                                message += "</li>";
                            }
                        }
                    }
                }
                else
                {
                    CartItemPromotion cartItemPromotion = (CartItemPromotion)cartItem;
                    PromotionSelected promotionSelected = cartItemPromotion.PromotionSelected;
                    foreach (PromotionSelectedItem item in promotionSelected.PromotionSelectedItems)
                    {
                        Product  product         = item.Product;
                        string[] optionsUseStock = item.GetUseStockOptionItems().ToArray(typeof(string)) as string[];
                        int      productStock    = product.GetStock(optionsUseStock);
                        int      currentStock    = productStock - quantity;
                        if (currentStock != DataAccessContext.Configurations.GetIntValue("OutOfStockValue"))
                        {
                            if (CatalogUtilities.IsOutOfStock(currentStock, CheckUseInventory(product.ProductID)))
                            {
                                message += "<li>" + productName;
                                message += "</li>";
                            }
                        }
                    }
                }
            }
        }

        if (!String.IsNullOrEmpty(message))
        {
            message =
                "<p class=\"ErrorHeader\">[$StockError]</p>" +
                "<ul class=\"ErrorBody\">" + message + "</ul>";

            return(false);
        }
        else
        {
            return(true);
        }
    }
Ejemplo n.º 5
0
    protected void uxAddToCartButton_Click(object sender, EventArgs e)
    {
        PromotionSelected promotion = new PromotionSelected(StoreContext.Culture, new StoreRetriever().GetCurrentStoreID());

        promotion.SetPromotionGroupID = PromotionGroupID;
        bool isSuccess = true;

        foreach (DataListItem item in uxList.Items)
        {
            if (item.FindControl("uxGroup") != null)
            {
                Components_PromotionProductGroup group = (Components_PromotionProductGroup)item.FindControl("uxGroup");
                if (group.IsSelectedProduct)
                {
                    string   productGroup = group.GetSelectedOption;
                    string[] groupInfo    = productGroup.Split(':');

                    IList <string> options = new List <string>();
                    foreach (string option in groupInfo[1].Split(','))
                    {
                        if (option.Trim() == "")
                        {
                            continue;
                        }
                        options.Add(option);
                    }
                    Product product = DataAccessContext.ProductRepository.GetOne(StoreContext.Culture, groupInfo[0], new StoreRetriever().GetCurrentStoreID());
                    promotion.AddSelectedPromotionItem(group.PromotionSubGroupID, product, options);
                }
                else
                {
                    isSuccess = false;
                }
            }
        }
        if (!isSuccess)
        {
            return;
        }

        // Check Inventory
        isSuccess = CheckOutOfStock(promotion.PromotionSelectedItems);
        if (!isSuccess)
        {
            Response.Redirect("AddShoppingCartNotComplete.aspx?ProductID=0&PromotionStock=1");
        }
        // Check Free Shipping
        isSuccess = CartItemPromotion.CheckCanAddItemToCart(StoreContext.ShoppingCart, promotion);
        if (isSuccess)
        {
            PromotionSelected.AddPromotionItem(StoreContext.ShoppingCart, promotion, 1);

            bool enableNotification = ConvertUtilities.ToBoolean(DataAccessContext.Configurations.GetValue("EnableAddToCartNotification", StoreContext.CurrentStore));
            if (UrlManager.IsMobileDevice(Request))
            {
                enableNotification = false;
            }
            if (enableNotification)
            {
                uxAddToCartNotification.Show(promotion, 1);
            }
            else
            {
                Response.Redirect("ShoppingCart.aspx");
            }
        }
        else
        {
            Response.Redirect("AddShoppingCartNotComplete.aspx?ProductID=0&FreeShiping=1");
        }
    }