Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
        /// <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 ProductManager.GetAllProducts(false))
                {
                    foreach (ProductVariant pv in ProductManager.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 = 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 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 CategoryManager.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);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Print product collection to PDF
        /// </summary>
        /// <param name="productCollection"></param>
        /// <param name="filePath"></param>
        public static void PrintProductsToPdf(List <Product> productCollection, string filePath)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }

            Document doc     = new Document();
            Section  section = doc.AddSection();

            int productNumber = 1;
            int prodCount     = productCollection.Count;

            foreach (var product in productCollection)
            {
                Paragraph p1 = section.AddParagraph(String.Format("{0}. {1}", productNumber, product.LocalizedName));
                p1.Format.Font.Bold  = true;
                p1.Format.Font.Color = Colors.Black;

                section.AddParagraph();

                section.AddParagraph(HtmlHelper.StripTags(HtmlHelper.ConvertHtmlToPlainText(product.LocalizedFullDescription)));

                section.AddParagraph();

                var pictures = PictureManager.GetPicturesByProductId(product.ProductId);
                if (pictures.Count > 0)
                {
                    Table table = section.AddTable();
                    table.Borders.Visible = false;

                    table.AddColumn(Unit.FromCentimeter(10));
                    table.AddColumn(Unit.FromCentimeter(10));

                    Row row = table.AddRow();
                    for (int i = 0; i < pictures.Count; i++)
                    {
                        int cellNum = i % 2;
                        var pic     = pictures[i];

                        if (pic != null && pic.LoadPictureBinary() != null && pic.LoadPictureBinary().Length > 0)
                        {
                            row.Cells[cellNum].AddImage(PictureManager.GetPictureLocalPath(pic, 200, true));
                        }

                        if (i != 0 && i % 2 == 0)
                        {
                            row = table.AddRow();
                        }
                    }

                    section.AddParagraph();
                }

                int pvNum = 1;

                foreach (var productVariant in product.ProductVariants)
                {
                    string pvName = String.IsNullOrEmpty(productVariant.LocalizedName) ? LocalizationManager.GetLocaleResourceString("PDFProductCatalog.UnnamedProductVariant") : productVariant.LocalizedName;
                    section.AddParagraph(String.Format("{0}.{1}. {2}", productNumber, pvNum, pvName));

                    section.AddParagraph();

                    if (!String.IsNullOrEmpty(productVariant.LocalizedDescription))
                    {
                        section.AddParagraph(HtmlHelper.StripTags(HtmlHelper.ConvertHtmlToPlainText(productVariant.LocalizedDescription)));
                        section.AddParagraph();
                    }

                    var pic = productVariant.Picture;
                    if (pic != null && pic.LoadPictureBinary() != null && pic.LoadPictureBinary().Length > 0)
                    {
                        section.AddImage(PictureManager.GetPictureLocalPath(pic, 200, true));
                    }

                    section.AddParagraph(String.Format("{0}: {1} {2}", LocalizationManager.GetLocaleResourceString("PDFProductCatalog.Price"), productVariant.Price, CurrencyManager.PrimaryStoreCurrency.CurrencyCode));
                    section.AddParagraph(String.Format("{0}: {1}", LocalizationManager.GetLocaleResourceString("PDFProductCatalog.SKU"), productVariant.SKU));

                    if (productVariant.Weight > Decimal.Zero)
                    {
                        section.AddParagraph(String.Format("{0}: {1} {2}", LocalizationManager.GetLocaleResourceString("PDFProductCatalog.Weight"), productVariant.Weight, MeasureManager.BaseWeightIn.Name));
                    }

                    if (productVariant.ManageInventory == (int)ManageInventoryMethodEnum.ManageStock)
                    {
                        section.AddParagraph(String.Format("{0}: {1}", LocalizationManager.GetLocaleResourceString("PDFProductCatalog.StockQuantity"), productVariant.StockQuantity));
                    }

                    section.AddParagraph();

                    pvNum++;
                }

                productNumber++;

                if (productNumber <= prodCount)
                {
                    section.AddPageBreak();
                }
            }

            PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);

            renderer.Document = doc;
            renderer.RenderDocument();
            renderer.PdfDocument.Save(filePath);
        }
Exemplo n.º 4
0
        protected void BindData()
        {
            var product = ProductManager.GetProductById(this.ProductId);

            if (product != null)
            {
                lProductName.Text      = Server.HtmlEncode(product.LocalizedName);
                lShortDescription.Text = product.LocalizedShortDescription;
                lFullDescription.Text  = product.LocalizedFullDescription;

                //manufacturers
                List <Manufacturer> manufacturers = new List <Manufacturer>();
                foreach (var pm in product.ProductManufacturers)
                {
                    var manufacturer = pm.Manufacturer;
                    if (manufacturer != null)
                    {
                        manufacturers.Add(manufacturer);
                    }
                }
                if (manufacturers.Count > 0)
                {
                    if (manufacturers.Count == 1)
                    {
                        lManufacturersTitle.Text = GetLocaleResourceString("Products.Manufacturer");
                    }
                    else
                    {
                        lManufacturersTitle.Text = GetLocaleResourceString("Products.Manufacturers");
                    }
                    rptrManufacturers.DataSource = manufacturers;
                    rptrManufacturers.DataBind();
                }
                else
                {
                    phManufacturers.Visible = false;
                }

                //pictures
                var pictures = PictureManager.GetPicturesByProductId(product.ProductId);
                if (pictures.Count > 1)
                {
                    defaultImage.ImageUrl        = PictureManager.GetPictureUrl(pictures[0], SettingManager.GetSettingValueInteger("Media.Product.DetailImageSize", 300));
                    defaultImage.ToolTip         = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.LocalizedName);
                    defaultImage.AlternateText   = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.LocalizedName);
                    lvProductPictures.DataSource = pictures;
                    lvProductPictures.DataBind();
                }
                else if (pictures.Count == 1)
                {
                    defaultImage.ImageUrl      = PictureManager.GetPictureUrl(pictures[0], SettingManager.GetSettingValueInteger("Media.Product.DetailImageSize", 300));
                    defaultImage.ToolTip       = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.LocalizedName);
                    defaultImage.AlternateText = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.LocalizedName);
                    lvProductPictures.Visible  = false;
                }
                else
                {
                    defaultImage.ImageUrl      = PictureManager.GetDefaultPictureUrl(SettingManager.GetSettingValueInteger("Media.Product.DetailImageSize", 300));
                    defaultImage.ToolTip       = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.LocalizedName);
                    defaultImage.AlternateText = String.Format(GetLocaleResourceString("Media.Product.ImageAlternateTextFormat"), product.LocalizedName);
                    lvProductPictures.Visible  = false;
                }
                if (SettingManager.GetSettingValueBoolean("Media.Product.DefaultPictureZoomEnabled", false))
                {
                    var picture = product.DefaultPicture;
                    if (picture != null)
                    {
                        lnkMainLightbox.Attributes["href"] = PictureManager.GetPictureUrl(picture);
                        lnkMainLightbox.Attributes["rel"]  = "lightbox-pd";
                    }
                }
            }
            else
            {
                this.Visible = false;
            }
        }