コード例 #1
0
        private void BindData()
        {
            if (product != null)
            {
                string productURL = SEOHelper.GetProductUrl(product.ProductId);

                // product name
                hpProductName.Text        = product.Name;
                hpProductName.NavigateUrl = productURL;

                // view more
                hlViewMore.NavigateUrl = productURL;

                #region product price
                var productVariantCollection = ProductManager.GetProductVariantsByProductId(product.ProductId);
                if (productVariantCollection.Count > 0)
                {
                    if (!(productVariantCollection.Count > 1))
                    {
                        var productVariant = productVariantCollection[0];

                        if (!SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                            (NopContext.Current.User != null &&
                             !NopContext.Current.User.IsGuest))
                        {
                            if (productVariant.CustomerEntersPrice)
                            {
                                lblPrice.Visible = false;
                            }
                            else
                            {
                                decimal oldPriceBase = TaxManager.GetPrice(productVariant, productVariant.OldPrice);
                                decimal finalPriceWithoutDiscountBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));

                                decimal oldPrice = CurrencyManager.ConvertCurrency(oldPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                                decimal finalPriceWithoutDiscount = CurrencyManager.ConvertCurrency(finalPriceWithoutDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                                if (finalPriceWithoutDiscountBase != oldPriceBase && oldPriceBase != decimal.Zero)
                                {
                                    lblPrice.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount, false, false);
                                }
                                else
                                {
                                    lblPrice.Text = PriceHelper.FormatPrice(finalPriceWithoutDiscount, false, false);
                                }
                            }
                        }
                        else
                        {
                            lblPrice.Visible = false;
                        }
                    }
                    else
                    {
                        var productVariant = GetVariant(productVariantCollection);
                        if (productVariant != null)
                        {
                            if (!SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                                (NopContext.Current.User != null &&
                                 !NopContext.Current.User.IsGuest))
                            {
                                if (productVariant.CustomerEntersPrice)
                                {
                                    lblPrice.Visible = false;
                                }
                                else
                                {
                                    decimal fromPriceBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));
                                    decimal fromPrice     = CurrencyManager.ConvertCurrency(fromPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                                    lblPrice.Text = String.Format(GetLocaleResourceString("Products.PriceRangeFromText"), PriceHelper.FormatPrice(fromPrice, false, false));
                                }
                            }
                            else
                            {
                                lblPrice.Visible = false;
                            }
                        }
                    }
                }
                else
                {
                    lblPrice.Visible = false;
                }
                #endregion

                // category
                var productCategories = CategoryManager.GetProductCategoriesByProductId(product.ProductId);
                if (productCategories.Count > 0)
                {
                    var breadCrumb = CategoryManager.GetBreadCrumb(productCategories[0].CategoryId);
                    if (breadCrumb.Count > 0)
                    {
                        rptrCategoryBreadcrumb.DataSource = breadCrumb;
                        rptrCategoryBreadcrumb.DataBind();
                    }
                }

                lblCategory.Text = "";// ProductManager.GetProductReviewByProductId(Product.ProductId);
                // catalog number
                LWG.Business.CatalogBiz catalogBiz = new LWG.Business.CatalogBiz();
                lwg_Catalog             catalog    = catalogBiz.GetByID(product.ProductId);
                hlCatalogNo.Text        = Server.HtmlEncode("# - " + catalog.CatalogNumber);
                hlCatalogNo.NavigateUrl = productURL;
            }
        }
