private IEnumerable <IEntity> GetEntities(CatalogEntryDto.CatalogEntryRow entry, IEnumerable <string> languages, string catalogName, ESalesVariantHelper variantHelper) { foreach (var language in languages) { var locale = language.ToESalesLocale(); var attributes = new List <Attribute> { NewAttribute("id", entry.CatalogEntryId + "_" + language), NewAttribute("_id", entry.CatalogEntryId), NewAttribute("code", entry.Code), NewAttribute("name", entry.Name), NewAttribute("_lang", language), NewAttribute("locale", locale), NewAttribute("locale_filter", locale), NewAttribute("startdate", entry.StartDate), NewAttribute("enddate", entry.EndDate), NewAttribute("_classtype", entry.ClassTypeId.ToLowerInvariant()), NewAttribute("_catalog", catalogName), NewAttribute("product_url", _urlResolver.GetEntryUrl(entry, language)) }; attributes.AddRange(GetPrices(entry)); attributes.AddRange(GetNodeEntryRelations(catalogName, new CatalogEntryRowMapper(entry))); attributes.AddRange(GetMetaData(entry, language)); AddAds(entry, attributes); AddFacets(attributes); var filteredAttributes = FilterConfiguredAttributes(attributes); yield return(GetEntity(entry, variantHelper, language, filteredAttributes)); } }
public static IEnumerable <CatalogEntryDto.CatalogItemSeoRow> GetSeo(this CatalogEntryDto.CatalogEntryRow entry) { var seo = new CatalogEntryDto.CatalogItemSeoDataTable(); seo.AddCatalogItemSeoRow("sv-se", 1, entry, entry.Name + ".aspx", entry.Name, entry.Name, entry.Name, ApplicationId, ""); return(seo); }
public IEnumerable <IEntity> Convert(CatalogEntryDto.CatalogEntryRow entry, IEnumerable <string> languages, CatalogDto.CatalogRow catalog, ESalesVariantHelper variantHelper) { var entities = GetEntities(entry, languages, catalog.Name, variantHelper); return(entities); }
private void BindTargetItems() { if (!String.IsNullOrEmpty(CatalogEntryIds)) { string[] ids = CatalogEntryIds.Split(','); Items.Clear(); for (int i = 0; i < ids.Length; i++) { CatalogEntryDto ent = CatalogContext.Current.GetCatalogEntryDto(int.Parse(ids[i])); if (ent != null && ent.CatalogEntry.Count > 0) { CatalogEntryDto.CatalogEntryRow row = ent.CatalogEntry[0]; Items.Add(new ListItem(row.Name, row.Code)); } } } if (Items != null && Items.Count > 0) { lbTarget.Items.Clear(); foreach (ListItem li in Items) { lbTarget.Items.Add(li); li.Selected = true; ltlSelector.Items.Add(li); } } }
protected override void OnCatalogEntryIndex(ref SearchDocument document, CatalogEntryDto.CatalogEntryRow entry, string language) { if (entry.ClassTypeId != "Product") { return; } var result = GetDocument(language, entry.Code).Result; if (result == null) { throw new Exception(String.Format("could not connect to {0}, please make sure site is active", _url + String.Format("referenceapi/searchdocuments/{0}/{1}", language, entry.Code))); } foreach (var field in result.Fields.Where(field => field.Values.Any())) { document.Add ( field.IsDecimal ? new SearchField(field.Name, Decimal.Parse(field.Values.First(), CultureInfo.InvariantCulture), field.Attributes.ToArray()) : new SearchField(field.Name, field.Values.First(), field.Attributes.ToArray()) ); } }
/// <summary> /// Indexes the catalog entry dto. /// </summary> /// <param name="entryRow">The entry row.</param> /// <param name="languages">The languages.</param> private static int IndexCatalogEntryDto(CatalogEntryDto.CatalogEntryRow entryRow, string[] languages) { int indexCounter = 0; CatalogContext.MetaDataContext.UseCurrentUICulture = false; MetaObjectSerialized serialized = new MetaObjectSerialized(); foreach (string language in languages) { CatalogContext.MetaDataContext.Language = language; MetaObject metaObj = null; metaObj = MetaObject.Load(CatalogContext.MetaDataContext, entryRow.CatalogEntryId, entryRow.MetaClassId); if (metaObj == null) { continue; } serialized.AddMetaObject(language, metaObj); indexCounter++; } entryRow.SerializedData = serialized.BinaryValue; CatalogContext.MetaDataContext.UseCurrentUICulture = true; return(indexCounter); }
private void PopulateVariationInfo(CatalogEntryDto.CatalogEntryRow entryRow, LineItem lineItem) { CatalogEntryDto.VariationRow variationRow = entryRow.GetVariationRows().FirstOrDefault(); if (variationRow != null) { lineItem.MaxQuantity = variationRow.MaxQuantity; lineItem.MinQuantity = variationRow.MinQuantity; CustomerContact customerContact = CustomerContext.Current.GetContactById(lineItem.Parent.Parent.CustomerId); Money?newListPrice = GetItemPrice(entryRow, lineItem, customerContact); if (newListPrice.HasValue) { Money oldListPrice = new Money(Math.Round(lineItem.ListPrice, 2), lineItem.Parent.Parent.BillingCurrency); if (oldListPrice != newListPrice.Value) { AddWarningSafe(Warnings, "LineItemPriceChange-" + lineItem.Parent.LineItems.IndexOf(lineItem).ToString(), string.Format("Price for \"{0}\" has been changed from {1} to {2}.", lineItem.DisplayName, oldListPrice.ToString(), newListPrice.ToString())); // Set new price on line item. lineItem.ListPrice = newListPrice.Value.Amount; if (lineItem.Parent.Parent.ProviderId.ToLower().Equals("frontend")) { lineItem.PlacedPrice = newListPrice.Value.Amount; } } } } }
/// <summary> /// Called when a catalog entry is indexed. /// We use this method to load the prices for the variants of a product and store /// the highest variant price on the product for optimal retrieval in the product listing. /// </summary> protected override void OnCatalogEntryIndex(ref SearchDocument document, CatalogEntryDto.CatalogEntryRow entry, string language) { if (!entry.ClassTypeId.Equals(EntryType.Product)) { return; } UpdateSearchDocument(ref document, entry, language); }
private static IEnumerable <CatalogEntryDto.VariationRow> GetEntryVariations(CatalogEntryDto.CatalogEntryRow catalogEntry) { if (catalogEntry == null) { throw new ArgumentNullException("catalogEntry"); } return(catalogEntry.GetVariationRows()); }
/// <summary> /// Pre processes item record adding additional LineItems if needed. /// </summary> /// <param name="order">The order.</param> /// <param name="record">The record.</param> private void PreProcessItemRecord(OrderGroup order, PromotionItemRecord record) { // We do special logic for the gift promotion reward if (record.PromotionReward is GiftPromotionReward) { // Check if item already in the cart, if not add if (((GiftPromotionReward)record.PromotionReward).AddStrategy == GiftPromotionReward.Strategy.AddWhenNeeded) { // We assume that all affected entries are the gifts that need to be added to the cart foreach (PromotionEntry entry in record.AffectedEntriesSet.Entries) { LineItem giftLineItem = FindGiftLineItemInOrder(order, entry.CatalogEntryCode, record); if (!IsOrderHaveSpecifiedGiftPromotion(order, record)) { // Didn't find, add it if (giftLineItem == null) { // we should some kind of delegate or common implementation here so we can use the same function in both discount and front end CatalogEntryResponseGroup responseGroup = new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Variations); Entry catEntry = CatalogContext.Current.GetCatalogEntry(entry.CatalogEntryCode, responseGroup); giftLineItem = AddNewGiftLineItemToOrder(order, catEntry, entry.Quantity); AddGiftItemToAShipment(giftLineItem, giftLineItem.Parent.LineItems.Count - 1); CatalogEntryDto entryDto = CatalogContext.Current.GetCatalogEntryDto(giftLineItem.Code, responseGroup); CatalogEntryDto.CatalogEntryRow entryRow = entryDto.CatalogEntry[0]; Money?price = GetItemPrice(entryRow, giftLineItem, CustomerContext.Current.CurrentContact); giftLineItem.ListPrice = price.HasValue ? price.Value.Amount : 0m; giftLineItem.PlacedPrice = giftLineItem.ListPrice; // populate inventory information for giftLineItem var aggregateInventory = ServiceLocator.Current.GetInstance <IInventoryService>().QueryByEntry(new [] { entryRow.Code }); foreach (var inventoryRecord in aggregateInventory) { PopulateInventoryInfo(inventoryRecord, giftLineItem); } } else { giftLineItem.Quantity = Math.Max(entry.Quantity, giftLineItem.Quantity); var index = giftLineItem.Parent.LineItems.IndexOf(giftLineItem); if (!giftLineItem.Parent.Shipments.SelectMany(x => x.LineItemIndexes).Contains(index.ToString())) { AddGiftItemToAShipment(giftLineItem, index); } } } else { entry.Quantity = giftLineItem != null?Math.Min(entry.Quantity, giftLineItem.Quantity) : entry.Quantity; } entry.Owner = giftLineItem; entry.CostPerEntry = giftLineItem != null ? giftLineItem.ListPrice : 0m; } } } }
/// <summary> /// Creates a line item. /// Code copied from OrderHelper.cs. /// </summary> /// <param name="random">A Random object seeded from the start of test method.</param> /// <returns></returns> private LineItem createLineItem(Random random, Guid shippingMethod, String shippingMethodName) { CatalogDto catalogs = CatalogContext.Current.GetCatalogDto(); CatalogEntryDto.CatalogEntryRow entry = null; bool found = false; string catalogName = String.Empty; int seed = 0; while (!found) { seed = random.Next(catalogs.Catalog.Count - 1); CatalogDto.CatalogRow catalog = catalogs.Catalog[seed]; catalogName = catalog.Name; // Get Catalog Nodes CatalogNodeDto nodes = CatalogContext.Current.GetCatalogNodesDto(catalogName); // Pick random node if (nodes.CatalogNode.Count > 0) { seed = random.Next(nodes.CatalogNode.Count - 1); CatalogNodeDto.CatalogNodeRow node = nodes.CatalogNode[seed]; CatalogEntryDto entryDto = CatalogContext.Current.GetCatalogEntriesDto(catalogName, node.CatalogNodeId); if (entryDto.CatalogEntry.Count > 0) { seed = random.Next(entryDto.CatalogEntry.Count - 1); entry = entryDto.CatalogEntry[seed]; if (entry.IsActive) { found = true; } } } } LineItem lineItem = new LineItem(); lineItem.DisplayName = entry.Name; lineItem.CatalogEntryId = entry.Code; lineItem.ShippingMethodId = shippingMethod; lineItem.ShippingMethodName = shippingMethodName; lineItem.ShippingAddressId = "Home"; // Choose a random quantity for chosen product. int quantity = random.Next(1, 7); lineItem.Quantity = quantity; lineItem.CatalogNode = catalogName; lineItem.Discounts.Add(OrderHelper.CreateLineItemDiscount()); return(lineItem); }
/// <summary> /// Handles the RowChanged event of the CatalogEntry control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Data.DataRowChangeEventArgs"/> instance containing the event data.</param> void CatalogEntry_RowChanged(object sender, DataRowChangeEventArgs e) { CatalogEntryDto.CatalogEntryDataTable table = (CatalogEntryDto.CatalogEntryDataTable)sender; CatalogEntryDto.CatalogEntryRow row = (CatalogEntryDto.CatalogEntryRow)table.Rows[0]; if (row.CatalogEntryId > 0) { MetaDataTab.MetaClassId = row.MetaClassId; MetaDataTab.ObjectId = row.CatalogEntryId; } }
/// <summary> /// Creates the line item. /// </summary> /// <returns></returns> public static LineItem CreateLineItem() { CatalogDto catalogs = CatalogContext.Current.GetCatalogDto(); CatalogEntryDto.CatalogEntryRow entry = null; bool found = false; string catalogName = String.Empty; Random random = new Random(); int seed = 0; while (!found) { seed = random.Next(catalogs.Catalog.Count - 1); CatalogDto.CatalogRow catalog = catalogs.Catalog[seed]; catalogName = catalog.Name; // Get Catalog Nodes CatalogNodeDto nodes = CatalogContext.Current.GetCatalogNodesDto(catalogName); // Pick random node if (nodes.CatalogNode.Count > 0) { seed = random.Next(nodes.CatalogNode.Count - 1); CatalogNodeDto.CatalogNodeRow node = nodes.CatalogNode[seed]; CatalogEntryDto entryDto = CatalogContext.Current.GetCatalogEntriesDto(catalogName, node.CatalogNodeId); if (entryDto.CatalogEntry.Count > 0) { seed = random.Next(entryDto.CatalogEntry.Count - 1); entry = entryDto.CatalogEntry[seed]; if (entry.IsActive) { found = true; } } } } LineItem lineItem = new LineItem(); lineItem.DisplayName = entry.Name; lineItem.CatalogEntryId = entry.Code; lineItem.ShippingMethodId = new Guid("17995798-a2cc-43ad-81e8-bb932f6827e4"); lineItem.ShippingMethodName = "Online Download"; lineItem.ShippingAddressId = "Home"; lineItem.ListPrice = 100; lineItem.Quantity = 2; lineItem.CatalogNode = catalogName; lineItem.Discounts.Add(CreateLineItemDiscount()); return(lineItem); }
private void BuildCatalogStructure(FindDocument document, CatalogEntryDto.CatalogEntryRow entryRow) { Dictionary <int, FindDocumentBuilder.CatalogInfo> catalogs = new Dictionary <int, FindDocumentBuilder.CatalogInfo>(); Dictionary <int, FindDocumentBuilder.CatalogNodeInfo> catalogNodes = new Dictionary <int, FindDocumentBuilder.CatalogNodeInfo>(); List <FindDocumentBuilder.NodeEntryRelationInfo> list = FindDocumentBuilder.CatalogSystem.GetCatalogRelationDto(entryRow.CatalogEntryId).NodeEntryRelation.Select <CatalogRelationDto.NodeEntryRelationRow, FindDocumentBuilder.NodeEntryRelationInfo>((Func <CatalogRelationDto.NodeEntryRelationRow, FindDocumentBuilder.NodeEntryRelationInfo>)(r => new FindDocumentBuilder.NodeEntryRelationInfo(r, catalogs, catalogNodes))).ToList <FindDocumentBuilder.NodeEntryRelationInfo>(); FindDocumentBuilder.CatalogInfo.GetCatalog(entryRow.CatalogId, catalogs); document.Catalogs = catalogs.Select <KeyValuePair <int, FindDocumentBuilder.CatalogInfo>, string>((Func <KeyValuePair <int, FindDocumentBuilder.CatalogInfo>, string>)(kv => kv.Value.CatalogName)).Distinct <string>().OrderBy <string, string>((Func <string, string>)(s => s)).ToList <string>(); document.CatalogNodes = catalogNodes.Select <KeyValuePair <int, FindDocumentBuilder.CatalogNodeInfo>, string>((Func <KeyValuePair <int, FindDocumentBuilder.CatalogNodeInfo>, string>)(kv => kv.Value.CatalogNodeCode)).Distinct <string>().OrderBy <string, string>((Func <string, string>)(s => s)).ToList <string>(); document.Outlines = list.SelectMany <FindDocumentBuilder.NodeEntryRelationInfo, string>((Func <FindDocumentBuilder.NodeEntryRelationInfo, IEnumerable <string> >)(r => this.BuildOutlines(r))).Distinct <string>().OrderBy <string, string>((Func <string, string>)(s => s)).ToList <string>(); }
private void UpdateProduct(CatalogEntryDto.CatalogEntryRow entry, string[] languages, CatalogDto.CatalogRow catalog, ESalesVariantHelper variantHelper) { if (_incremental) { // Variants might have changed from products -> variants, so delete as products just in case. var variantEntries = variantHelper.GetVariants(entry.CatalogEntryId).Select(v => _catalogSystem.GetCatalogEntry(v)); RemoveProducts(new[] { entry }.Concat(variantEntries), languages); } Add(entry, languages, catalog, variantHelper); }
/// <summary> /// Called when a catalog entry is indexed. /// We use this method to load the prices for the variants of a product and store /// the highest variant price on the product for optimal retrieval in the product listing. /// </summary> protected override void OnCatalogEntryIndex(ref SearchDocument document, CatalogEntryDto.CatalogEntryRow entry, string language) { switch (entry.ClassTypeId) { case EntryType.Package: case EntryType.Bundle: case EntryType.Product: UpdateSearchDocument(ref document, entry.Code, language); break; } }
/// <summary> /// Check catalog entry's tracking inventory was enable or not. /// </summary> /// <param name="catalogEntry">Catalog entry.</param> private bool InventoryTrackingEnabled(CatalogEntryDto.CatalogEntryRow catalogEntry) { if (catalogEntry == null) { return(false); } var entryVariations = catalogEntry.GetVariationRows(); var variation = entryVariations.FirstOrDefault(); return(variation != null && variation.TrackInventory); }
private IEntity GetEntity(CatalogEntryDto.CatalogEntryRow entry, ESalesVariantHelper variantHelper, string language, IEnumerable <Attribute> attributes) { var keyValue = _keyLookup.Value(entry, language); if (variantHelper.IsVariant(entry.CatalogEntryId)) { var productKey = _keyLookup.Value(_catalogSystem.GetCatalogEntry(variantHelper.GetParentProduct(entry.CatalogEntryId)), language); return(new Variant(keyValue, productKey, attributes)); } return(new Product(keyValue, attributes)); }
private void Add(CatalogEntryDto.CatalogEntryRow entry, IEnumerable <string> languages, CatalogDto.CatalogRow catalog, ESalesVariantHelper variantHelper) { foreach (var convertedEntry in _entryConverter.Convert(entry, languages, catalog, variantHelper)) { var entity = convertedEntry; if (_converterPlugin != null) { entity = _converterPlugin.Convert(convertedEntry); } _writer.Add(entity); } }
/// <summary> /// Updates meta field /// </summary> /// <param name="item">The data item.</param> /// <returns></returns> private void UpdateMetaField(CatalogEntryDto.CatalogEntryRow item) { int MetaClassId = item.MetaClassId; int ObjectId = item.CatalogEntryId; MetaDataContext MDContext = CatalogContext.MetaDataContext; if (ObjectId != 0) { // set username here, because calling FrameworkContext.Current.Profile causes MeteDataContext.Current to change (it's bug in ProfileContext class). string userName = FrameworkContext.Current.Profile.UserName; MDContext.UseCurrentUICulture = false; MDContext.Language = LanguageCode; MetaObject metaObj = null; bool saveChanges = true; metaObj = MetaObject.Load(MDContext, ObjectId, MetaClassId); if (metaObj == null) { metaObj = MetaObject.NewObject(MDContext, ObjectId, MetaClassId, userName); //DataBind(); return; } else { metaObj.ModifierId = userName; metaObj.Modified = DateTime.UtcNow; } foreach (Control ctrl in MetaControls.Controls) { // Only update controls that belong to current language if (String.Compare(((IMetaControl)ctrl).LanguageCode, LanguageCode, true) == 0) { ((IMetaControl)ctrl).MetaObject = metaObj; //((IMetaControl)ctrl).MetaField = metaObj; ((IMetaControl)ctrl).Update(); } } // Only save changes when new object has been created if (saveChanges) { metaObj.AcceptChanges(MDContext); } MDContext.UseCurrentUICulture = true; } }
private void IndexEntry(CatalogEntryDto.CatalogEntryRow entry, string[] languages, CatalogDto.CatalogRow catalog, ESalesVariantHelper variantHelper) { if (variantHelper.IsVariant(entry.CatalogEntryId)) { Add(entry, languages, catalog, variantHelper); } else { UpdateProduct(entry, languages, catalog, variantHelper); } ReportAddProgress(); }
protected Money?GetItemPrice(CatalogEntryDto.CatalogEntryRow entry, LineItem lineItem, CustomerContact customerContact) { Currency currency = new Currency(lineItem.Parent.Parent.BillingCurrency); List <CustomerPricing> customerPricing = new List <CustomerPricing>(); customerPricing.Add(CustomerPricing.AllCustomers); if (customerContact != null) { var userKey = _mapUserKey.ToUserKey(customerContact.UserId); if (userKey != null && !string.IsNullOrWhiteSpace(userKey.ToString())) { customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.UserName, userKey.ToString())); } if (!string.IsNullOrEmpty(customerContact.EffectiveCustomerGroup)) { customerPricing.Add(new CustomerPricing(CustomerPricing.PriceType.PriceGroup, customerContact.EffectiveCustomerGroup)); } } IPriceService priceService = ServiceLocator.Current.GetInstance <IPriceService>(); PriceFilter priceFilter = new PriceFilter() { Currencies = new List <Currency>() { currency }, Quantity = lineItem.Quantity, CustomerPricing = customerPricing, ReturnCustomerPricing = false // just want one value }; // Get the lowest price among all the prices matching the parameters IPriceValue priceValue = priceService .GetPrices(lineItem.Parent.Parent.MarketId, FrameworkContext.Current.CurrentDateTime, new CatalogKey(entry), priceFilter) .OrderBy(pv => pv.UnitPrice) .FirstOrDefault(); if (priceValue != null) { return(priceValue.UnitPrice); } if (lineItem.PlacedPrice != 0) { return(new Money(lineItem.PlacedPrice, currency)); } return(null); }
public void Update() { CatalogEntryDto.CatalogEntryRow item = (CatalogEntryDto.CatalogEntryRow)DataItem; if (item != null) { if (IsMetaField) { UpdateMetaField(item); } else { UpdateStaticField(item); } } }
public string GetEntryUrl(CatalogEntryDto.CatalogEntryRow entry, string language) { string url; var seo = _entryAdditionalData.GetCatalogItemSeoRows(entry).FirstOrDefault(s => s.LanguageCode == language); if (seo != null && !string.IsNullOrWhiteSpace(seo.Uri) && !seo.Uri.StartsWith("~/")) { url = "~/" + seo.Uri; } else { url = UrlService.GetUrl("EntryView", (object)"ec", (object)entry.Code); } return(url); }
private static bool CheckNeedEntryTracking(CatalogEntryDto.CatalogEntryRow catalogEntry) { if (catalogEntry == null) { throw new ArgumentNullException("catalogEntry"); } var retVal = false; var entryVariations = GetEntryVariations(catalogEntry); var variation = entryVariations.FirstOrDefault(); if (variation != null) { retVal = variation.TrackInventory; } return(retVal); }
public FindDocumentBuilder(CatalogEntryDto.CatalogEntryRow entryRow, ISearchConfiguration configuration, IEnumerable <string> languages) { this.Document = new FindDocument(); this.Document.CatalogEntryId = entryRow.CatalogEntryId; this.Document.CatalogEntryCode = entryRow.Code.ToLowerInvariant(); this.Document.CatalogEntryType = entryRow.ClassTypeId.ToLowerInvariant(); this.Document.MetaClassName = MetaClass.Load(CatalogContext.MetaDataContext, entryRow.MetaClassId).FriendlyName; this.Document.Name = entryRow.Name.ToLowerInvariant(); this.Document.StartDate = entryRow.StartDate; this.Document.EndDate = entryRow.EndDate; this.Document.Languages = languages.Where <string>((Func <string, bool>)(l => entryRow.IsEntryPublished(l))).ToList <string>(); this.Document.IsActive = entryRow.IsActive; this.BuildPreorderFields(this.Document, entryRow.Code); this.BuildCatalogStructure(this.Document, entryRow); this.BuildPrices(this.Document, entryRow, configuration); this.BuildMetaFields(this.Document, entryRow, configuration); }
private static CatalogEntryDto.CatalogEntryRow GetEntryRowForLineItem(LineItem lineItem) { CatalogEntryDto.CatalogEntryRow retVal = null; // Remove cache before proceeding var responseGroup = new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull); string cacheKey = CatalogCache.CreateCacheKey("catalogentry", responseGroup.CacheKey, lineItem.CatalogEntryId.ToString()); CatalogCache.Remove(cacheKey); // Now get the entry CatalogEntryDto entryDto = CatalogContext.Current.GetCatalogEntryDto(lineItem.CatalogEntryId, responseGroup); if (entryDto != null) { retVal = entryDto.CatalogEntry.FirstOrDefault(); } return(retVal); }
/// <summary> /// Saves the changes. /// </summary> /// <param name="context">The context.</param> public void SaveChanges(IDictionary context) { CatalogEntryDto dto = (CatalogEntryDto)context[_CatalogEntryDtoString]; CatalogEntryDto.CatalogEntryRow row = null; if (dto.CatalogEntry == null || dto.CatalogEntry.Count == 0) { row = dto.CatalogEntry.NewCatalogEntryRow(); row.ApplicationId = CatalogConfiguration.Instance.ApplicationId; row.ClassTypeId = EntryType; } else { row = dto.CatalogEntry[0]; if (row.MetaClassId != Int32.Parse(MetaClassList.SelectedValue)) { MetaObject.Delete(CatalogContext.MetaDataContext, row.CatalogEntryId, row.MetaClassId); } } row.Name = Name.Text; row.StartDate = AvailableFrom.Value.ToUniversalTime(); row.EndDate = ExpiresOn.Value.ToUniversalTime(); row.Code = CodeText.Text; row.IsActive = IsActive.IsSelected; if (ParentCatalogId > 0 && row.RowState == DataRowState.Detached) { row.CatalogId = ParentCatalogId; } row.TemplateName = DisplayTemplate.SelectedValue; row.MetaClassId = Int32.Parse(MetaClassList.SelectedValue); if (row.RowState == DataRowState.Detached) { dto.CatalogEntry.Rows.Add(row); } dto.CatalogEntry.RowChanged += new DataRowChangeEventHandler(CatalogEntry_RowChanged); }
/// <summary> /// Gets the price. /// </summary> /// <param name="entryRow">The entry row.</param> /// <param name="languageCode">The language code.</param> /// <returns></returns> private decimal GetPrice(CatalogEntryDto.CatalogEntryRow entryRow, string defaultCurrency, string languageCode) { string currencyCode = new RegionInfo(languageCode).ISOCurrencySymbol; decimal price = -1; CatalogEntryDto.VariationRow[] varRows = entryRow.GetVariationRows(); if (varRows.Length > 0 && defaultCurrency.Equals(currencyCode, StringComparison.OrdinalIgnoreCase)) { price = varRows[0].ListPrice; } CatalogEntryDto.SalePriceRow[] saleRows = entryRow.GetSalePriceRows(); if (saleRows != null) { // We only get sale price which is assigned to all customers, and has no quantity restrictions foreach (CatalogEntryDto.SalePriceRow priceRow in saleRows) { if (!priceRow.Currency.Equals(currencyCode, StringComparison.OrdinalIgnoreCase)) { continue; } // Check inventory first if (priceRow.MinQuantity > 0) { continue; // didn't meet min quantity requirements } // Check dates if (priceRow.StartDate > FrameworkContext.Current.CurrentDateTime || priceRow.EndDate < FrameworkContext.Current.CurrentDateTime) { continue; // falls outside of acceptable range } if ((SaleType.TypeKey)priceRow.SaleType == SaleType.TypeKey.AllCustomers) // no need to check, applies to everyone { price = priceRow.UnitPrice; break; } } } return(price); }
private List <ProductInfo> BuildProductVariationRelations(Dictionary <int, CatalogEntryDto.CatalogEntryRow> catalogEntryRows, ICatalogSystem catalog) { List <ProductInfo> productsAndVariations = new List <ProductInfo>(); CatalogEntryResponseGroup variatonRespGroup = new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo); // Build product -> variation hierarchy foreach (KeyValuePair <int, CatalogEntryDto.CatalogEntryRow> keyValue in catalogEntryRows) { CatalogEntryDto.CatalogEntryRow entryRow = keyValue.Value; if (string.Compare(entryRow.ClassTypeId, "Product", StringComparison.InvariantCultureIgnoreCase) == 0) { ProductInfo productInfo = new ProductInfo { EntryRow = entryRow, CatalogEntryId = keyValue.Key, Code = entryRow.Code, Name = entryRow.Name }; // Now load all related variations manually CatalogEntryDto variationEntries = catalog.GetCatalogEntriesDto(keyValue.Key, string.Empty, string.Empty, variatonRespGroup); foreach (CatalogEntryDto.CatalogEntryRow variationRow in variationEntries.CatalogEntry) { if (catalogEntryRows.ContainsKey(variationRow.CatalogEntryId)) { productInfo.Variations.Add(catalogEntryRows[variationRow.CatalogEntryId]); } } // Only add if we have a product with one or more variations if (productInfo.Variations.Count > 0) { productsAndVariations.Add(productInfo); } } } return(productsAndVariations); }