Example #1
0
        protected void btnAddToCart_Click(object sender, CommandEventArgs e)
        {
            int productId        = Convert.ToInt32(e.CommandArgument);
            int productVariantId = 0;

            if (ProductManager.DirectAddToCartAllowed(productId, out productVariantId))
            {
                var addToCartWarnings = ShoppingCartManager.AddToCart(ShoppingCartTypeEnum.ShoppingCart,
                                                                      productVariantId, string.Empty, decimal.Zero, 1);
                if (addToCartWarnings.Count == 0)
                {
                    Response.Redirect("~/shoppingcart.aspx");
                }
                else
                {
                    string productURL = SEOHelper.GetProductUrl(productId);
                    Response.Redirect(productURL);
                }
            }
            else
            {
                string productURL = SEOHelper.GetProductUrl(productId);
                Response.Redirect(productURL);
            }
        }
        protected void dlAlsoPurchasedProducts_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var product = e.Item.DataItem as Product;
                if (product != null)
                {
                    string productURL = SEOHelper.GetProductUrl(product);

                    var hlImageLink = e.Item.FindControl("hlImageLink") as HyperLink;
                    if (hlImageLink != null)
                    {
                        var picture = product.DefaultPicture;
                        if (picture != null)
                        {
                            hlImageLink.ImageUrl = this.PictureService.GetPictureUrl(picture, this.SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 125), true);
                        }
                        else
                        {
                            hlImageLink.ImageUrl = this.PictureService.GetDefaultPictureUrl(this.SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 125));
                        }
                        hlImageLink.NavigateUrl = productURL;
                        hlImageLink.ToolTip     = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.LocalizedName);
                        hlImageLink.Text        = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.LocalizedName);
                    }

                    var hlProduct = e.Item.FindControl("hlProduct") as HyperLink;
                    if (hlProduct != null)
                    {
                        hlProduct.NavigateUrl = productURL;
                        hlProduct.Text        = product.LocalizedName;
                    }
                }
            }
        }
Example #3
0
        protected void rptrRequests_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var returnRequest = (ReturnRequest)e.Item.DataItem;

                var lRequestTitle = (Literal)e.Item.FindControl("lRequestTitle");
                var lItem         = (Literal)e.Item.FindControl("lItem");
                var lReason       = (Literal)e.Item.FindControl("lReason");
                var lAction       = (Literal)e.Item.FindControl("lAction");
                var lDate         = (Literal)e.Item.FindControl("lDate");
                var phComments    = (PlaceHolder)e.Item.FindControl("phComments");
                var lComments     = (Literal)e.Item.FindControl("lComments");

                lRequestTitle.Text = string.Format(GetLocaleResourceString("CustomerReturnRequests.RequestTitle"), returnRequest.ReturnRequestId, OrderManager.GetReturnRequestStatusName(returnRequest.ReturnStatus));
                string prodLink = string.Format("<a href=\"{0}\">{1}</a>", SEOHelper.GetProductUrl(returnRequest.OrderProductVariant.ProductVariant.Product), returnRequest.OrderProductVariant.ProductVariant.LocalizedFullProductName);
                lItem.Text   = string.Format(GetLocaleResourceString("CustomerReturnRequests.Item"), returnRequest.Quantity, prodLink);
                lReason.Text = string.Format(GetLocaleResourceString("CustomerReturnRequests.Reason"), Server.HtmlEncode(returnRequest.ReasonForReturn));
                lAction.Text = string.Format(GetLocaleResourceString("CustomerReturnRequests.Action"), Server.HtmlEncode(returnRequest.RequestedAction));
                lDate.Text   = string.Format(GetLocaleResourceString("CustomerReturnRequests.Date"), DateTimeHelper.ConvertToUserTime(returnRequest.CreatedOn, DateTimeKind.Utc));
                if (!string.IsNullOrEmpty(returnRequest.CustomerComments))
                {
                    phComments.Visible = true;
                    lComments.Text     = OrderManager.FormatReturnRequestCommentsText(returnRequest.CustomerComments);
                }
                else
                {
                    phComments.Visible = false;
                }
            }
        }
Example #4
0
        protected void lvCart_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                var dataItem = e.Item as ListViewDataItem;
                if (dataItem != null)
                {
                    var sci = dataItem.DataItem as ShoppingCartItem;
                    if (sci != null)
                    {
                        var hlProduct = dataItem.FindControl("hlProduct") as HyperLink;
                        if (hlProduct != null)
                        {
                            hlProduct.NavigateUrl = SEOHelper.GetProductUrl(sci.ProductVariant.Product);
                            hlProduct.Text        = Server.HtmlEncode(sci.ProductVariant.FullProductName);
                        }

                        var lblQty = dataItem.FindControl("lblQty") as Label;
                        if (lblQty != null)
                        {
                            lblQty.Text = string.Format("{0} x ", sci.Quantity);
                        }
                    }
                }
            }
        }
Example #5
0
        protected void BindData()
        {
            var product = this.ProductService.GetProductById(this.ProductId);

            if (product != null)
            {
                hlProduct.NavigateUrl = SEOHelper.GetProductUrl(product);

                var productCategories = product.ProductCategories;
                if (productCategories.Count > 0)
                {
                    var category = productCategories[0].Category;
                    if (category != null)
                    {
                        var breadCrumb = this.CategoryService.GetBreadCrumb(category.CategoryId);
                        if (breadCrumb.Count > 0)
                        {
                            rptrCategoryBreadcrumb.DataSource = breadCrumb;
                            rptrCategoryBreadcrumb.DataBind();
                        }
                    }
                }

                hlProduct.Text = Server.HtmlEncode(product.LocalizedName);
            }
            else
            {
                this.Visible = false;
            }
        }
