protected void rptVariants_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var productVariant         = e.Item.DataItem as ProductVariant;
                var pnlDownloadSample      = e.Item.FindControl("pnlDownloadSample") as Panel;
                var hlDownloadSample       = e.Item.FindControl("hlDownloadSample") as HyperLink;
                var iProductVariantPicture = e.Item.FindControl("iProductVariantPicture") as Image;
                var pnlStockAvailablity    = e.Item.FindControl("pnlStockAvailablity") as Panel;
                var lblStockAvailablity    = e.Item.FindControl("lblStockAvailablity") as Label;
                var phSKU = e.Item.FindControl("phSKU") as PlaceHolder;
                var lSKU  = e.Item.FindControl("lSKU") as Literal;
                var txtCustomerEnteredPrice = e.Item.FindControl("txtCustomerEnteredPrice") as DecimalTextBox;
                var txtQuantity             = e.Item.FindControl("txtQuantity") as NumericTextBox;
                var btnAddToCart            = e.Item.FindControl("btnAddToCart") as Button;
                var btnAddToWishlist        = e.Item.FindControl("btnAddToWishlist") as Button;

                if (iProductVariantPicture != null)
                {
                    var    productVariantPicture = productVariant.Picture;
                    string pictureUrl            = PictureManager.GetPictureUrl(productVariantPicture, SettingManager.GetSettingValueInteger("Media.Product.VariantImageSize", 125), false);
                    if (String.IsNullOrEmpty(pictureUrl))
                    {
                        iProductVariantPicture.Visible = false;
                    }
                    else
                    {
                        iProductVariantPicture.ImageUrl = pictureUrl;
                    }
                    iProductVariantPicture.ToolTip       = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), productVariant.LocalizedName);
                    iProductVariantPicture.AlternateText = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), productVariant.LocalizedName);
                }

                btnAddToWishlist.Visible = SettingManager.GetSettingValueBoolean("Common.EnableWishlist");

                //stock
                if (pnlStockAvailablity != null && lblStockAvailablity != null)
                {
                    string stockMessage = PriceHelper.FormatStockMessage(productVariant);
                    if (!String.IsNullOrEmpty(stockMessage))
                    {
                        lblStockAvailablity.Text = stockMessage;
                    }
                    else
                    {
                        pnlStockAvailablity.Visible = false;
                    }
                }

                //sku
                if (SettingManager.GetSettingValueBoolean("Display.Products.ShowSKU") &&
                    !String.IsNullOrEmpty(productVariant.SKU))
                {
                    phSKU.Visible = true;
                    lSKU.Text     = Server.HtmlEncode(productVariant.SKU);
                }
                else
                {
                    phSKU.Visible = false;
                }

                //price entered by a customer
                if (productVariant.CustomerEntersPrice)
                {
                    int minimumCustomerEnteredPrice = Convert.ToInt32(Math.Ceiling(CurrencyManager.ConvertCurrency(productVariant.MinimumCustomerEnteredPrice, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency)));
                    int maximumCustomerEnteredPrice = Convert.ToInt32(Math.Truncate(CurrencyManager.ConvertCurrency(productVariant.MaximumCustomerEnteredPrice, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency)));
                    txtCustomerEnteredPrice.Visible           = true;
                    txtCustomerEnteredPrice.ValidationGroup   = string.Format("ProductVariant{0}", productVariant.ProductVariantId);
                    txtCustomerEnteredPrice.Value             = minimumCustomerEnteredPrice;
                    txtCustomerEnteredPrice.MinimumValue      = minimumCustomerEnteredPrice.ToString();
                    txtCustomerEnteredPrice.MaximumValue      = maximumCustomerEnteredPrice.ToString();
                    txtCustomerEnteredPrice.RangeErrorMessage = string.Format(GetLocaleResourceString("Products.CustomerEnteredPrice.Range"), minimumCustomerEnteredPrice, maximumCustomerEnteredPrice);
                }
                else
                {
                    txtCustomerEnteredPrice.Visible = false;
                }

                //buttons
                if (!productVariant.DisableBuyButton)
                {
                    txtQuantity.ValidationGroup      = string.Format("ProductVariant{0}", productVariant.ProductVariantId);
                    btnAddToCart.ValidationGroup     = string.Format("ProductVariant{0}", productVariant.ProductVariantId);
                    btnAddToWishlist.ValidationGroup = string.Format("ProductVariant{0}", productVariant.ProductVariantId);

                    txtQuantity.Value = productVariant.OrderMinimumQuantity;
                }
                else
                {
                    txtQuantity.Visible      = false;
                    btnAddToCart.Visible     = false;
                    btnAddToWishlist.Visible = false;
                }

                //sample downloads
                if (pnlDownloadSample != null && hlDownloadSample != null)
                {
                    if (productVariant.IsDownload && productVariant.HasSampleDownload)
                    {
                        pnlDownloadSample.Visible    = true;
                        hlDownloadSample.NavigateUrl = DownloadManager.GetSampleDownloadUrl(productVariant);
                    }
                    else
                    {
                        pnlDownloadSample.Visible = false;
                    }
                }

                //final check - hide prices for non-registered customers
                if (!SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                    (NopContext.Current.User != null &&
                     !NopContext.Current.User.IsGuest))
                {
                    //
                }
                else
                {
                    txtCustomerEnteredPrice.Visible = false;
                    txtQuantity.Visible             = false;
                    btnAddToCart.Visible            = false;
                    btnAddToWishlist.Visible        = false;
                }
            }
        }