コード例 #2
0
        private void BindData()
        {
            if (product != null)
            {
                string productURL = SEOHelper.GetProductUrl(product);

                LWG.Business.CatalogBiz catalogBiz = new LWG.Business.CatalogBiz();
                lwg_Catalog             catalog    = catalogBiz.GetByID(product.ProductId);

                hlCatalogNo.Text      = Server.HtmlEncode(catalog.CatalogNumber);
                hlProduct.NavigateUrl = hlCatalogNo.NavigateUrl = productURL;
                hlProduct.Text        = Server.HtmlEncode(product.Name);

                ProductPicture productPicture = product.DefaultProductPicture;
                if (productPicture != null)
                {
                    hlImageLink.ImageUrl = PictureManager.GetPictureUrl(productPicture.Picture, this.ProductImageSize, true);
                    hlImageLink.ToolTip  = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.Name);
                    hlImageLink.Text     = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.Name);
                }
                else
                {
                    hlImageLink.ImageUrl = PictureManager.GetDefaultPictureUrl(this.ProductImageSize);
                    hlImageLink.ToolTip  = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.Name);
                    hlImageLink.Text     = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.Name);
                }
                hlImageLink.NavigateUrl = productURL;

                lShortDescription.Text = product.ShortDescription;

                var productVariantCollection = product.ProductVariants;

                if (productVariantCollection.Count > 0)
                {
                    if (!product.HasMultipleVariants)
                    {
                        var productVariant = productVariantCollection[0];
                        btnAddToCart.Visible = (!productVariant.DisableBuyButton);
                        if (!SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                            (NopContext.Current.User != null &&
                             !NopContext.Current.User.IsGuest))
                        {
                            if (productVariant.CustomerEntersPrice)
                            {
                                lblOldPrice.Visible = false;
                                lblPrice.Visible    = false;
                            }
                            else
                            {
                                decimal oldPriceBase = TaxManager.GetPrice(productVariant, productVariant.OldPrice);
                                decimal finalPriceWithoutDiscountBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));

                                decimal oldPrice = CurrencyManager.ConvertCurrency(oldPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                                decimal finalPriceWithoutDiscount = CurrencyManager.ConvertCurrency(finalPriceWithoutDiscountBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);

                                if (finalPriceWithoutDiscountBase != oldPriceBase && oldPriceBase != decimal.Zero)
                                {
                                    lblOldPrice.Text = PriceHelper.FormatPrice(oldPrice);
                                    lblPrice.Text    = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                                }
                                else
                                {
                                    lblOldPrice.Visible = false;
                                    lblPrice.Text       = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                                }
                            }
                        }
                        else
                        {
                            lblOldPrice.Visible  = false;
                            lblPrice.Visible     = false;
                            btnAddToCart.Visible = false;
                        }
                        ddlVariantPrice.Visible = false;
                    }
                    else
                    {
                        lblOldPrice.Visible  = false;
                        lblPrice.Visible     = false;
                        btnAddToCart.Visible = false;

                        ddlVariantPrice.Visible    = true;
                        ddlVariantPrice.DataSource = productVariantCollection.OrderBy(pv => pv.Price);
                        ddlVariantPrice.DataBind();
                        #region comment built-in code
                        //var productVariant = product.MinimalPriceProductVariant;
                        //if (productVariant != null)
                        //{
                        //    if (!SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                        //        (NopContext.Current.User != null &&
                        //        !NopContext.Current.User.IsGuest))
                        //    {
                        //        if (productVariant.CustomerEntersPrice)
                        //        {
                        //            lblOldPrice.Visible = false;
                        //            lblPrice.Visible = false;
                        //        }
                        //        else
                        //        {
                        //            decimal fromPriceBase = TaxManager.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false));
                        //            decimal fromPrice = CurrencyManager.ConvertCurrency(fromPriceBase, CurrencyManager.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                        //            lblOldPrice.Visible = false;
                        //            lblPrice.Text = String.Format(GetLocaleResourceString("Products.PriceRangeFromText"), PriceHelper.FormatPrice(fromPrice));
                        //        }
                        //    }
                        //    else
                        //    {
                        //        lblOldPrice.Visible = false;
                        //        lblPrice.Visible = false;
                        //        btnAddToCart.Visible = false;
                        //    }
                        //}

                        //btnAddToCart.Visible = false;
                        #endregion
                    }
                }
                else
                {
                    lblOldPrice.Visible  = false;
                    lblPrice.Visible     = false;
                    btnAddToCart.Visible = false;
                }
            }
        }