Example #6
0
 private void WriteProducts(StringBuilder sb, ProductCollection productCollection)
 {
     foreach (Product product in productCollection)
     {
         sb.AppendFormat("<li><a href=\"{0}\">{1}</a></li>", SEOHelper.GetProductUrl(product), Server.HtmlEncode(product.Name));
     }
 }
Example #7
0
        protected void btnProductDetails_Click(object sender, CommandEventArgs e)
        {
            int    productId  = Convert.ToInt32(e.CommandArgument);
            string productURL = SEOHelper.GetProductUrl(productId);

            Response.Redirect(productURL);
        }
Example #8
0
        protected void BindData()
        {
            var product = ProductManager.GetProductById(this.ProductId);
            var catalog = (new LWG.Business.CatalogBiz()).GetByID(product.ProductId);

            if (product != null)
            {
                hlProduct.NavigateUrl = SEOHelper.GetProductUrl(product);

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

                hlProduct.Text = Server.HtmlEncode(catalog.CatalogNumber + " - " + product.Name);
            }
            else
            {
                this.Visible = false;
            }
        }
Example #9
0
        private string GetProductUrlWithPricelistProvider(int productId, int affiliateId)
        {
            string url = SEOHelper.GetProductUrl(productId);

            if (AffiliateId != 0)
            {
                url = CommonHelper.ModifyQueryString(url, "AffiliateID=" + AffiliateId.ToString(), null);
            }
            return(url);
        }
        public string GetProductUrl(ShoppingCartItem shoppingCartItem)
        {
            var productVariant = shoppingCartItem.ProductVariant;

            if (productVariant != null)
            {
                return(SEOHelper.GetProductUrl(productVariant.ProductId));
            }
            return(string.Empty);
        }
        public string GetProductUrl(int productVariantId)
        {
            var productVariant = ProductManager.GetProductVariantById(productVariantId);

            if (productVariant != null)
            {
                return(SEOHelper.GetProductUrl(productVariant.ProductId));
            }
            return(string.Empty);
        }
Example #12
0
        private void BindData()
        {
            if (product != null)
            {
                string productURL = SEOHelper.GetProductUrl(product);

                hlProduct.NavigateUrl = productURL;
                hlProduct.Text        = Server.HtmlEncode(product.LocalizedName);

                var picture = product.DefaultPicture;
                if (picture != null)
                {
                    hlImageLink.ImageUrl = PictureManager.GetPictureUrl(picture, this.ProductImageSize, true);
                    hlImageLink.ToolTip  = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.LocalizedName);
                    hlImageLink.Text     = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.LocalizedName);
                }
                else
                {
                    hlImageLink.ImageUrl = PictureManager.GetDefaultPictureUrl(this.ProductImageSize);
                    hlImageLink.ToolTip  = String.Format(GetLocaleResourceString("Media.Product.ImageLinkTitleFormat"), product.LocalizedName);
                    hlImageLink.Text     = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.LocalizedName);
                }

                hlImageLink.NavigateUrl = productURL;
                lShortDescription.Text  = product.LocalizedShortDescription;

                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))
                        {
                            //nothing
                        }
                        else
                        {
                            btnAddToCart.Visible = false;
                        }
                    }
                    else
                    {
                        btnAddToCart.Visible = false;
                    }
                }
                else
                {
                    btnAddToCart.Visible = false;
                }
            }
        }
Example #13
0
        private void WriteProducts()
        {
            var products = ProductManager.GetAllProducts(false);

            foreach (var product in products)
            {
                var url             = SEOHelper.GetProductUrl(product);
                var updateFrequency = UpdateFrequency.Weekly;
                var updateTime      = product.UpdatedOn;
                WriteUrlLocation(url, updateFrequency, updateTime);
            }
        }
Example #14
0
        protected void dlProducts_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var product = e.Item.DataItem as Product;

                var hlLink = e.Item.FindControl("hlLink") as HyperLink;
                if (hlLink != null)
                {
                    hlLink.NavigateUrl = SEOHelper.GetProductUrl(product);
                    hlLink.Text        = Server.HtmlEncode(product.LocalizedName);
                }
            }
        }
Example #15
0
 protected void lvRecentlyViewedProducts_ItemDataBound(object sender, ListViewItemEventArgs e)
 {
     if (e.Item.ItemType == ListViewItemType.DataItem)
     {
         var dataItem = e.Item as ListViewDataItem;
         if (dataItem != null)
         {
             var product = dataItem.DataItem as Product;
             if (product != null)
             {
                 var hlProduct = dataItem.FindControl("hlProduct") as HyperLink;
                 hlProduct.NavigateUrl = SEOHelper.GetProductUrl(product);
             }
         }
     }
 }
