Esempio 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();
    }