public void Can_parse_host_values() { var store = new Store() { Hosts = "yourstore.com, www.yourstore.com, " }; var hosts = store.ParseHostValues(); hosts.Length.ShouldEqual(2); hosts[0].ShouldEqual("yourstore.com"); hosts[1].ShouldEqual("www.yourstore.com"); }
public void Can_find_host_value() { var store = new Store() { Hosts = "yourstore.com, www.yourstore.com, " }; store.ContainsHostValue(null).ShouldEqual(false); store.ContainsHostValue("").ShouldEqual(false); store.ContainsHostValue("store.com").ShouldEqual(false); store.ContainsHostValue("yourstore.com").ShouldEqual(true); store.ContainsHostValue("yoursTore.com").ShouldEqual(true); store.ContainsHostValue("www.yourstore.com").ShouldEqual(true); }
/// <summary> /// Deletes a store /// </summary> /// <param name="store">Store</param> public virtual void DeleteStore(Store store) { if (store == null) throw new ArgumentNullException("store"); var allStores = GetAllStores(); if (allStores.Count == 1) throw new Exception("You cannot delete the only configured store"); _storeRepository.Delete(store); _cacheManager.RemoveByPattern(STORES_PATTERN_KEY); //event notification _eventPublisher.EntityDeleted(store); }
public void Can_save_and_load_store() { var store = new Store { Name = "Computer store", Url = "http://www.yourStore.com", Hosts = "yourStore.com,www.yourStore.com", DisplayOrder = 1 }; var fromDb = SaveAndLoadEntity(store); fromDb.ShouldNotBeNull(); fromDb.Name.ShouldEqual("Computer store"); fromDb.Url.ShouldEqual("http://www.yourStore.com"); fromDb.Hosts.ShouldEqual("yourStore.com,www.yourStore.com"); fromDb.DisplayOrder.ShouldEqual(1); }
public virtual void AddStoreTokens(IList<Token> tokens, Store store) { tokens.Add(new Token("Store.Name", store.Name)); tokens.Add(new Token("Store.URL", store.Url, true)); var defaultEmailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId); if (defaultEmailAccount == null) defaultEmailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault(); tokens.Add(new Token("Store.Email", defaultEmailAccount.Email)); }
/// <summary> /// Generate a feed /// </summary> /// <param name="stream">Stream</param> /// <param name="store">Store</param> /// <returns>Generated feed</returns> public void GenerateFeed(Stream stream, Store store) { if (stream == null) throw new ArgumentNullException("stream"); if (store == null) throw new ArgumentNullException("store"); const string googleBaseNamespace = "http://base.google.com/ns/1.0"; var settings = new XmlWriterSettings { Encoding = Encoding.UTF8 }; using (var writer = XmlWriter.Create(stream, settings)) { //Generate feed according to the following specs: http://www.google.com/support/merchants/bin/answer.py?answer=188494&expand=GB writer.WriteStartDocument(); writer.WriteStartElement("rss"); writer.WriteAttributeString("version", "2.0"); writer.WriteAttributeString("xmlns", "g", null, googleBaseNamespace); writer.WriteStartElement("channel"); writer.WriteElementString("title", "Google Base feed"); writer.WriteElementString("link", "http://base.google.com/base/"); writer.WriteElementString("description", "Information about products"); var products = _productService.SearchProducts(storeId: store.Id); foreach (var product in products) { var productVariants = _productService.GetProductVariantsByProductId(product.Id); foreach (var productVariant in productVariants) { writer.WriteStartElement("item"); #region Basic Product Information //id [id]- An identifier of the item writer.WriteElementString("g", "id", googleBaseNamespace, productVariant.Id.ToString()); //title [title] - Title of the item writer.WriteStartElement("title"); var title = productVariant.FullProductName; //title should be not longer than 70 characters if (title.Length > 70) title = title.Substring(0, 70); writer.WriteCData(title); writer.WriteEndElement(); // title //description [description] - Description of the item 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; if (String.IsNullOrEmpty(description)) description = productVariant.FullProductName; //description is required //resolving character encoding issues in your data feed description = StripInvalidChars(description, true); writer.WriteCData(description); writer.WriteEndElement(); // description //google product category [google_product_category] - Google's category of the item //the category of the product according to Google’s product taxonomy. http://www.google.com/support/merchants/bin/answer.py?answer=160081 string googleProductCategory = ""; var googleProduct = _googleService.GetByProductVariantId(productVariant.Id); if (googleProduct != null) googleProductCategory = googleProduct.Taxonomy; if (String.IsNullOrEmpty(googleProductCategory)) googleProductCategory = _froogleSettings.DefaultGoogleCategory; if (String.IsNullOrEmpty(googleProductCategory)) throw new NasException("Default Google category is not set"); writer.WriteStartElement("g", "google_product_category", googleBaseNamespace); writer.WriteCData(googleProductCategory); writer.WriteFullEndElement(); // g:google_product_category //product type [product_type] - Your category of the item var defaultProductCategory = _categoryService.GetProductCategoriesByProductId(product.Id).FirstOrDefault(); if (defaultProductCategory != null) { var categoryBreadCrumb = GetCategoryBreadCrumb(defaultProductCategory.Category); string yourProductCategory = ""; for (int i = 0; i < categoryBreadCrumb.Count; i++) { var cat = categoryBreadCrumb[i]; yourProductCategory = yourProductCategory + cat.Name; if (i != categoryBreadCrumb.Count - 1) yourProductCategory = yourProductCategory + " > "; } if (!String.IsNullOrEmpty((yourProductCategory))) { writer.WriteStartElement("g", "product_type", googleBaseNamespace); writer.WriteCData(yourProductCategory); writer.WriteFullEndElement(); // g:product_type } } //link [link] - URL directly linking to your item's page on your website var productUrl = string.Format("{0}{1}", store.Url, product.GetSeName(_workContext.WorkingLanguage.Id)); writer.WriteElementString("link", productUrl); //image link [image_link] - URL of an image of the item string imageUrl; var picture = _pictureService.GetPictureById(productVariant.PictureId); if (picture == null) picture = _pictureService.GetPicturesByProductId(product.Id, 1).FirstOrDefault(); if (picture != null) imageUrl = _pictureService.GetPictureUrl(picture, _froogleSettings.ProductPictureSize, storeLocation: store.Url); else imageUrl = _pictureService.GetDefaultPictureUrl(_froogleSettings.ProductPictureSize, storeLocation: store.Url); writer.WriteElementString("g", "image_link", googleBaseNamespace, imageUrl); //condition [condition] - Condition or state of the item writer.WriteElementString("g", "condition", googleBaseNamespace, "new"); #endregion #region Availability & Price //availability [availability] - Availability status of the item string availability = "in stock"; //in stock by default if (productVariant.ManageInventoryMethod == ManageInventoryMethod.ManageStock && productVariant.StockQuantity <= 0) { switch (productVariant.BackorderMode) { case BackorderMode.NoBackorders: { availability = "out of stock"; } break; case BackorderMode.AllowQtyBelow0: case BackorderMode.AllowQtyBelow0AndNotifyCustomer: { availability = "available for order"; //availability = "preorder"; } break; default: break; } } writer.WriteElementString("g", "availability", googleBaseNamespace, availability); //price [price] - Price of the item var currency = GetUsedCurrency(); decimal price = _currencyService.ConvertFromPrimaryStoreCurrency(productVariant.Price, currency); writer.WriteElementString("g", "price", googleBaseNamespace, price.ToString(new CultureInfo("en-US", false).NumberFormat) + " " + currency.CurrencyCode); #endregion #region Unique Product Identifiers /* Unique product identifiers such as UPC, EAN, JAN or ISBN allow us to show your listing on the appropriate product page. If you don't provide the required unique product identifiers, your store may not appear on product pages, and all your items may be removed from Product Search. * We require unique product identifiers for all products - except for custom made goods. For apparel, you must submit the 'brand' attribute. For media (such as books, movies, music and video games), you must submit the 'gtin' attribute. In all cases, we recommend you submit all three attributes. * You need to submit at least two attributes of 'brand', 'gtin' and 'mpn', but we recommend that you submit all three if available. For media (such as books, movies, music and video games), you must submit the 'gtin' attribute, but we recommend that you include 'brand' and 'mpn' if available. */ //GTIN [gtin] - GTIN var gtin = productVariant.Gtin; if (!String.IsNullOrEmpty(gtin)) { writer.WriteStartElement("g", "gtin", googleBaseNamespace); writer.WriteCData(gtin); writer.WriteFullEndElement(); // g:gtin } //brand [brand] - Brand of the item var defaultManufacturer = _manufacturerService.GetProductManufacturersByProductId((product.Id)).FirstOrDefault(); if (defaultManufacturer != null) { writer.WriteStartElement("g", "brand", googleBaseNamespace); writer.WriteCData(defaultManufacturer.Manufacturer.Name); writer.WriteFullEndElement(); // g:brand } //mpn [mpn] - Manufacturer Part Number (MPN) of the item var mpn = productVariant.ManufacturerPartNumber; if (!String.IsNullOrEmpty(mpn)) { writer.WriteStartElement("g", "mpn", googleBaseNamespace); writer.WriteCData(mpn); writer.WriteFullEndElement(); // g:mpn } #endregion #region Apparel Products /* Apparel includes all products that fall under 'Apparel & Accessories' (including all sub-categories) * in Google’s product taxonomy. */ //gender [gender] - Gender of the item if (googleProduct != null && !String.IsNullOrEmpty(googleProduct.Gender)) { writer.WriteStartElement("g", "gender", googleBaseNamespace); writer.WriteCData(googleProduct.Gender); writer.WriteFullEndElement(); // g:gender } //age group [age_group] - Target age group of the item if (googleProduct != null && !String.IsNullOrEmpty(googleProduct.AgeGroup)) { writer.WriteStartElement("g", "age_group", googleBaseNamespace); writer.WriteCData(googleProduct.AgeGroup); writer.WriteFullEndElement(); // g:age_group } //color [color] - Color of the item if (googleProduct != null && !String.IsNullOrEmpty(googleProduct.Color)) { writer.WriteStartElement("g", "color", googleBaseNamespace); writer.WriteCData(googleProduct.Color); writer.WriteFullEndElement(); // g:color } //size [size] - Size of the item if (googleProduct != null && !String.IsNullOrEmpty(googleProduct.Size)) { writer.WriteStartElement("g", "size", googleBaseNamespace); writer.WriteCData(googleProduct.Size); writer.WriteFullEndElement(); // g:size } #endregion #region Tax & Shipping //tax [tax] //The tax attribute is an item-level override for merchant-level tax settings as defined in your Google Merchant Center account. This attribute is only accepted in the US, if your feed targets a country outside of the US, please do not use this attribute. //IMPORTANT NOTE: Set tax in your Google Merchant Center account settings //IMPORTANT NOTE: Set shipping in your Google Merchant Center account settings //shipping weight [shipping_weight] - Weight of the item for shipping //We accept only the following units of weight: lb, oz, g, kg. if (_froogleSettings.PassShippingInfo) { var weightName = "kg"; var shippingWeight = productVariant.Weight; switch (_measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).SystemKeyword) { case "ounce": weightName = "oz"; break; case "lb": weightName = "lb"; break; case "grams": weightName = "g"; break; case "kg": weightName = "kg"; break; default: //unknown weight weightName = "kg"; break; } writer.WriteElementString("g", "shipping_weight", googleBaseNamespace, string.Format(CultureInfo.InvariantCulture, "{0} {1}", shippingWeight.ToString(new CultureInfo("en-US", false).NumberFormat), weightName)); } #endregion writer.WriteElementString("g", "expiration_date", googleBaseNamespace, DateTime.Now.AddDays(28).ToString("yyyy-MM-dd")); writer.WriteEndElement(); // item } } writer.WriteEndElement(); // channel writer.WriteEndElement(); // rss writer.WriteEndDocument(); } }
/// <summary> /// Generate a static file for froogle /// </summary> /// <param name="store">Store</param> public virtual void GenerateStaticFile(Store store) { if (store == null) throw new ArgumentNullException("store"); string filePath = System.IO.Path.Combine(HttpRuntime.AppDomainAppPath, "content\\files\\exportimport", store.Id + "-" + _froogleSettings.StaticFileName); using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)) { GenerateFeed(fs, store); } }
/// <summary> /// Updates the store /// </summary> /// <param name="store">Store</param> public virtual void UpdateStore(Store store) { if (store == null) throw new ArgumentNullException("store"); _storeRepository.Update(store); _cacheManager.RemoveByPattern(STORES_PATTERN_KEY); //event notification _eventPublisher.EntityUpdated(store); }
public static Store ToEntity(this StoreModel model, Store destination) { return Mapper.Map(model, destination); }
public new void SetUp() { _genericAttributeService = MockRepository.GenerateMock<IGenericAttributeService>(); _settingService = MockRepository.GenerateMock<ISettingService>(); _workContext = MockRepository.GenerateMock<IWorkContext>(); _store = new Store() { Id = 1 }; _storeContext = MockRepository.GenerateMock<IStoreContext>(); _storeContext.Expect(x => x.CurrentStore).Return(_store); _dateTimeSettings = new DateTimeSettings() { AllowCustomersToSetTimeZone = false, DefaultStoreTimeZoneId = "" }; _dateTimeHelper = new DateTimeHelper(_workContext, _genericAttributeService, _settingService, _dateTimeSettings); }
public new void SetUp() { _workContext = MockRepository.GenerateMock<IWorkContext>(); _store = new Store() { Id = 1 }; _storeContext = MockRepository.GenerateMock<IStoreContext>(); _storeContext.Expect(x => x.CurrentStore).Return(_store); var pluginFinder = new PluginFinder(); var cacheManager = new NasNullCache(); //price calculation service _discountService = MockRepository.GenerateMock<IDiscountService>(); _categoryService = MockRepository.GenerateMock<ICategoryService>(); _productAttributeParser = MockRepository.GenerateMock<IProductAttributeParser>(); _shoppingCartSettings = new ShoppingCartSettings(); _catalogSettings = new CatalogSettings(); _priceCalcService = new PriceCalculationService(_workContext, _discountService, _categoryService, _productAttributeParser, _shoppingCartSettings, _catalogSettings); _eventPublisher = MockRepository.GenerateMock<IEventPublisher>(); _eventPublisher.Expect(x => x.Publish(Arg<object>.Is.Anything)); _localizationService = MockRepository.GenerateMock<ILocalizationService>(); //shipping _shippingSettings = new ShippingSettings(); _shippingSettings.ActiveShippingRateComputationMethodSystemNames = new List<string>(); _shippingSettings.ActiveShippingRateComputationMethodSystemNames.Add("FixedRateTestShippingRateComputationMethod"); _shippingMethodRepository = MockRepository.GenerateMock<IRepository<ShippingMethod>>(); _logger = new NullLogger(); _shippingService = new ShippingService(_shippingMethodRepository, _logger, _productAttributeParser, _checkoutAttributeParser, _genericAttributeService, _localizationService, _shippingSettings, pluginFinder, _eventPublisher, _shoppingCartSettings); _paymentService = MockRepository.GenerateMock<IPaymentService>(); _checkoutAttributeParser = MockRepository.GenerateMock<ICheckoutAttributeParser>(); _giftCardService = MockRepository.GenerateMock<IGiftCardService>(); _genericAttributeService = MockRepository.GenerateMock<IGenericAttributeService>(); _eventPublisher = MockRepository.GenerateMock<IEventPublisher>(); _eventPublisher.Expect(x => x.Publish(Arg<object>.Is.Anything)); //tax _taxSettings = new TaxSettings(); _taxSettings.ShippingIsTaxable = true; _taxSettings.PaymentMethodAdditionalFeeIsTaxable = true; _taxSettings.DefaultTaxAddressId = 10; _addressService = MockRepository.GenerateMock<IAddressService>(); _addressService.Expect(x => x.GetAddressById(_taxSettings.DefaultTaxAddressId)).Return(new Address() { Id = _taxSettings.DefaultTaxAddressId }); _taxService = new TaxService(_addressService, _workContext, _taxSettings, pluginFinder); _rewardPointsSettings = new RewardPointsSettings(); _orderTotalCalcService = new OrderTotalCalculationService(_workContext, _storeContext, _priceCalcService, _taxService, _shippingService, _paymentService, _checkoutAttributeParser, _discountService, _giftCardService, _genericAttributeService, _taxSettings, _rewardPointsSettings, _shippingSettings, _shoppingCartSettings, _catalogSettings); }