Example #16
0
        protected void btnAddToCart_Click(object sender, CommandEventArgs e)
        {
            int productId        = Convert.ToInt32(e.CommandArgument);
            int productVariantId = 0;

            if (ProductManager.DirectAddToCartAllowed(productId, out productVariantId))
            {
                var addToCartWarnings = ShoppingCartManager.AddToCart(ShoppingCartTypeEnum.ShoppingCart,
                                                                      productVariantId, string.Empty, decimal.Zero, 1);
                if (addToCartWarnings.Count == 0)
                {
                    bool displayCart = true;
                    if (this.RedirectCartAfterAddingProduct.HasValue)
                    {
                        displayCart = this.RedirectCartAfterAddingProduct.Value;
                    }
                    else
                    {
                        displayCart = SettingManager.GetSettingValueBoolean("Display.Products.DisplayCartAfterAddingProduct");
                    }

                    if (displayCart)
                    {
                        //redirect to shopping cart page
                        Response.Redirect(SEOHelper.GetShoppingCartUrl());
                    }
                    else
                    {
                        //display notification message
                        this.DisplayAlertMessage(GetLocaleResourceString("Products.ProductHasBeenAddedToTheCart"));
                    }
                }
                else
                {
                    string productURL = SEOHelper.GetProductUrl(productId);
                    Response.Redirect(productURL);
                }
            }
            else
            {
                string productURL = SEOHelper.GetProductUrl(productId);
                Response.Redirect(productURL);
            }
        }
Example #17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (product == null || product.Deleted)
            {
                Response.Redirect(CommonHelper.GetStoreLocation());
            }

            //title, meta
            string title = string.Empty;

            if (!string.IsNullOrEmpty(product.LocalizedMetaTitle))
            {
                title = product.LocalizedMetaTitle;
            }
            else
            {
                title = product.LocalizedName;
            }
            SEOHelper.RenderTitle(this, title, true);
            SEOHelper.RenderMetaTag(this, "description", product.LocalizedMetaDescription, true);
            SEOHelper.RenderMetaTag(this, "keywords", product.LocalizedMetaKeywords, true);

            //canonical URL
            if (SEOHelper.EnableUrlRewriting &&
                this.SettingManager.GetSettingValueBoolean("SEO.CanonicalURLs.Products.Enabled"))
            {
                if (!this.SEName.Equals(SEOHelper.GetProductSEName(product)))
                {
                    string canonicalUrl = SEOHelper.GetProductUrl(product);

                    SEOHelper.RenderCanonicalTag(Page, canonicalUrl);
                }
            }

            if (!Page.IsPostBack)
            {
                this.ProductService.AddProductToRecentlyViewedList(product.ProductId);
            }
        }
        protected void BindData()
        {
            var product = this.ProductService.GetProductById(this.ProductId);

            if (product != null)
            {
                hlProduct.NavigateUrl  = SEOHelper.GetProductUrl(product);
                hlProduct.Text         = Server.HtmlEncode(product.LocalizedName);
                lShortDescription.Text = product.LocalizedShortDescription;

                if (NopContext.Current.User == null && this.CustomerService.AllowAnonymousUsersToEmailAFriend)
                {
                    this.CustomerService.CreateAnonymousUser();
                }

                if (NopContext.Current.User == null || (NopContext.Current.User.IsGuest && !this.CustomerService.AllowAnonymousUsersToEmailAFriend))
                {
                    lblEmailAFriend.Text       = GetLocaleResourceString("Products.OnlyRegisteredUsersCanEmailAFriend");
                    pnlFriendsEmail.Visible    = false;
                    pnlFrom.Visible            = false;
                    pnlPersonalMessage.Visible = false;
                    btnEmail.Enabled           = false;
                }
                else
                {
                    lblEmailAFriend.Text       = string.Empty;
                    pnlFriendsEmail.Visible    = true;
                    pnlFrom.Visible            = true;
                    lblFrom.Text               = NopContext.Current.User.Email;
                    pnlPersonalMessage.Visible = true;
                    btnEmail.Enabled           = true;
                }
            }
            else
            {
                this.Visible = false;
            }
        }
Example #19
0
 protected void ddlVariantPrice_ItemCommand(object source, DataListCommandEventArgs e)
 {
     if (e.CommandName == "AddToCart")
     {
         var pv = ProductManager.GetProductVariantById(Convert.ToInt32(e.CommandArgument.ToString()));
         if (pv == null)
         {
             return;
         }
         Label   lblPrice = e.Item.FindControl("lblPrice") as Label;
         var     ctrlProductAttributes = e.Item.FindControl("ctrlProductAttributes") as ProductAttributesControl;
         decimal price;
         if (decimal.TryParse(lblPrice.Text, out price))
         {
             string        attributes        = ctrlProductAttributes.SelectedAttributes;
             List <string> addToCartWarnings = ShoppingCartManager.AddToCart(
                 ShoppingCartTypeEnum.ShoppingCart,
                 pv.ProductVariantId,
                 attributes,
                 price,
                 1);
             if (addToCartWarnings.Count == 0)
             {
                 Response.Redirect("~/shoppingcart.aspx");
             }
             else
             {
                 string productURL = SEOHelper.GetProductUrl(Product.ProductId);
                 Response.Redirect(productURL);
             }
         }
         else
         {
             string productURL = SEOHelper.GetProductUrl(Product.ProductId);
             Response.Redirect(productURL);
         }
     }
 }
