Beispiel #1
0
 public void SaveGoogleBaseProduct(GoogleBaseProduct item)
 {
     if (item.ProductVariant != null)
     {
         item.ProductVariant.GoogleBaseProducts.Clear();
         item.ProductVariant.GoogleBaseProducts.Add(item);
     }
     _session.Transact(session => session.SaveOrUpdate(item));
 }
Beispiel #2
0
 public ActionResult GoogleBaseProduct(GoogleBaseProduct googleBaseProduct)
 {
     if (googleBaseProduct != null)
     {
         ViewData["product-conditions"] = _optionService.GetEnumOptions <ProductCondition>();
         ViewData["genders"]            = _optionService.GetEnumOptions <Gender>();
         ViewData["age-groups"]         = _optionService.GetEnumOptions <AgeGroup>();
         return(PartialView(googleBaseProduct));
     }
     return(RedirectToAction("Dashboard"));
 }
Beispiel #3
0
 public JsonResult UpdateGoogleBaseProduct(GoogleBaseProduct googleBaseProduct)
 {
     try
     {
         _googleBaseManager.SaveGoogleBaseProduct(googleBaseProduct);
         return(Json(googleBaseProduct.Id));
     }
     catch (Exception ex)
     {
         CurrentRequestData.ErrorSignal.Raise(ex);
         return(Json(false));
     }
 }
Beispiel #4
0
        public void GoogleBaseService_SaveGoogleBaseProduct_ShouldUpdateItem()
        {
            var pv   = new ProductVariant();
            var item = new GoogleBaseProduct {
                ProductVariant = pv
            };

            Session.Transact(session => session.Save(item));
            item.Grouping = "Group2";

            _googleBaseManager.SaveGoogleBaseProduct(item);
            Session.Evict(item);

            Session.QueryOver <GoogleBaseProduct>().SingleOrDefault().Grouping.Should().Be("Group2");
        }
 public void SaveGoogleBaseProduct(GoogleBaseProduct item)
 {
     if (item.ProductVariant != null)
     {
         item.ProductVariant.GoogleBaseProducts.Clear();
         item.ProductVariant.GoogleBaseProducts.Add(item);
     }
     using (var transaction = _session.BeginTransaction())
     {
         if (item.Id == 0)
         {
             _session.Save(item);
         }
         else
         {
             _session.Update(item);
         }
         transaction.Commit();
     }
 }
