/// <summary> /// Gets the sample rendering model. /// </summary> /// <param name="rendering">The rendering.</param> /// <param name="propertyBag">The property bag.</param> /// <returns> /// An initilaized sample rendering model is returned. /// </returns> public SampleJsonResult GetSample(IVisitorContext visitorContext, StringPropertyCollection propertyBag = null) { var jsonResult = ModelProvider.GetModel <SampleJsonResult>(); if (PageMode.IsExperienceEditor) { try { var response = SampleManager.GetSample(visitorContext, StorefrontContext, propertyBag); if (!response.ServiceProviderResult.Success) { jsonResult.SetErrors(response.ServiceProviderResult); return(jsonResult); } var sample = response.Result; if (sample != null) { jsonResult.Initialize(sample); } } catch (Exception e) { Log.Error(e.Message, e, this); jsonResult.SetErrors("GetSample", e); return(jsonResult); } } return(jsonResult); }
public SimpleTextRenderingModel RaisePageEvent(IVisitorContext visitorContext, StringPropertyCollection propertyBag = null) { SimpleTextRenderingModel model = this.ModelProvider.GetModel <SimpleTextRenderingModel>(); this.Init((BaseCommerceRenderingModel)model); Item currentCatalogItem = this.SiteContext.CurrentCatalogItem; if (this.Context.IsExperienceEditor) { model.Text = "Visited Product Details Page Event - Invisible at runtime."; } else if (currentCatalogItem != null) { CatalogItemRenderingModel product = this.GetProduct(visitorContext); if (product != null) { if (!string.IsNullOrEmpty(this.XcBaseCatalogRepository.GetPersonalizationId())) { if (propertyBag == null) { propertyBag = new StringPropertyCollection(); } if (!propertyBag.ContainsProperty("PersonalizationId")) { propertyBag.Add("PersonalizationId", this.XcBaseCatalogRepository.GetPersonalizationId()); } } this.CatalogManager.VisitedProductDetailsPage(this.StorefrontContext.CurrentStorefront, visitorContext, product.CatalogItem.ID.ToGuid().ToString(), product.DisplayName, product.ParentCategoryId, product.ParentCategoryName, propertyBag); } } return(model); }
/// <summary> /// Gets the delivery data. /// </summary> /// <param name="visitorContext">The visitor context.</param> /// <param name="propertyBag">The property bag.</param> /// <returns> /// The sample. /// </returns> public SampleRenderingModel GetSampleRenderingModel(IRendering rendering, StringPropertyCollection propertyBag = null) { var model = ModelProvider.GetModel <SampleRenderingModel>(); Init(model); model.Initialize(rendering); return(model); }
public override ProductListRenderingModel GetProductListRenderingModel(StringPropertyCollection propertyBag = null) { _personalizationCache.Remove("PersonalizationId"); if (!string.IsNullOrEmpty(this.PersonalizationId)) { _personalizationCache.Add("PersonalizationId", PersonalizationId); } ProductListRenderingModel model = this.ModelProvider.GetModel <ProductListRenderingModel>(); this.Init(model); model.Initialize(this.SiteContext); return(model); }
/// <summary> /// Gets the sample rendering model. /// </summary> /// <param name="rendering">The rendering.</param> /// <param name="propertyBag">The property bag.</param> /// <returns> /// An initilaized sample rendering model is returned. /// </returns> public SamplesJsonResult GetSamples(IVisitorContext visitorContext, GetSamplesInputModel inputModel, StringPropertyCollection propertyBag = null) { Assert.ArgumentNotNull(inputModel, nameof(inputModel)); var jsonResult = ModelProvider.GetModel <SamplesJsonResult>(); try { var response = SampleManager.GetSamples(StorefrontContext.CurrentStorefront, visitorContext, propertyBag); if (!response.ServiceProviderResult.Success) { jsonResult.SetErrors(response.ServiceProviderResult); return(jsonResult); } var samples = response.Result; if (samples != null) { jsonResult.Initialize(samples); } } catch (Exception e) { Log.Error(e.Message, e, this); jsonResult.SetErrors("GetSample", e); return(jsonResult); } return(jsonResult); }
/// <summary> /// Get the samples for the given visitor context /// </summary> /// <param name="storefront">The storefront</param> /// <param name="visitorContext">The visitor context.</param> /// <param name="propertyBag">The property bag.</param> /// <returns> /// samples for the given visitor context /// </returns> public virtual ManagerResponse <GetSamplesResult, IEnumerable <Sample> > GetSamples(CommerceStorefront storefront, IVisitorContext visitorContext, StringPropertyCollection propertyBag = null) { Assert.ArgumentNotNull(storefront, nameof(storefront)); Assert.ArgumentNotNull(visitorContext, nameof(visitorContext)); var request = new GetSamplesRequest() { CustomerId = visitorContext.CustomerId }; request.CopyPropertyBag(propertyBag); var response = SampleServiceProvider.GetSamples(request); return(new ManagerResponse <GetSamplesResult, IEnumerable <Sample> >(response, response.Samples)); }
/// <summary> /// Get the sample for the given visitor context. /// </summary> /// <param name="visitorContext">The visitor context.</param> /// <param name="storefrontContext">The storefront context.</param> /// <param name="propertyBag">The property bag.</param> /// <returns> /// The sample for the given visitor context. /// </returns> public virtual ManagerResponse <SampleResult, Sample> GetSample(IVisitorContext visitorContext, IStorefrontContext storefrontContext, StringPropertyCollection propertyBag = null) { Assert.ArgumentNotNull(visitorContext, nameof(visitorContext)); Assert.ArgumentNotNull(storefrontContext, nameof(storefrontContext)); var request = new SampleRequest("sample") { CustomerId = visitorContext.CustomerId }; request.CopyPropertyBag(propertyBag); var response = SampleServiceProvider.GetSample(request); return(new ManagerResponse <SampleResult, Sample>(response, response.Sample)); }
public virtual ManagerResponse <CreateUserResult, CommerceUser> RegisterUser(IStorefrontContext storefrontContext, string userName, string password, string email, StringPropertyCollection propertyBag = null) { Diagnostics.Assert.ArgumentNotNull(storefrontContext, "storefrontContext"); Diagnostics.Assert.ArgumentNotNullOrEmpty(userName, "userName"); Diagnostics.Assert.ArgumentNotNullOrEmpty(password, "password"); CreateUserResult createUserResult; try { CreateUserRequest request = new CreateUserRequest(userName, password, email, storefrontContext.CurrentStorefront.ShopName); request.CopyPropertyBag(propertyBag); createUserResult = _customerServiceProvider.CreateUser(request); if (!createUserResult.Success) { Helpers.LogSystemMessages(createUserResult.SystemMessages, createUserResult); } else if (createUserResult.Success && createUserResult.CommerceUser == null && createUserResult.SystemMessages.Count == 0) { createUserResult.Success = false; createUserResult.SystemMessages.Add(new SystemMessage { Message = storefrontContext.GetSystemMessage("User Already Exists") }); } } catch (MembershipCreateUserException ex) { createUserResult = new CreateUserResult { Success = false }; createUserResult.SystemMessages.Add(new SystemMessage { Message = ex.StatusCode.ToString() }); } catch (Exception ex) { createUserResult = new CreateUserResult { Success = false }; createUserResult.SystemMessages.Add(new SystemMessage { Message = storefrontContext.GetSystemMessage("Unknown Membership Provider Error") }); } return(new ManagerResponse <CreateUserResult, CommerceUser>(createUserResult, createUserResult.CommerceUser)); }
public override ManagerResponse <GetProductBulkPricesResult, bool> GetProductBulkPrices(CommerceStorefront storefront, IVisitorContext visitorContext, IEnumerable <ProductEntity> productEntityList, StringPropertyCollection propertyBag = null) { if (productEntityList == null || !productEntityList.Any()) { return(new ManagerResponse <GetProductBulkPricesResult, bool>(new GetProductBulkPricesResult(), true)); } string catalogName = productEntityList.Select(p => p.CatalogName).FirstOrDefault(); List <string> list = productEntityList.Select(p => p.ProductId + (p.Variants != null && p.Variants.Any()? "|" + p.Variants.First().VariantId : "")).ToList(); ManagerResponse <GetProductBulkPricesResult, IDictionary <string, Price> > productBulkPrices = this.PricingManager.GetProductBulkPrices(storefront, visitorContext, catalogName, list, propertyBag, null); IDictionary <string, Price> source = productBulkPrices == null || productBulkPrices.Result == null ? new Dictionary <string, Price>() : productBulkPrices.Result; foreach (ProductEntity productEntity in productEntityList) { Price price; if (source.Any() && source.TryGetValue(productEntity.ProductId, out price)) { CommercePrice commercePrice = (CommercePrice)price; productEntity.ListPrice = commercePrice.LowestPricedVariantListPrice.HasValue? commercePrice.LowestPricedVariantListPrice.Value : new decimal?(commercePrice.Amount); productEntity.AdjustedPrice = commercePrice.LowestPricedVariant.HasValue? commercePrice.LowestPricedVariant : new decimal?(commercePrice.ListPrice); productEntity.LowestPricedVariantAdjustedPrice = commercePrice.LowestPricedVariant; productEntity.LowestPricedVariantListPrice = commercePrice.LowestPricedVariantListPrice; productEntity.HighestPricedVariantAdjustedPrice = commercePrice.HighestPricedVariant; } } return(new ManagerResponse <GetProductBulkPricesResult, bool>(new GetProductBulkPricesResult(), true)); }
public override BaseJsonResult GetProductStockInformation(string productId, StringPropertyCollection propertyBag = null) { StockInfoListJsonResult model = this.ModelProvider.GetModel <StockInfoListJsonResult>(); if (string.IsNullOrWhiteSpace(productId)) { return(model); } try { CommerceStorefront currentStorefront = this.StorefrontContext.CurrentStorefront; string catalog = currentStorefront.Catalog; Item product = this.SearchManager.GetProduct(productId, catalog); Assert.IsNotNull(product, string.Format(CultureInfo.InvariantCulture, "Unable to locate the product with id: {0}", productId)); bool includeBundledItemsInventory = this.ItemTypeProvider.IsBundle(product); List <CommerceInventoryProduct> inventoryProductList1 = new List <CommerceInventoryProduct>(); if (!includeBundledItemsInventory && product.HasChildren) { var childList = product.Children.Where(child => { var variantPersonalizationId = child["PersonalizationId"]; var liveDate = child["LiveDate"]; var expiryDate = child["ExpiryDate"]; if (this.PersonalizationId.Equals(child["PersonalizationId"], System.StringComparison.OrdinalIgnoreCase)) { if (!string.IsNullOrEmpty(liveDate)) { var parseSuccess = DateTimeOffset.TryParseExact(liveDate, "yyyyMMddTHHmmss", null, DateTimeStyles.None, out var variantLiveDate); if (parseSuccess && variantLiveDate > DateTimeOffset.Now) { return(false); } } if (!string.IsNullOrEmpty(expiryDate)) { var parseSuccess = DateTimeOffset.TryParseExact(expiryDate, "yyyyMMddTHHmmss", null, DateTimeStyles.None, out var variantExpiryDate); if (parseSuccess && variantExpiryDate <= DateTimeOffset.Now) { return(false); } } return(true); } return(false); }); if (!childList.Any()) { childList = product.Children.Where(child => string.IsNullOrEmpty(child["PersonalizationId"])); } foreach (Item child in childList) { List <CommerceInventoryProduct> inventoryProductList2 = inventoryProductList1; CommerceInventoryProduct inventoryProduct = new CommerceInventoryProduct(); inventoryProduct.ProductId = productId; inventoryProduct.CatalogName = catalog; inventoryProduct.VariantId = child.Name; inventoryProductList2.Add(inventoryProduct); } } else { List <CommerceInventoryProduct> inventoryProductList2 = inventoryProductList1; CommerceInventoryProduct inventoryProduct = new CommerceInventoryProduct(); inventoryProduct.ProductId = productId; inventoryProduct.CatalogName = catalog; inventoryProductList2.Add(inventoryProduct); } ManagerResponse <GetStockInformationResult, IEnumerable <StockInformation> > stockInformation = this.InventoryManager.GetStockInformation(currentStorefront, inventoryProductList1, StockDetailsLevel.All, includeBundledItemsInventory, propertyBag); if (!stockInformation.ServiceProviderResult.Success) { model.SetErrors(stockInformation.ServiceProviderResult); } else { model.Initialize(stockInformation.Result); } } catch (Exception ex) { model.SetErrors("GetCurrentProductStockInfo", ex); } return(model); }
public Organisation() { BillingExtraInfo = new StringPropertyCollection(); }
public override ProductListJsonResult GetProductListJsonResult(IVisitorContext visitorContext, string currentItemId, string currentCatalogItemId, string searchKeyword, int?pageNumber, string facetValues, string sortField, int?pageSize, SortDirection?sortDirection, StringPropertyCollection propertyBag = null) { var model = base.GetProductListJsonResult(visitorContext, currentItemId, currentCatalogItemId, searchKeyword, pageNumber, facetValues, sortField, pageSize, sortDirection, propertyBag); var personalizationId = _personalizationCache.ContainsKey("PersonalizationId") ? _personalizationCache.GetValue("PersonalizationId").ToString() : string.Empty; foreach (var subModel in model.ChildProducts) { if (subModel.CatalogItem.HasChildren) { var childList = subModel.CatalogItem.Children.Where(child => { var variantPersonalizationId = child["PersonalizationId"]; var liveDate = child["LiveDate"]; var expiryDate = child["ExpiryDate"]; if (personalizationId.Equals(child["PersonalizationId"], System.StringComparison.OrdinalIgnoreCase)) { if (!string.IsNullOrEmpty(liveDate)) { var parseSuccess = DateTimeOffset.TryParseExact(liveDate, "yyyyMMddTHHmmss", null, DateTimeStyles.None, out var variantLiveDate); if (parseSuccess && variantLiveDate > DateTimeOffset.Now) { return(false); } } if (!string.IsNullOrEmpty(expiryDate)) { var parseSuccess = DateTimeOffset.TryParseExact(expiryDate, "yyyyMMddTHHmmss", null, DateTimeStyles.None, out var variantExpiryDate); if (parseSuccess && variantExpiryDate <= DateTimeOffset.Now) { return(false); } } return(true); } return(false); }); if (!childList.Any()) { childList = subModel.CatalogItem.Children.Where(child => string.IsNullOrEmpty(child["PersonalizationId"])); } foreach (Item child in childList) { MultilistField field = child.Fields["Images"]; if (field != null) { subModel.Images.Clear(); foreach (ID targetId in field.TargetIDs) { subModel.Images.Add(child.Database.GetItem(targetId)); } return(model); } } } } return(model); }
protected override ICollection <ProductEntity> AdjustProductPriceAndStockStatus(IVisitorContext visitorContext, SearchResults searchResult, Item currentCategory, StringPropertyCollection propertyBag = null) { Assert.ArgumentNotNull(currentCategory, nameof(currentCategory)); Assert.ArgumentNotNull(searchResult, nameof(searchResult)); CommerceStorefront currentStorefront = this.StorefrontContext.CurrentStorefront; List <ProductEntity> productEntityList = new List <ProductEntity>(); string str = "Category/" + currentCategory.Name; if (this.SiteContext.Items[str] != null) { return((ICollection <ProductEntity>) this.SiteContext.Items[str]); } if (searchResult.SearchResultItems != null && searchResult.SearchResultItems.Count > 0) { foreach (Item searchResultItem in searchResult.SearchResultItems) { ProductEntity model = this.ModelProvider.GetModel <ProductEntity>(); model.Initialize(currentStorefront, searchResultItem, this.GetProductVariants(searchResultItem)); productEntityList.Add(model); } this.CatalogManager.GetProductBulkPrices(currentStorefront, visitorContext, productEntityList, null); this.InventoryManager.GetProductsStockStatus(currentStorefront, productEntityList, currentStorefront.UseIndexFileForProductStatusInLists, null); foreach (ProductEntity productEntity1 in productEntityList) { ProductEntity productEntity = productEntity1; Item productItem = searchResult.SearchResultItems.FirstOrDefault(item => { if (item.Name == productEntity.ProductId) { return(item.Language == Context.Language); } return(false); }); if (productItem != null) { productEntity.CustomerAverageRating = this.CatalogManager.GetProductRating(productItem, null); } } } this.SiteContext.Items[str] = productEntityList; return(productEntityList); }
public CatalogItemVariantsRenderingModel GetProductImagesRenderingModel(IVisitorContext visitorContext, StringPropertyCollection propertyBag = null) { return(GetProduct(visitorContext)); }