Example #20
0
        /// <summary>
        /// Generate YandexMarket feed
        /// </summary>
        /// <param name="stream">Stream</param>
        public static void GenerateFeed(Stream stream)
        {
            const string googleBaseNamespace = "http://base.google.com/ns/1.0";

            var settings = new XmlWriterSettings
            {
                Encoding     = Encoding.GetEncoding(1251),
                Indent       = true,
                IndentChars  = "  ",
                NewLineChars = "\r\n"
            };

            using (var writer = XmlWriter.Create(stream, settings))
            {
                writer.WriteStartDocument();
//                writer.WriteDocType("yml_catalog", null, null, "SYSTEM \"shops.dtd\"");
                writer.WriteDocType("yml_catalog", null, "shops.dtd", null);
                //writer.WriteDocType("book", null, null, "<!ENTITY h \"hardcover\">");
                writer.WriteStartElement("yml_catalog");
                writer.WriteAttributeString("date", DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
//                writer.WriteAttributeString("version", "1.0");
                //writer.WriteAttributeString("xmlns", "g", null, googleBaseNamespace);
                writer.WriteStartElement("shop");
                writer.WriteElementString("name", string.Format("{0}", SettingManager.StoreName));
                writer.WriteElementString("company", SettingManager.CompanyFullName);
                writer.WriteElementString("url", "http://s-t-r.ru");

                writer.WriteStartElement("currencies");
                writer.WriteStartElement("currency");
                writer.WriteAttributeString("id", "RUR");
                writer.WriteAttributeString("rate", "1");
                writer.WriteEndElement(); //currency
                writer.WriteEndElement(); //currencies

                writer.WriteStartElement("categories");
                CategoryCollection cc = CategoryManager.GetEverythingCategories();
                foreach (Category c in cc)
                {
                    //writer.WriteElementString("category", c.Name);
                    writer.WriteStartElement("category");
                    writer.WriteAttributeString("id", c.CategoryId.ToString());
                    if (c.ParentCategoryId > 0)
                    {
                        writer.WriteAttributeString("parentId", c.ParentCategoryId.ToString());
                    }
                    writer.WriteString(c.Name);
                    writer.WriteEndElement(); //category
                }
                writer.WriteEndElement();     //categories

                writer.WriteElementString("local_delivery_cost", SettingManager.GetSettingValueDecimalNative("ShippingRateComputationMethod.FixedRate.Rate").ToString());

                writer.WriteStartElement("offers");

                var products = ProductManager.GetAllProducts(false);
                foreach (var product in products)
                {
                    var productVariants = ProductManager.GetProductVariantsByProductId(product.ProductId, false);

                    foreach (var productVariant in productVariants)
                    {
                        if (!productVariant.AllowYandexMarket)
                        {
                            continue;
                        }
                        if (product.Deleted)
                        {
                            continue;
                        }
                        writer.WriteStartElement("offer");
//                      writer.WriteAttributeString("AllowYandexMarket", productVariant.AllowYandexMarket.ToString());

                        writer.WriteAttributeString("id", productVariant.ProductVariantId.ToString());
                        writer.WriteAttributeString("available", "false");

                        writer.WriteElementString("url", SEOHelper.GetProductUrl(product));
                        writer.WriteElementString("price", productVariant.Price.ToString("F", new CultureInfo("en-US", false)));
                        writer.WriteElementString("currencyId", "RUR");
                        writer.WriteElementString("categoryId", product.ProductCategories[0].CategoryId.ToString());
                        writer.WriteElementString("delivery", "true");

                        writer.WriteElementString("name", productVariant.FullProductName);
                        writer.WriteElementString("sales_notes", "Только предоплата.");
//                      writer.WriteElementString("sales_notes", "Только предоплата. Минимальный заказ: 10000 руб.");
                        //writer.WriteStartElement("description");
                        //string description = productVariant.Description;
                        //if (String.IsNullOrEmpty(description))
                        //    description = product.FullDescription;
                        //if (String.IsNullOrEmpty(description))
                        //    description = product.ShortDescription;
                        //if (String.IsNullOrEmpty(description))
                        //    description = product.Name;
                        //writer.WriteCData(description);
                        //writer.WriteEndElement(); // description

                        //writer.WriteStartElement("g", "brand", googleBaseNamespace);
                        //writer.WriteFullEndElement(); // g:brand
                        //writer.WriteElementString("g", "condition", googleBaseNamespace, "new");
                        //writer.WriteElementString("g", "expiration_date", googleBaseNamespace, DateTime.Now.AddDays(28).ToString("yyyy-MM-dd"));
                        //writer.WriteElementString("g", "id", googleBaseNamespace, productVariant.ProductVariantId.ToString());
                        //string imageUrl = string.Empty;
                        //var productPictures = product.ProductPictures;
                        //if (productPictures.Count > 0)
                        //    imageUrl = PictureManager.GetPictureUrl(productPictures[0].Picture, SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize"), true);
                        //writer.WriteElementString("g", "image_link", googleBaseNamespace, imageUrl);
                        //decimal price = productVariant.Price;

                        //uncomment and set your product_type attribute
                        //writer.WriteStartElement("g", "product_type", googleBaseNamespace);
                        //writer.WriteCData("Clothing & Accessories > Clothing Accessories > Hair Accessories > Hair Pins & Clips");
                        //writer.WriteFullEndElement(); // g:brand


                        //if (productVariant.Weight != decimal.Zero)
                        //{
                        //    writer.WriteElementString("g", "weight", googleBaseNamespace, string.Format(CultureInfo.InvariantCulture, "{0} {1}", productVariant.Weight.ToString(new CultureInfo("en-US", false).NumberFormat), MeasureManager.BaseWeightIn.SystemKeyword));
                        //}
                        writer.WriteEndElement(); // offer
                    }
                }

                writer.WriteEndElement(); //offers

                writer.WriteEndElement(); // shop
                writer.WriteEndElement(); // yml_catalog
                writer.WriteEndDocument();
            }
        }
Example #21
0
        private void BindData()
        {
            if (product != null)
            {
                string productURL = SEOHelper.GetProductUrl(product);

                hlProduct.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;
                        }
                    }
                    else
                    {
                        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;
                    }
                }
                else
                {
                    lblOldPrice.Visible  = false;
                    lblPrice.Visible     = false;
                    btnAddToCart.Visible = false;
                }
            }
        }