Beispiel #6
0
        /// <summary>
        ///     Export Google BaseProduct
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="productVariant"></param>
        /// <param name="ns"></param>
        private void ExportGoogleBaseProduct(ref XmlTextWriter xml, ProductVariant productVariant, string ns)
        {
            xml.WriteStartElement("item");

            //TITLE
            string title = String.Empty;

            if (!String.IsNullOrWhiteSpace(productVariant.DisplayName))
            {
                title = productVariant.DisplayName;
            }
            if (title.Length > 70)
            {
                title = title.Substring(0, 70);
            }
            xml.WriteElementString("title", title);

            //LINK
            if (productVariant.Product != null && !String.IsNullOrWhiteSpace(productVariant.DisplayName))
            {
                xml.WriteElementString("link", GeneralHelper.GetValidProductVariantUrl(productVariant));
            }

            //DESCRIPTION
            xml.WriteStartElement("description");
            string description = String.Empty;

            if (productVariant.Product != null && !String.IsNullOrWhiteSpace(productVariant.DisplayName))
            {
                description = productVariant.Product.BodyContent.StripHtml();
            }
            if (productVariant.Product != null && String.IsNullOrEmpty(description))
            {
                description = productVariant.Product.ProductAbstract.StripHtml();
            }
            if (productVariant.Product != null && String.IsNullOrEmpty(description))
            {
                description = productVariant.DisplayName.StripHtml();
            }
            description = XmlCharacterWhitelist(description);
            byte[] descriptionBytes = Encoding.Default.GetBytes(description);
            description = Encoding.UTF8.GetString(descriptionBytes);
            xml.WriteCData(description);
            xml.WriteEndElement();

            GoogleBaseProduct googleBaseProduct = productVariant.GoogleBaseProducts.FirstOrDefault();

            //CONDITION
            xml.WriteElementString("g", "condition", ns,
                                   googleBaseProduct != null
                    ? googleBaseProduct.Condition.ToString()
                    : ProductCondition.New.ToString());

            //PRICE
            xml.WriteElementString("g", "price", ns, productVariant.Price.ToCurrencyFormat());

            //AVAILABILITY
            string availability = "In Stock";

            if (productVariant.TrackingPolicy == TrackingPolicy.Track && _getStockRemainingQuantity.Get(productVariant) <= 0)
            {
                availability = "Out of Stock";
            }
            xml.WriteElementString("g", "availability", ns, availability);

            //GOOGLE PRODUCT CATEGORY
            if (googleBaseProduct != null)
            {
                xml.WriteElementString("g", "google_product_category", ns, googleBaseProduct.Category);
            }

            //PRODUCT CATEGORY
            if (productVariant.Product != null && productVariant.Product.Categories.Any() &&
                !String.IsNullOrWhiteSpace(productVariant.Product.Categories.First().Name))
            {
                xml.WriteElementString("g", "product_type", ns, productVariant.Product.Categories.First().Name);
            }
            else if (googleBaseProduct != null)
            {
                xml.WriteElementString("g", "product_type", ns, googleBaseProduct.Category);
            }

            //IMAGES
            if (productVariant.Product != null && productVariant.Product.Images.Any() &&
                !String.IsNullOrWhiteSpace(productVariant.Product.Images.First().FileUrl))
            {
                xml.WriteElementString("g", "image_link", ns,
                                       GeneralHelper.GetValidImageUrl(productVariant.Product.Images.First().FileUrl));
            }
            if (productVariant.Product != null && productVariant.Product.Images.Count() > 1 &&
                !String.IsNullOrWhiteSpace(productVariant.Product.Images.ToList()[1].FileUrl))
            {
                xml.WriteElementString("g", "additional_image_link", ns,
                                       GeneralHelper.GetValidImageUrl(productVariant.Product.Images.ToList()[1].FileUrl));
            }

            //BRAND
            if (productVariant.Product != null && productVariant.Product.BrandPage != null && !String.IsNullOrWhiteSpace(productVariant.Product.BrandPage.Name))
            {
                xml.WriteElementString("g", "brand", ns, productVariant.Product.BrandPage.Name);
            }

            //ID
            xml.WriteElementString("g", "id", ns, productVariant.Id.ToString(new CultureInfo("en-GB", false).NumberFormat));

            //GTIN
            if (!String.IsNullOrWhiteSpace(productVariant.Barcode))
            {
                xml.WriteElementString("g", "gtin", ns, productVariant.Barcode);
            }

            //MPN
            if (!String.IsNullOrWhiteSpace(productVariant.ManufacturerPartNumber))
            {
                xml.WriteElementString("g", "mpn", ns, productVariant.ManufacturerPartNumber);
            }

            if (googleBaseProduct != null)
            {
                //GENDER
                xml.WriteElementString("g", "gender", ns, googleBaseProduct.Gender.ToString());

                //AGE GROUP
                xml.WriteElementString("g", "age_group", ns, googleBaseProduct.AgeGroup.ToString());
            }

            //ITEM GROUP ID
            if (productVariant.Product != null)
            {
                xml.WriteElementString("g", "item_group_id", ns,
                                       productVariant.Product.Id.ToString(new CultureInfo("en-GB", false).NumberFormat));
            }

            if (googleBaseProduct != null)
            {
                //COLOR
                if (!String.IsNullOrWhiteSpace(googleBaseProduct.Color))
                {
                    xml.WriteElementString("g", "color", ns, googleBaseProduct.Color);
                }

                //SIZE
                if (!String.IsNullOrWhiteSpace(googleBaseProduct.Size))
                {
                    xml.WriteElementString("g", "size", ns, googleBaseProduct.Size);
                }

                //PATTERN
                if (!String.IsNullOrWhiteSpace(googleBaseProduct.Pattern))
                {
                    xml.WriteElementString("g", "pattern", ns, googleBaseProduct.Pattern);
                }

                //MATERIAL
                if (!String.IsNullOrWhiteSpace(googleBaseProduct.Material))
                {
                    xml.WriteElementString("g", "material", ns, googleBaseProduct.Material);
                }
            }

            //SHIPPING
            SetGoogleBaseShipping(ref xml, productVariant, ns);

            //WEIGHT
            xml.WriteElementString("g", "shipping_weight", ns,
                                   string.Format(CultureInfo.InvariantCulture,
                                                 "{0} {1}", productVariant.Weight.ToString(new CultureInfo("en-GB", false).NumberFormat),
                                                 "kg"));

            //ADWORDS
            if (googleBaseProduct != null)
            {
                if (!String.IsNullOrWhiteSpace(googleBaseProduct.Grouping))
                {
                    xml.WriteElementString("g", "adwords_grouping", ns, googleBaseProduct.Grouping);
                }
                if (!String.IsNullOrWhiteSpace(googleBaseProduct.Labels))
                {
                    xml.WriteElementString("g", "adwords_labels", ns, googleBaseProduct.Labels);
                }
                if (!String.IsNullOrWhiteSpace(googleBaseProduct.Redirect))
                {
                    xml.WriteElementString("g", "adwords_redirect", ns, googleBaseProduct.Redirect);
                }
            }

            xml.WriteEndElement();
        }