示例#2
0
        protected void BindProductVariantInfo(ProductVariant productVariant)
        {
            btnAddToWishlist.Visible = SettingManager.GetSettingValueBoolean("Common.EnableWishlist");

            //sku
            if (SettingManager.GetSettingValueBoolean("Display.Products.ShowSKU") &&
                !String.IsNullOrEmpty(productVariant.SKU))
            {
                phSKU.Visible = true;
                lSKU.Text     = Server.HtmlEncode(productVariant.SKU);
            }
            else
            {
                phSKU.Visible = false;
            }

            ctrlTierPrices.ProductVariantId         = productVariant.ProductVariantId;
            ctrlProductAttributes.ProductVariantId  = productVariant.ProductVariantId;
            ctrlGiftCardAttributes.ProductVariantId = productVariant.ProductVariantId;
            ctrlProductPrice.ProductVariantId       = productVariant.ProductVariantId;

            //stock
            string stockMessage = PriceHelper.FormatStockMessage(productVariant);

            if (!String.IsNullOrEmpty(stockMessage))
            {
                lblStockAvailablity.Text = stockMessage;
            }
            else
            {
                pnlStockAvailablity.Visible = false;
            }

            //price entered by a customer
            if (productVariant.CustomerEntersPrice)
            {
                int minimumCustomerEnteredPrice = Convert.ToInt32(Math.Ceiling(CurrencyManager.ConvertCurrency(productVariant.MinimumCustomerEnteredPrice, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency)));
                int maximumCustomerEnteredPrice = Convert.ToInt32(Math.Truncate(CurrencyManager.ConvertCurrency(productVariant.MaximumCustomerEnteredPrice, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency)));
                txtCustomerEnteredPrice.Visible           = true;
                txtCustomerEnteredPrice.ValidationGroup   = string.Format("ProductVariant{0}", productVariant.ProductVariantId);
                txtCustomerEnteredPrice.Value             = minimumCustomerEnteredPrice;
                txtCustomerEnteredPrice.MinimumValue      = minimumCustomerEnteredPrice.ToString();
                txtCustomerEnteredPrice.MaximumValue      = maximumCustomerEnteredPrice.ToString();
                txtCustomerEnteredPrice.RangeErrorMessage = string.Format(GetLocaleResourceString("Products.CustomerEnteredPrice.Range"), minimumCustomerEnteredPrice, maximumCustomerEnteredPrice);
            }
            else
            {
                txtCustomerEnteredPrice.Visible = false;
            }

            //buttons
            if (!productVariant.DisableBuyButton)
            {
                txtQuantity.ValidationGroup      = string.Format("ProductVariant{0}", productVariant.ProductVariantId);
                btnAddToCart.ValidationGroup     = string.Format("ProductVariant{0}", productVariant.ProductVariantId);
                btnAddToWishlist.ValidationGroup = string.Format("ProductVariant{0}", productVariant.ProductVariantId);

                txtQuantity.Value = productVariant.OrderMinimumQuantity;
            }
            else
            {
                txtQuantity.Visible      = false;
                btnAddToCart.Visible     = false;
                btnAddToWishlist.Visible = false;
            }

            //samle downlaods
            if (pnlDownloadSample != null && hlDownloadSample != null)
            {
                if (productVariant.IsDownload && productVariant.HasSampleDownload)
                {
                    pnlDownloadSample.Visible    = true;
                    hlDownloadSample.NavigateUrl = DownloadManager.GetSampleDownloadUrl(productVariant);
                }
                else
                {
                    pnlDownloadSample.Visible = false;
                }
            }

            //final check - hide prices for non-registered customers
            if (!SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                (NopContext.Current.User != null &&
                 !NopContext.Current.User.IsGuest))
            {
                //
            }
            else
            {
                txtCustomerEnteredPrice.Visible = false;
                txtQuantity.Visible             = false;
                btnAddToCart.Visible            = false;
                btnAddToWishlist.Visible        = false;
            }
        }