Example #22
0
        /// <summary>
        /// Generate froogle feed
        /// </summary>
        /// <param name="stream">Stream</param>
        public static void GenerateFeed(Stream stream)
        {
            const string googleBaseNamespace = "http://base.google.com/ns/1.0";

            var settings = new XmlWriterSettings
            {
                Encoding = Encoding.UTF8
            };

            using (var writer = XmlWriter.Create(stream, settings))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("rss");
                writer.WriteAttributeString("version", "2.0");
                writer.WriteAttributeString("xmlns", "g", null, googleBaseNamespace);
                writer.WriteStartElement("channel");
                writer.WriteElementString("title", string.Format("{0} Google Base", SettingManager.StoreName));
                writer.WriteElementString("link", "http://base.google.com/base/");
                writer.WriteElementString("description", "Information about products");


                var products = ProductManager.GetAllProducts(false);
                foreach (var product in products)
                {
                    var productVariants = ProductManager.GetProductVariantsByProductId(product.ProductId, false);

                    foreach (var productVariant in productVariants)
                    {
                        writer.WriteStartElement("item");
                        writer.WriteElementString("link", SEOHelper.GetProductUrl(product));
                        writer.WriteElementString("title", productVariant.FullProductName);
                        writer.WriteStartElement("description");
                        string description = productVariant.Description;
                        if (String.IsNullOrEmpty(description))
                        {
                            description = product.FullDescription;
                        }
                        if (String.IsNullOrEmpty(description))
                        {
                            description = product.ShortDescription;
                        }
                        if (String.IsNullOrEmpty(description))
                        {
                            description = product.Name;
                        }
                        writer.WriteCData(description);
                        writer.WriteEndElement();     // description
                        writer.WriteStartElement("g", "brand", googleBaseNamespace);
                        writer.WriteFullEndElement(); // g:brand
                        writer.WriteElementString("g", "condition", googleBaseNamespace, "new");
                        writer.WriteElementString("g", "expiration_date", googleBaseNamespace, DateTime.Now.AddDays(28).ToString("yyyy-MM-dd"));
                        writer.WriteElementString("g", "id", googleBaseNamespace, productVariant.ProductVariantId.ToString());
                        string imageUrl = string.Empty;
                        var    pictures = PictureManager.GetPicturesByProductId(product.ProductId, 1);
                        if (pictures.Count > 0)
                        {
                            imageUrl = PictureManager.GetPictureUrl(pictures[0], SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize"), true);
                        }
                        writer.WriteElementString("g", "image_link", googleBaseNamespace, imageUrl);
                        decimal price = productVariant.Price;
                        writer.WriteElementString("g", "price", googleBaseNamespace, price.ToString(new CultureInfo("en-US", false).NumberFormat));

                        //uncomment and set your product_type attribute
                        //writer.WriteStartElement("g", "product_type", googleBaseNamespace);
                        //writer.WriteCData("Clothing & Accessories > Clothing Accessories > Hair Accessories > Hair Pins & Clips");
                        //writer.WriteFullEndElement(); // g:brand


                        //if (productVariant.Weight != decimal.Zero)
                        //{
                        //    writer.WriteElementString("g", "weight", googleBaseNamespace, string.Format(CultureInfo.InvariantCulture, "{0} {1}", productVariant.Weight.ToString(new CultureInfo("en-US", false).NumberFormat), MeasureManager.BaseWeightIn.SystemKeyword));
                        //}
                        writer.WriteEndElement(); // item
                    }
                }

                writer.WriteEndElement(); // channel
                writer.WriteEndElement(); // rss
                writer.WriteEndDocument();
            }
        }
