private static void AddCatalogLanguage(CatalogDto workingDto, CatalogDto.CatalogRow catalogRow, string languageCode)
 {
     CatalogDto.CatalogLanguageRow languageRow = workingDto.CatalogLanguage.NewCatalogLanguageRow();
     languageRow.LanguageCode = languageCode;
     languageRow.CatalogId    = catalogRow.CatalogId;
     workingDto.CatalogLanguage.AddCatalogLanguageRow(languageRow);
 }
Exemplo n.º 2
0
        private void ValidateItems()
        {
            CatalogRelationDto relationDto = null;

            CatalogDto.CatalogRow catalogRow = null;

            var marketTester   = new ExcludedCatalogEntryMarketsField();
            var orderMarket    = ServiceLocator.Current.GetInstance <IMarketService>().GetMarket(OrderGroup.MarketId);
            var orderForms     = OrderGroup.OrderForms.ToArray();
            var lineItems      = orderForms.SelectMany(x => x.LineItems.ToArray());
            var validLineItems = lineItems.Where(x => x.CatalogEntryId != "0" && !String.IsNullOrEmpty(x.CatalogEntryId) && !x.CatalogEntryId.StartsWith("@"));

            foreach (var lineItem in validLineItems)
            {
                var entryRow = GetEntryRowForLineItem(lineItem);

                if (entryRow == null)
                {
                    AddWarningSafe(Warnings, "LineItemCodeRemoved-" + lineItem.Id,
                                   String.Format("The catalog entry code that maps to the line item {0} has been removed or changed.  The line item is no longer valid", lineItem.CatalogEntryId));
                    DeleteInvalidItem(orderForms, lineItem);
                    continue;
                }

                if (!marketTester.IsValidForMarket(entryRow, orderMarket))
                {
                    AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(),
                                   String.Format("Item \"{0}\" has been removed from the cart because it is not available in your market.",
                                                 lineItem.DisplayName));
                    DeleteInvalidItem(orderForms, lineItem);
                }
                else if (entryRow.IsActive &&
                         entryRow.StartDate < FrameworkContext.Current.CurrentDateTime &&
                         entryRow.EndDate > FrameworkContext.Current.CurrentDateTime)
                {
                    if (catalogRow == null || catalogRow.CatalogId != entryRow.CatalogId)
                    {
                        var catalogDto = CatalogContext.Current.GetCatalogDto(entryRow.CatalogId);
                        catalogRow = catalogDto.Catalog.FirstOrDefault();
                    }

                    // check if catalog is visible
                    if (catalogRow != null && catalogRow.IsActive &&
                        catalogRow.StartDate < FrameworkContext.Current.CurrentDateTime &&
                        catalogRow.EndDate > FrameworkContext.Current.CurrentDateTime)
                    {
                        relationDto = CatalogContext.Current.GetCatalogRelationDto(entryRow.CatalogEntryId);
                        // populate item
                        lineItem.Catalog = catalogRow.Name;
                        lineItem.ParentCatalogEntryId = GetParentCatalogEntryId(entryRow.CatalogEntryId, relationDto);
                        //Inventory Info
                        IWarehouseInventory aggregateInventory = ServiceLocator.Current.GetInstance <IWarehouseInventoryService>()
                                                                 .GetTotal(new CatalogKey(entryRow));
                        PopulateInventoryInfo(aggregateInventory, lineItem);
                        //Variation Info
                        PopulateVariationInfo(entryRow, lineItem);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Finds the catalog id.
        /// </summary>
        /// <param name="catalogName">Name of the catalog.</param>
        /// <returns></returns>
        int findCatalogId(string catalogName)
        {
            CatalogDto dto = CatalogContext.Current.GetCatalogDto();

            CatalogDto.CatalogRow row = null;

            int index = -1;

            try
            {
                foreach (CatalogDto.CatalogRow node in dto.Catalog)
                {
                    if (node.Name.Equals(catalogName))
                    {
                        index = row.CatalogId;
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.Write(e.Message);
            }

            return(index);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates the site catalog object from the DTO CatalogRow.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns>SiteCatalog instance</returns>
        public static SiteCatalog CreateSiteCatalog(CatalogDto.CatalogRow input)
        {
            SiteCatalog node = new SiteCatalog();

            if (input != null)
            {
                node.Name = input.Name;
                // Catalog Name is it's id
                node.CatalogId = input.Name;
            }
            return(node);
        }
Exemplo n.º 7
0
 public static FindDocumentBuilder.CatalogInfo GetCatalog(int catalogId, Dictionary <int, FindDocumentBuilder.CatalogInfo> loadedCatalogs)
 {
     FindDocumentBuilder.CatalogInfo catalogInfo;
     if (!loadedCatalogs.TryGetValue(catalogId, out catalogInfo))
     {
         CatalogDto.CatalogRow catalogRow = FindDocumentBuilder.CatalogSystem.GetCatalogDto(catalogId).Catalog.Single <CatalogDto.CatalogRow>();
         catalogInfo = new FindDocumentBuilder.CatalogInfo()
         {
             CatalogId   = catalogId,
             CatalogName = FindDocumentBuilder.FormatStructureElement(catalogRow.Name)
         };
         loadedCatalogs.Add(catalogId, catalogInfo);
     }
     return(catalogInfo);
 }
        private void WriteDocuments(CatalogDto.CatalogRow catalog, string[] languages)
        {
            var variantHelper        = new ESalesVariantHelper(GetRelations(catalog.CatalogId));
            var catalogEntryProvider = CatalogEntryProviderFactory.Create(_incremental, catalog.CatalogId, variantHelper, _catalogSystem, _indexSystem);

            _progress.TotalNbrOfEntries = catalogEntryProvider.Count;
            var firstCatalogEntryId = int.MaxValue;
            var lastCatalogEntryId  = int.MinValue;

            _indexSystem.Log("Begin indexing catalog \"{0}\" in eSales...", _progress.GetCurrentProgressPercent(), catalog.Name);

            foreach (var entry in catalogEntryProvider.GetCatalogEntries())
            {
                SetFirstAndLastEntry(entry.CatalogEntryId, ref firstCatalogEntryId, ref lastCatalogEntryId);
                IndexEntry(entry, languages, catalog, variantHelper);
            }

            _progress.IncreaseCatalogCount();
            _indexSystem.Log("Done indexing catalog \"{0}\".", _progress.GetCurrentProgressPercent(), catalog.Name);
            _indexSystem.SetBuildProperties(firstCatalogEntryId, lastCatalogEntryId, catalog.Name);
        }
        private void ValidateItems()
        {
            CatalogRelationDto relationDto = null;

            CatalogDto.CatalogRow catalogRow = null;

            var marketTester   = new ExcludedCatalogEntryMarketsField();
            var orderMarket    = ServiceLocator.Current.GetInstance <IMarketService>().GetMarket(OrderGroup.MarketId);
            var lineItems      = OrderGroup.OrderForms.SelectMany(x => x.LineItems.ToArray());
            var validLineItems = lineItems.Where(x => x.Code != "0" && !String.IsNullOrEmpty(x.Code) && !x.Code.StartsWith("@") && !x.IsGift);

            List <LineItem> lineItemsToRemove = new List <LineItem>();

            foreach (var lineItem in validLineItems)
            {
                var entryRow = GetEntryRowForLineItem(lineItem);

                if (entryRow == null)
                {
                    AddWarningSafe(Warnings, "LineItemCodeRemoved-" + lineItem.Id,
                                   String.Format("The catalog entry code that maps to the line item {0} has been removed or changed.  The line item is no longer valid", lineItem.Code));
                    continue;
                }

                if (!marketTester.IsValidForMarket(entryRow, orderMarket))
                {
                    AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(),
                                   String.Format("Item \"{0}\" has been removed from the cart because it is not available in your market.",
                                                 lineItem.DisplayName));
                    lineItemsToRemove.Add(lineItem);
                    continue;
                }

                var requestDate = FrameworkContext.Current.CurrentDateTime;

                if (catalogRow == null || catalogRow.CatalogId != entryRow.CatalogId)
                {
                    var catalogDto = CatalogContext.Current.GetCatalogDto(entryRow.CatalogId);
                    catalogRow = catalogDto.Catalog.FirstOrDefault();
                }

                //check if the catalog of this entry is not available
                if (catalogRow == null || !catalogRow.IsActive || requestDate < catalogRow.StartDate || requestDate > catalogRow.EndDate)
                {
                    AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(),
                                   String.Format("Item \"{0}\" has been removed from the cart because the catalog of this entry is not available.",
                                                 lineItem.DisplayName));
                    lineItemsToRemove.Add(lineItem);
                    continue;
                }

                relationDto = CatalogContext.Current.GetCatalogRelationDto(entryRow.CatalogEntryId);
                // populate item
                lineItem.Catalog = catalogRow.Name;
                lineItem.ParentCatalogEntryId = GetParentCatalogEntryId(entryRow.CatalogEntryId, relationDto);

                //Variation Info
                PopulateVariationInfo(entryRow, lineItem, lineItemsToRemove);

                if (string.IsNullOrEmpty(lineItem.WarehouseCode))
                {
                    // This case was passed because lineItem.WarehouseCode will be set in next activity - GetFulfillmentWarehouseActivity
                    continue;
                }

                var inventoryRecord = InventoryService.Get(lineItem.Code, lineItem.WarehouseCode);

                if (inventoryRecord == null)
                {
                    AddWarningSafe(Warnings, "LineItemCodeRemoved-" + lineItem.Id,
                                   String.Format("The catalog entry code that maps to the line item {0} has been removed or changed.  The line item is no longer valid", lineItem.Code));
                    lineItemsToRemove.Add(lineItem);
                    continue;
                }

                // Get minimum date that the entry is available. It should be is minimum date of preorder date and start date
                var minAvailableDate = entryRow.StartDate;
                if (inventoryRecord != null && inventoryRecord.PreorderAvailableUtc > SafeBeginningOfTime && minAvailableDate > inventoryRecord.PreorderAvailableUtc)
                {
                    minAvailableDate = inventoryRecord.PreorderAvailableUtc;
                }

                //check if the entry is not available
                if (!entryRow.IsActive || requestDate < minAvailableDate || requestDate > entryRow.EndDate)
                {
                    AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(),
                                   String.Format("Item \"{0}\" has been removed from the cart because it is not available.",
                                                 lineItem.DisplayName));
                    lineItemsToRemove.Add(lineItem);
                    continue;
                }

                //Inventory Info
                PopulateInventoryInfo(inventoryRecord, lineItem);
            }

            if (lineItemsToRemove.Count > 0)
            {
                // remove lineitem from shipment
                foreach (OrderForm form in OrderGroup.OrderForms)
                {
                    foreach (var lineItem in lineItemsToRemove)
                    {
                        form.RemoveLineItemFromShipments(lineItem);
                    }
                }

                // remove lineitem from order
                foreach (var lineItem in lineItemsToRemove)
                {
                    lineItem.Delete();
                }
            }
        }
Exemplo n.º 10
0
        private void WalkCatalogNodes(ICatalogSystem catalogSystem, CatalogNodeDto nodes, CatalogDto.CatalogRow catalog, Dictionary <int, CatalogEntryDto.CatalogEntryRow> catalogEntryRows)
        {
            foreach (CatalogNodeDto.CatalogNodeRow node in nodes.CatalogNode)
            {
                CatalogSearchParameters pars    = new CatalogSearchParameters();
                CatalogSearchOptions    options = new CatalogSearchOptions {
                    CacheResults = false
                };
                pars.CatalogNames.Add(catalog.Name);
                pars.CatalogNodes.Add(node.Code);
                //CatalogEntryDto entries = CatalogContext.Current.FindItemsDto(
                //    pars,
                //    options,
                //    ref count,
                //    new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                CatalogEntryDto entries = catalogSystem.GetCatalogEntriesDto(catalog.CatalogId, node.CatalogNodeId,
                                                                             new CatalogEntryResponseGroup(
                                                                                 CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));

                _log.DebugFormat("Entries in Node: {0} (Count: {1})", node.Name, entries.CatalogEntry.Rows.Count);
                foreach (CatalogEntryDto.CatalogEntryRow entry in entries.CatalogEntry)
                {
                    // _log.DebugFormat("{3}: {0} ({1} - {2})", entry.Name, entry.Code, entry.CatalogEntryId, entry.ClassTypeId);
                    if (catalogEntryRows.ContainsKey(entry.CatalogEntryId) == false)
                    {
                        catalogEntryRows.Add(entry.CatalogEntryId, entry);
                    }
                }

                // Get Subnodes
                CatalogNodeDto subNodes = catalogSystem.GetCatalogNodesDto(catalog.CatalogId, node.CatalogNodeId);
                WalkCatalogNodes(catalogSystem, subNodes, catalog, catalogEntryRows);
            }
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Saves the changes.
        /// </summary>
        /// <param name="context">The context.</param>
        public void SaveChanges(IDictionary context)
        {
            CatalogDto dto = (CatalogDto)context["Catalog"];

            CatalogDto.CatalogRow row = null;

            if (dto.Catalog.Count > 0)
            {
                row          = dto.Catalog[0];
                row.Modified = DateTime.UtcNow;
            }
            else
            {
                row           = dto.Catalog.NewCatalogRow();
                row.Created   = DateTime.UtcNow;
                row.Modified  = DateTime.UtcNow;
                row.IsPrimary = true;
            }

            row.Name            = CatalogName.Text;
            row.DefaultCurrency = DefaultCurrency.SelectedValue;
            row.DefaultLanguage = DefaultLanguage.SelectedValue;
            row.WeightBase      = BaseWeight.SelectedValue;
            row.StartDate       = this.AvailableFrom.Value.ToUniversalTime();
            row.EndDate         = this.ExpiresOn.Value.ToUniversalTime();
            row.IsActive        = this.IsCatalogActive.IsSelected;
            row.SortOrder       = Int32.Parse(this.SortOrder.Text);
            row.ApplicationId   = CatalogConfiguration.Instance.ApplicationId;

            if (row.RowState == DataRowState.Detached)
            {
                dto.Catalog.Rows.Add(row);
            }

            // Populate other languages
            foreach (ListItem item in OtherLanguagesList.Items)
            {
                if (item.Selected && !DefaultLanguage.SelectedValue.Equals(item.Value))
                {
                    if (dto.CatalogLanguage.Select(String.Format("CatalogId = {0} and LanguageCode = '{1}'", CatalogId, item.Value)).Length == 0)
                    {
                        CatalogDto.CatalogLanguageRow langRow = dto.CatalogLanguage.NewCatalogLanguageRow();
                        langRow.LanguageCode = item.Value;
                        langRow.CatalogId    = row.CatalogId;
                        dto.CatalogLanguage.Rows.Add(langRow);
                    }
                }
                else
                {
                    DataRow[] rows = dto.CatalogLanguage.Select(String.Format("CatalogId = {0} and LanguageCode = '{1}'", CatalogId, item.Value));
                    if (rows.Length > 0)
                    {
                        foreach (CatalogDto.CatalogLanguageRow lrow in rows)
                        {
                            lrow.Delete();
                        }
                    }
                }
            }

            // Populate sites
            foreach (ListItem item in SiteList.Items)
            {
                if (item.Selected) // add row
                {
                    DataRow[] rows = dto.SiteCatalog.Select(String.Format("CatalogId = {0} and SiteId = '{1}'", CatalogId, item.Value));
                    if (rows.Length == 0)
                    {
                        CatalogDto.SiteCatalogRow siteRow = dto.SiteCatalog.NewSiteCatalogRow();
                        siteRow.SiteId    = new Guid(item.Value);
                        siteRow.CatalogId = row.CatalogId;
                        dto.SiteCatalog.Rows.Add(siteRow);
                    }
                }
                else // delete row
                {
                    DataRow[] rows = dto.SiteCatalog.Select(String.Format("CatalogId = {0} and SiteId = '{1}'", CatalogId, item.Value));
                    if (rows.Length > 0)
                    {
                        foreach (CatalogDto.SiteCatalogRow srow in rows)
                        {
                            srow.Delete();
                        }
                    }
                }
            }

            // Re add sites
        }
 private static IEnumerable <string> GetCatalogLanguages(CatalogDto.CatalogRow catalog)
 {
     return(new[] { catalog.DefaultLanguage }.Concat(catalog.GetCatalogLanguageRows().Select(l => l.LanguageCode)).Distinct());
 }
 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);
     }
 }
 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);
 }
        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();
        }