Example #23
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;
            }
        }
        protected void btnReview_Click(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsValid)
                {
                    var product = ProductManager.GetProductById(this.ProductId);
                    if (product != null && product.AllowCustomerReviews)
                    {
                        if (NopContext.Current.User == null && CustomerManager.AllowAnonymousUsersToReviewProduct)
                        {
                            CustomerManager.CreateAnonymousUser();
                        }

                        if (NopContext.Current.User == null || (NopContext.Current.User.IsGuest && !CustomerManager.AllowAnonymousUsersToReviewProduct))
                        {
                            lblLeaveYourReview.Text = GetLocaleResourceString("Products.OnlyRegisteredUsersCanWriteReviews");
                            return;
                        }

                        string productReviewTitle = txtProductReviewTitle.Text.Trim();
                        string productReviewText  = txtProductReviewText.Text.Trim();
                        if (String.IsNullOrEmpty(productReviewTitle))
                        {
                            throw new NopException(GetLocaleResourceString("Products.PleaseEnterReviewTitle"));
                        }
                        if (String.IsNullOrEmpty(productReviewText))
                        {
                            throw new NopException(GetLocaleResourceString("Products.PleaseEnterReviewText"));
                        }

                        int rating = 4;
                        if (rblRating.SelectedItem != null)
                        {
                            rating = int.Parse(rblRating.SelectedItem.Value);
                        }
                        bool isApproved = !CustomerManager.ProductReviewsMustBeApproved;

                        ProductManager.InsertProductReview(product.ProductId, NopContext.Current.User.CustomerId,
                                                           productReviewTitle, productReviewText,
                                                           rating, 0, 0, isApproved, DateTime.Now);
                        txtProductReviewTitle.Text = string.Empty;
                        txtProductReviewText.Text  = string.Empty;

                        if (!isApproved)
                        {
                            lblLeaveYourReview.Text = GetLocaleResourceString("Products.You'llSeeYourProductReviewAfterApprovingByStoreAdministrator");
                        }
                        else
                        {
                            string productURL = SEOHelper.GetProductUrl(product);
                            Response.Redirect(productURL);
                        }
                    }
                    else
                    {
                        Response.Redirect(CommonHelper.GetStoreLocation());
                    }
                }
            }
            catch (Exception exc)
            {
                pnlError.Visible   = true;
                lErrorMessage.Text = Server.HtmlEncode(exc.Message);
            }
        }
        /// <summary>
        /// Generate PriceGrabber feed
        /// </summary>
        /// <param name="stream">Stream</param>
        public static void GenerateFeed(Stream stream)
        {
            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.WriteLine("Unique Retailer SKU;Manufacturer Name;Manufacturer Part Number;Product Title;Categorization;Product URL;Image URL;Detailed Description;Selling Price;Condition;Availability");

                foreach (Product p in IoC.Resolve <IProductService>().GetAllProducts(false))
                {
                    foreach (ProductVariant pv in IoC.Resolve <IProductService>().GetProductVariantsByProductId(p.ProductId, false))
                    {
                        string sku = pv.ProductVariantId.ToString();
                        string manufacturerName       = p.ProductManufacturers.Count > 0 ? p.ProductManufacturers[0].Manufacturer.Name : String.Empty;
                        string manufacturerPartNumber = pv.ManufacturerPartNumber;
                        string productTitle           = pv.FullProductName;
                        string productUrl             = SEOHelper.GetProductUrl(p);

                        string imageUrl = string.Empty;
                        var    pictures = IoC.Resolve <IPictureService>().GetPicturesByProductId(p.ProductId, 1);
                        if (pictures.Count > 0)
                        {
                            imageUrl = IoC.Resolve <IPictureService>().GetPictureUrl(pictures[0], IoC.Resolve <ISettingManager>().GetSettingValueInteger("PromotionProvider.PriceGrabber.ProductThumbnailImageSize"), true);
                        }
                        else
                        {
                            imageUrl = IoC.Resolve <IPictureService>().GetDefaultPictureUrl(PictureTypeEnum.Entity, IoC.Resolve <ISettingManager>().GetSettingValueInteger("PromotionProvider.PriceGrabber.ProductThumbnailImageSize"));
                        }

                        string description    = pv.Description;
                        string price          = IoC.Resolve <ICurrencyService>().ConvertCurrency(pv.Price, IoC.Resolve <ICurrencyService>().PrimaryStoreCurrency, PriceGrabberService.UsedCurrency).ToString(new CultureInfo("en-US", false).NumberFormat);
                        string availability   = pv.StockQuantity > 0 ? "Yes" : "No";
                        string categorization = "no category";

                        if (String.IsNullOrEmpty(description))
                        {
                            description = p.FullDescription;
                        }
                        if (String.IsNullOrEmpty(description))
                        {
                            description = p.ShortDescription;
                        }
                        if (String.IsNullOrEmpty(description))
                        {
                            description = p.Name;
                        }

                        var productCategories = p.ProductCategories;
                        if (productCategories.Count > 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            foreach (Category cat in IoC.Resolve <ICategoryService>().GetBreadCrumb(productCategories[0].CategoryId))
                            {
                                sb.AppendFormat("{0}>", cat.Name);
                            }
                            sb.Length     -= 1;
                            categorization = sb.ToString();
                        }

                        productTitle           = RemoveSpecChars(productTitle);
                        manufacturerPartNumber = RemoveSpecChars(manufacturerPartNumber);
                        manufacturerName       = RemoveSpecChars(manufacturerName);
                        description            = HtmlHelper.StripTags(description);
                        description            = RemoveSpecChars(description);
                        categorization         = RemoveSpecChars(categorization);

                        writer.WriteLine("{0};{1};{2};{3};{4};{5};{6};{7};{8};New;{9}",
                                         sku,
                                         manufacturerName,
                                         manufacturerPartNumber,
                                         productTitle,
                                         categorization,
                                         productUrl,
                                         imageUrl,
                                         description,
                                         price,
                                         availability);
                    }
                }
            }
        }
Example #26
0
        protected override void OnPreRender(EventArgs e)
        {
            ProductVariant productVariant = this.ProductService.GetProductVariantById(this.ProductVariantId);

            if (productVariant != null)
            {
                PreviewButton.OnClientClick = string.Format("javascript:OpenWindow('{0}', 800, 600, true); return false;", SEOHelper.GetProductUrl(productVariant.ProductId));
            }


            base.OnPreRender(e);
        }
Example #27
0
        protected override void OnPreRender(EventArgs e)
        {
            SimpleTextBox txtName = ctrlProductInfoEdit.FindControl("txtName") as SimpleTextBox;

            if (txtName != null)
            {
                txtProductCopyName.Text = "Copy of " + txtName.Text;
            }

            Product product = this.ProductService.GetProductById(this.ProductId);

            if (product != null)
            {
                PreviewButton.OnClientClick = string.Format("javascript:OpenWindow('{0}', 800, 600, true); return false;", SEOHelper.GetProductUrl(product.ProductId));
            }

            base.OnPreRender(e);
        }
Example #28
0
        /// <summary>
        /// Generate become.com feed
        /// </summary>
        /// <param name="stream">Stream</param>
        public static void GenerateFeed(Stream stream)
        {
            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.WriteLine("UPC;Mfr Part #;Manufacturer;Product URL;Image URL;Product Title;Product Description;Category;Price;Condition;Stock Status");

                foreach (Product p in ProductManager.GetAllProducts(false))
                {
                    foreach (ProductVariant pv in ProductManager.GetProductVariantsByProductId(p.ProductId, false))
                    {
                        string sku = pv.ProductVariantId.ToString("000000000000");
                        string manufacturerName       = p.ProductManufacturers.Count > 0 ? p.ProductManufacturers[0].Manufacturer.Name : String.Empty;
                        string manufacturerPartNumber = pv.ManufacturerPartNumber;
                        string productTitle           = pv.FullProductName;
                        string productUrl             = SEOHelper.GetProductUrl(p);

                        string imageUrl = string.Empty;
                        var    pictures = PictureManager.GetPicturesByProductId(p.ProductId, 1);
                        if (pictures.Count > 0)
                        {
                            imageUrl = PictureManager.GetPictureUrl(pictures[0], SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize"), true);
                        }
                        else
                        {
                            imageUrl = PictureManager.GetDefaultPictureUrl(PictureTypeEnum.Entity, SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize"));
                        }

                        string description = pv.Description;
                        string price       = pv.Price.ToString(new CultureInfo("en-US", false).NumberFormat);
                        string stockStatus = pv.StockQuantity > 0 ? "In Stock" : "Out of Stock";
                        string category    = "no category";

                        if (String.IsNullOrEmpty(description))
                        {
                            description = p.FullDescription;
                        }
                        if (String.IsNullOrEmpty(description))
                        {
                            description = p.ShortDescription;
                        }
                        if (String.IsNullOrEmpty(description))
                        {
                            description = p.Name;
                        }

                        var productCategories = p.ProductCategories;
                        if (productCategories.Count > 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            foreach (Category cat in CategoryManager.GetBreadCrumb(productCategories[0].CategoryId))
                            {
                                sb.AppendFormat("{0}>", cat.Name);
                            }
                            sb.Length -= 1;
                            category   = sb.ToString();
                        }

                        productTitle = CommonHelper.EnsureMaximumLength(productTitle, 80);
                        productTitle = RemoveSpecChars(productTitle);

                        manufacturerPartNumber = RemoveSpecChars(manufacturerPartNumber);
                        manufacturerName       = RemoveSpecChars(manufacturerName);

                        description = HtmlHelper.StripTags(description);
                        description = CommonHelper.EnsureMaximumLength(description, 250);
                        description = RemoveSpecChars(description);

                        category = RemoveSpecChars(category);

                        writer.WriteLine("{0};{1};{2};{3};{4};{5};{6};{7};{8};New;{9}",
                                         sku,
                                         manufacturerPartNumber,
                                         manufacturerName,
                                         productUrl,
                                         imageUrl,
                                         productTitle,
                                         description,
                                         category,
                                         price,
                                         stockStatus);
                    }
                }
            }
        }
Example #29
0
        protected void GenerateCompareTable()
        {
            this.tblCompareProducts.Rows.Clear();
            this.tblCompareProducts.Width = "100%";
            var compareProducts = this.ProductService.GetCompareProducts();

            if (compareProducts.Count > 0)
            {
                var headerRow = new HtmlTableRow();
                this.AddCell(headerRow, "&nbsp;");
                var productNameRow = new HtmlTableRow();
                this.AddCell(productNameRow, "&nbsp;");
                var priceRow = new HtmlTableRow();
                var cell     = new HtmlTableCell();
                cell.InnerText = GetLocaleResourceString("Products.CompareProductsPrice");
                cell.Align     = "left";
                priceRow.Cells.Add(cell);

                var specificationAttributeIds = new List <int>();
                foreach (var product in compareProducts)
                {
                    var productSpecificationAttributes = this.SpecificationAttributeService.GetProductSpecificationAttributesByProductId(product.ProductId, null, true);
                    foreach (var attribute in productSpecificationAttributes)
                    {
                        if (!specificationAttributeIds.Contains(attribute.SpecificationAttribute.SpecificationAttributeId))
                        {
                            specificationAttributeIds.Add(attribute.SpecificationAttribute.SpecificationAttributeId);
                        }
                    }
                }

                foreach (var product in compareProducts)
                {
                    var headerCell    = new HtmlTableCell();
                    var headerCellDiv = new HtmlGenericControl("div");

                    var productImagePanel = new HtmlGenericControl("p");
                    productImagePanel.Attributes.Add("align", "center");

                    var btnRemoveFromList = new Button();
                    btnRemoveFromList.ToolTip          = GetLocaleResourceString("Products.CompareProductsRemoveFromList");
                    btnRemoveFromList.Text             = GetLocaleResourceString("Products.CompareProductsRemoveFromList");
                    btnRemoveFromList.CommandName      = "Remove";
                    btnRemoveFromList.Command         += new CommandEventHandler(this.btnRemoveFromList_Command);
                    btnRemoveFromList.CommandArgument  = product.ProductId.ToString();
                    btnRemoveFromList.CausesValidation = false;
                    btnRemoveFromList.CssClass         = "remove-button";
                    btnRemoveFromList.ID = "btnRemoveFromList" + product.ProductId.ToString();
                    productImagePanel.Controls.Add(btnRemoveFromList);
                    productImagePanel.Controls.Add(new HtmlGenericControl("br"));

                    var productImage = new HtmlImage();
                    productImage.Border = 0;
                    //productImage.Align = "center";
                    productImage.Alt = "Product image";
                    var picture = product.DefaultPicture;
                    if (picture != null)
                    {
                        productImage.Src = this.PictureService.GetPictureUrl(picture, this.SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 125), true);
                    }
                    else
                    {
                        productImage.Src = this.PictureService.GetDefaultPictureUrl(this.SettingManager.GetSettingValueInteger("Media.Product.ThumbnailImageSize", 125));
                    }
                    productImagePanel.Controls.Add(productImage);
                    headerCellDiv.Controls.Add(productImagePanel);

                    headerCell.Controls.Add(headerCellDiv);
                    headerRow.Cells.Add(headerCell);
                    this.tblCompareProducts.Rows.Add(headerRow);

                    var productNameCell = new HtmlTableCell();
                    var productLink     = new HyperLink();
                    productLink.Text        = Server.HtmlEncode(product.LocalizedName);
                    productLink.NavigateUrl = SEOHelper.GetProductUrl(product);
                    productLink.Attributes.Add("class", "link");
                    productNameCell.Align = "center";
                    productNameCell.Controls.Add(productLink);
                    productNameRow.Cells.Add(productNameCell);
                    var priceCell = new HtmlTableCell();
                    priceCell.Align = "center";
                    var productVariantCollection = product.ProductVariants;
                    if (productVariantCollection.Count > 0)
                    {
                        var     productVariant = productVariantCollection[0];
                        decimal taxRate        = decimal.Zero;
                        decimal finalPriceWithoutDiscountBase = this.TaxService.GetPrice(productVariant, PriceHelper.GetFinalPrice(productVariant, false), out taxRate);
                        decimal finalPriceWithoutDiscount     = this.CurrencyService.ConvertCurrency(finalPriceWithoutDiscountBase, this.CurrencyService.PrimaryStoreCurrency, NopContext.Current.WorkingCurrency);
                        priceCell.InnerText = PriceHelper.FormatPrice(finalPriceWithoutDiscount);
                    }
                    priceRow.Cells.Add(priceCell);
                }
                productNameRow.Attributes.Add("class", "product-name");
                priceRow.Attributes.Add("class", "productPrice");
                this.tblCompareProducts.Rows.Add(productNameRow);
                if (!this.SettingManager.GetSettingValueBoolean("Common.HidePricesForNonRegistered") ||
                    (NopContext.Current.User != null &&
                     !NopContext.Current.User.IsGuest))
                {
                    this.tblCompareProducts.Rows.Add(priceRow);
                }

                foreach (int specificationAttributeId in specificationAttributeIds)
                {
                    var specificationAttribute = this.SpecificationAttributeService.GetSpecificationAttributeById(specificationAttributeId);
                    var productRow             = new HtmlTableRow();
                    this.AddCell(productRow, Server.HtmlEncode(specificationAttribute.LocalizedName)).Align = "left";

                    foreach (var product2 in compareProducts)
                    {
                        var productCell = new HtmlTableCell();
                        {
                            var productSpecificationAttributes2 = this.SpecificationAttributeService.GetProductSpecificationAttributesByProductId(product2.ProductId, null, true);
                            foreach (var psa2 in productSpecificationAttributes2)
                            {
                                if (specificationAttribute.SpecificationAttributeId == psa2.SpecificationAttribute.SpecificationAttributeId)
                                {
                                    // SpecMod
                                    if (psa2.SpecificationAttributeOption.LocalizedName == "Value" || psa2.SpecificationAttributeOption.Name == "Value")
                                    { // Its a value spec
                                        productCell.InnerHtml = (!String.IsNullOrEmpty(psa2.Value)) ? Server.HtmlEncode(psa2.Value) : "&nbsp;";
                                    }
                                    else
                                    { // Its not a value spec, handle it the nop way
                                        productCell.InnerHtml = (!String.IsNullOrEmpty(psa2.SpecificationAttributeOption.LocalizedName)) ? Server.HtmlEncode(psa2.SpecificationAttributeOption.LocalizedName) : "&nbsp;";
                                    }
                                }
                            }
                        }
                        productCell.Align  = "center";
                        productCell.VAlign = "top";
                        productRow.Cells.Add(productCell);
                    }
                    this.tblCompareProducts.Rows.Add(productRow);
                }

                string width = Math.Round((decimal)(90M / compareProducts.Count), 0, MidpointRounding.AwayFromZero).ToString() + "%";
                for (int i = 0; i < this.tblCompareProducts.Rows.Count; i++)
                {
                    var row = this.tblCompareProducts.Rows[i];
                    for (int j = 1; j < row.Cells.Count; j++)
                    {
                        if (j == (row.Cells.Count - 1))
                        {
                            row.Cells[j].Style.Add("width", width);
                            row.Cells[j].Style.Add("text-align", "center");
                        }
                        else
                        {
                            row.Cells[j].Style.Add("width", width);
                            row.Cells[j].Style.Add("text-align", "center");
                        }
                    }
                }
            }
            else
            {
                btnClearCompareProductsList.Visible = false;
                tblCompareProducts.Visible          = false;
            }
        }
Example #30
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;
                }
            }
        }