private Guid GetMerchantId(string merchant)
        {
            CatalogEntryDto merchants = CatalogContext.Current.GetMerchantsDto();

            if (merchants.Merchant != null)
            {
                DataRow[] drws       = null;
                Guid      merchantId = new Guid();
                try
                {
                    merchantId = new Guid(merchant);
                }
                catch {}
                if (merchantId != Guid.Empty)
                {
                    drws = merchants.Merchant.Select(String.Format("MerchantId = '{0}'", merchantId));
                    if (drws.Length > 0)
                    {
                        return(merchantId);
                    }
                }
                else
                {
                    drws = merchants.Merchant.Select(String.Format("Name LIKE '{0}'", merchant.Replace("'", "''")));
                    if (drws.Length > 0)
                    {
                        return(((CatalogEntryDto.MerchantRow)drws[0]).MerchantId);
                    }
                }
            }
            return(Guid.Empty);
        }
Example #2
0
        /// <summary>
        /// Gets the total records.
        /// </summary>
        /// <returns></returns>
        private int GetTotalRecords()
        {
            int            numRecords = 0;
            ICatalogSystem system     = CatalogContext.Current;

            // Get catalog lists
            CatalogDto catalogs = system.GetCatalogDto();

            foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog)
            {
                string catalogName = catalog.Name;

                // Get Catalog Nodes
                CatalogSearchParameters pars    = new CatalogSearchParameters();
                CatalogSearchOptions    options = new CatalogSearchOptions();
                options.CacheResults = false;
                pars.CatalogNames.Add(catalogName);
                options.RecordsToRetrieve = 1;
                options.StartingRecord    = 0;

                int             totalCount = 0;
                CatalogEntryDto entryDto   = CatalogContext.Current.FindItemsDto(pars, options, ref totalCount);
                numRecords += totalCount;
            }

            return(numRecords);
        }
        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);
                }
            }
        }
Example #4
0
        public string[] GetEntryList(string prefixText, int count)
        {
            if (count == 0)
            {
                count = 10;
            }

            CatalogEntryDto dto = CatalogContext.Current.GetCatalogEntriesDto(String.Format("%{0}%", prefixText), String.Empty);

            List <string> items = new List <string>(count);

            int newCount = 0;

            foreach (CatalogEntryDto.CatalogEntryRow row in dto.CatalogEntry)
            {
                string name = row.Name;

                name = name.Replace('|', '-');
                //name = name.Replace(']', '-');

                items.Add(String.Format("{0}|{1}", name, row.CatalogEntryId));
                newCount++;

                if (newCount == count)
                {
                    break;
                }
            }

            return(items.ToArray());
        }
Example #5
0
    /// <summary>
    /// Binds the value.
    /// </summary>
    /// <param name="entryCode">The entry code.</param>
    private void BindValue(string entryCode)
    {
        if (String.IsNullOrEmpty(entryCode))
        {
            return;
        }

        ComboBoxItem item = EntriesFilter.Items.FindByValue(entryCode);

        if (item != null)
        {
            EntriesFilter.SelectedItem = item;
        }
        else
        {
            CatalogEntryDto entryDto = CatalogContext.Current.GetCatalogEntryDto(entryCode);
            if (entryDto.CatalogEntry.Count > 0)
            {
                ComboBoxItem newItem = new ComboBoxItem();
                newItem.Text  = entryDto.CatalogEntry[0].Name;
                newItem.Value = entryDto.CatalogEntry[0].Code;
                EntriesFilter.Items.Add(newItem);
                EntriesFilter.SelectedItem = newItem;
            }
        }
    }
Example #6
0
        private IEnumerable <CatalogEntryDto.CatalogEntryRow> GetCatalogEntrys(IEnumerable <string> catalogNames)
        {
            // Changed to return all entries here
            string entryType = String.Empty;             //Mediachase.Commerce.Catalog.Objects.EntryType.Product.ToString();

            CatalogSearchParameters pars    = new CatalogSearchParameters();
            CatalogSearchOptions    options = new CatalogSearchOptions();

            options.RecordsToRetrieve = int.MaxValue;
            options.Namespace         = "Mediachase.Commerce.Catalog";
            options.StartingRecord    = 0;
            options.ReturnTotalCount  = true;
            //pars.SqlWhereClause = String.Format("[CatalogEntry].Name like '%{0}%' OR [CatalogEntry].Code like '%{0}%'", sFilter);

            // Add catalogs
            pars.CatalogNames.AddRange(catalogNames.ToArray());
            //CatalogDto catalogDto = CatalogContext.Current.GetCatalogDto();
            //foreach (CatalogDto.CatalogRow catalogRow in catalogDto.Catalog)
            //{
            //    pars.CatalogNames.Add(catalogRow.Name);
            //}

            int             totalRecords = 0;
            CatalogEntryDto dto          = CatalogContext.Current.FindItemsDto(pars, options, ref totalRecords);

            foreach (CatalogEntryDto.CatalogEntryRow entryRow in dto.CatalogEntry)
            {
                //ComboBoxItem item = new ComboBoxItem(entryRow.Name + " [" + entryRow.Code.ToString() + "]");
                //item.Value = entryRow.Code.ToString();
                //item["icon"] = Page.ResolveClientUrl(String.Format("~/app_themes/Default/images/icons/{0}.gif", entryRow.ClassTypeId));
                //EntriesFilter.Items.Add(item);
                yield return(entryRow);
            }
        }
Example #7
0
        private void CheckOnStringDict(MyPackage currentContent)
        {
            var stuff = currentContent.GetPropertyValue("StringDictDemo"); // nope

            CatalogEntryDto dto = catSys.Service.GetCatalogEntryDto(currentContent.Code);

            var row = dto.CatalogEntry.FirstOrDefault();

            MetaObject metaObject = MetaObject.Load(MetaDataContext.Instance, row.CatalogEntryId, row.MetaClassId);
            var        x          = metaObject["StringDictDemo"];


            System.Collections.Hashtable hash          = ObjectHelper.GetMetaFieldValues(dto.CatalogEntry.FirstOrDefault());
            Dictionary <int, string>     keyValuePairs = new Dictionary <int, string>();

            if (hash.Contains("StringDictDemo"))
            {
                foreach (var item in hash.Keys)
                {
                }
            }

            foreach (var item in hash)
            {
            }
        }
Example #8
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);
            }
        }
Example #9
0
        /// <summary>
        /// Finds the items dto.
        /// </summary>
        /// <param name="search">The search.</param>
        /// <param name="recordsCount">The records count.</param>
        /// <param name="responseGroup">The response group.</param>
        /// <returns></returns>
        internal static CatalogEntryDto FindItemsDto(CatalogSearch search, ref int recordsCount, CatalogEntryResponseGroup responseGroup)
        {
            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = String.Empty;

            // Only cache results if specified
            if (search.SearchOptions.CacheResults)
            {
                cacheKey = CatalogCache.CreateCacheKey("catalog-entriesdto", responseGroup.CacheKey, search.CacheKey);

                // check cache first
                object cachedObject = CatalogCache.Get(cacheKey);

                if (cachedObject != null)
                {
                    return((CatalogEntryDto)cachedObject);
                }
            }

            CatalogEntryDto dto = FindItemsDto2(search, ref recordsCount, responseGroup);

            if (!String.IsNullOrEmpty(cacheKey)) // cache results
            {
                // Insert to the cache collection
                CatalogCache.Insert(cacheKey, dto, search.SearchOptions.CacheTimeout);
            }

            return(dto);
        }
Example #10
0
 /// <summary>
 /// Raises the entry updating event.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="args">The <see cref="Mediachase.Commerce.Catalog.Events.EntryEventArgs"/> instance containing the event data.</param>
 public void RaiseEntryUpdatingEvent(CatalogEntryDto sender, EntryEventArgs args)
 {
     if (EntryUpdating != null)
     {
         EntryUpdating(sender, args);
     }
 }
Example #11
0
        /// <summary>
        /// Moves the catalog node.
        /// </summary>
        /// <param name="catalogId">The catalog id.</param>
        /// <param name="catalogNodeId">The catalog node id.</param>
        /// <param name="targetCatalogId">The target catalog id.</param>
        /// <param name="targetCatalogNodeId">The target catalog node id.</param>
        private void MoveCatalogNode(int catalogId, int catalogNodeId, int targetCatalogId, int targetCatalogNodeId)
        {
            if (catalogId != targetCatalogId || catalogNodeId != targetCatalogNodeId)
            {
                if (catalogNodeId > 0)
                {
                    CatalogNodeDto catalogNodeDto = CatalogContext.Current.GetCatalogNodeDto(catalogNodeId);
                    if (catalogNodeDto.CatalogNode.Count > 0)
                    {
                        catalogNodeDto.CatalogNode[0].CatalogId    = targetCatalogId;
                        catalogNodeDto.CatalogNode[0].ParentNodeId = targetCatalogNodeId;
                        CatalogContext.Current.SaveCatalogNode(catalogNodeDto);

                        CatalogNodeDto childCatalogNodesDto = CatalogContext.Current.GetCatalogNodesDto(catalogId, catalogNodeDto.CatalogNode[0].CatalogNodeId);
                        if (childCatalogNodesDto.CatalogNode.Count > 0)
                        {
                            for (int i = 0; i < childCatalogNodesDto.CatalogNode.Count; i++)
                            {
                                MoveCatalogNode(catalogId, childCatalogNodesDto.CatalogNode[i].CatalogNodeId, targetCatalogId, catalogNodeDto.CatalogNode[0].CatalogNodeId);
                            }
                        }

                        CatalogEntryDto catalogEntriesDto = CatalogContext.Current.GetCatalogEntriesDto(catalogId, catalogNodeDto.CatalogNode[0].CatalogNodeId);
                        if (catalogEntriesDto.CatalogEntry.Count > 0)
                        {
                            for (int i = 0; i < catalogEntriesDto.CatalogEntry.Count; i++)
                            {
                                MoveNodeEntry(catalogId, catalogNodeDto.CatalogNode[0].CatalogNodeId, catalogEntriesDto.CatalogEntry[i].CatalogEntryId, targetCatalogId, catalogNodeDto.CatalogNode[0].CatalogNodeId);
                            }
                        }
                    }
                }
            }
        }
Example #12
0
        /// <summary>
        /// Gets the catalog entry by URI dto.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="languageCode">The language code.</param>
        /// <param name="responseGroup">The response group.</param>
        /// <returns></returns>
        internal static CatalogEntryDto GetCatalogEntryByUriDto(string uri, string languageCode, CatalogEntryResponseGroup responseGroup)
        {
            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = CatalogCache.CreateCacheKey("catalogentry-uri-", responseGroup.CacheKey, uri, languageCode);

            CatalogEntryDto dto = null;

            // check cache first
            object cachedObject = CatalogCache.Get(cacheKey);

            if (cachedObject != null)
            {
                dto = (CatalogEntryDto)cachedObject;
            }

            // Load the object
            if (dto == null)
            {
                CatalogEntryAdmin catalog = new CatalogEntryAdmin();
                catalog.LoadByUri(uri, languageCode);
                dto = catalog.CurrentDto;

                if (dto.CatalogEntry.Count > 0)
                {
                    LoadEntry(catalog, dto.CatalogEntry[0], responseGroup);
                }

                // Insert to the cache collection
                CatalogCache.Insert(cacheKey, dto, CatalogConfiguration.Instance.Cache.CatalogEntryTimeout);
            }

            //dto.AcceptChanges();

            return(dto);
        }
Example #13
0
        /// <summary>
        /// Gets the catalog entries by catalog dto.
        /// </summary>
        /// <returns></returns>
        internal static CatalogEntryDto GetMerchants()
        {
            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = CatalogCache.CreateCacheKey("catalogentry-merchants");

            CatalogEntryDto dto = null;

            // check cache first
            object cachedObject = CatalogCache.Get(cacheKey);

            if (cachedObject != null)
            {
                dto = (CatalogEntryDto)cachedObject;
            }

            // Load the object
            if (dto == null)
            {
                CatalogEntryAdmin catalog = new CatalogEntryAdmin();
                catalog.LoadMerchants();
                dto = catalog.CurrentDto;

                // Insert to the cache collection
                CatalogCache.Insert(cacheKey, dto, CatalogConfiguration.Instance.Cache.CatalogCollectionTimeout);
            }

            //dto.AcceptChanges();

            return(dto);
        }
Example #14
0
        /// <summary>
        /// Creates the empty dtos.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <param name="relation">The relation.</param>
        /// <param name="association">The association.</param>
        /// <param name="persistInSession">if set to <c>true</c> [persist in session].</param>
        private void CreateEmptyDtos(ref CatalogEntryDto entry, ref CatalogRelationDto relation, ref CatalogAssociationDto association, bool persistInSession)
        {
            if (relation == null)
            {
                relation = new CatalogRelationDto();
                if (persistInSession)
                {
                    Session[_CatalogRelationDtoString] = relation;
                }
            }

            if (association == null)
            {
                association = new CatalogAssociationDto();
                if (persistInSession)
                {
                    Session[_CatalogAssociationDtoString] = association;
                }
            }

            if (entry == null)
            {
                entry = new CatalogEntryDto();
                if (persistInSession)
                {
                    Session[_CatalogEntryDtoString] = entry;
                }
            }
        }
        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>
        /// Gets the entry name by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        private string GetEntryNameById(int id)
        {
            string name  = String.Empty;
            bool   found = false;           // shows whether name was found

            // try to look up name using items in AssociationItemsFilter dropdown; if item with specified id is not there, get it from the db
            if (AssociataionItemsFilter.ItemCount > 0)
            {
                ComboBoxItem item = AssociataionItemsFilter.Items.FindByValue(id.ToString());
                if (item != null)
                {
                    name  = item.Text;
                    found = true;
                }
            }
            if (!found)
            {
                CatalogEntryDto dto = CatalogContext.Current.GetCatalogEntryDto(id);
                if (dto.CatalogEntry.Rows.Count > 0)
                {
                    name = ((CatalogEntryDto.CatalogEntryRow)dto.CatalogEntry.Rows[0]).Name;
                }
            }
            return(name);
        }
Example #17
0
            /// <summary>
            /// Gets a list of data from the underlying data storage.
            /// </summary>
            /// <param name="arguments">A <see cref="T:System.Web.UI.DataSourceSelectArguments"/> that is used to request operations on the data beyond basic data retrieval.</param>
            /// <returns>
            /// An <see cref="T:System.Collections.IEnumerable"/> list of data from the underlying data storage.
            /// </returns>
            protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments)
            {
                Options.RecordsToRetrieve = arguments.MaximumRows;
                Options.StartingRecord    = arguments.StartRowIndex;

                if (!String.IsNullOrEmpty(arguments.SortExpression))
                {
                    Parameters.OrderByClause = arguments.SortExpression;
                }

                if (DataMode == CatalogSearchDataMode.Objects)
                {
                    Entries entries = CatalogContext.Current.FindItems(Parameters, Options, ResponseGroup);

                    arguments.TotalRowCount = entries.TotalResults;
                    return(entries.Entry);
                }
                else
                {
                    int             totalRecordsCount = 0;
                    CatalogEntryDto entries           = CatalogContext.Current.FindItemsDto(Parameters, Options, ref totalRecordsCount, ResponseGroup);

                    if (totalRecordsCount > 0)
                    {
                        arguments.TotalRowCount = totalRecordsCount;
                        return(entries.CatalogEntry.Rows);
                    }
                    else
                    {
                        arguments.TotalRowCount = 0;
                        return(null);
                    }
                }
            }
Example #18
0
        public IEnumerable <ContentReference> AllCategories()
        {
            List <ContentReference> localList = new List <ContentReference>();
            List <int> nodeIds = new List <int>();

            CatalogEntryDto dto = CatalogContext.Current.GetCatalogEntriesDto("Fashion");

            CatalogRelationDto relDto = CatalogContext.Current.GetCatalogRelationDto(1, 0, 0, null,
                                                                                     new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));


            foreach (CatalogRelationDto.NodeEntryRelationRow item in relDto.NodeEntryRelation)
            {
                if (!nodeIds.Contains(item.CatalogNodeId))
                {
                    nodeIds.Add(item.CatalogNodeId);
                }
            }

            ReferenceConverter refConv = ServiceLocator.Current.GetInstance <ReferenceConverter>();

            foreach (int item in nodeIds)
            {
                localList.Add(refConv.GetContentLink(item, CatalogContentType.CatalogNode, 0));
            }

            return(localList);
        }
Example #19
0
        /// <summary>
        /// Binds the lists.
        /// </summary>
        private void BindLists()
        {
            // bind shipment packages
            if (PackageList.Items.Count <= 1)
            {
                ShippingMethodDto shippingDto = ShippingManager.GetShippingPackages();
                if (shippingDto.Package != null)
                {
                    foreach (ShippingMethodDto.PackageRow row in shippingDto.Package.Rows)
                    {
                        PackageList.Items.Add(new ListItem(row.Name, row.PackageId.ToString()));
                    }
                }
                PackageList.DataBind();
            }

            // bind warehouses
            if (WarehouseList.Items.Count <= 1)
            {
                WarehouseDto dto = WarehouseManager.GetWarehouseDto();
                if (dto.Warehouse != null)
                {
                    foreach (WarehouseDto.WarehouseRow row in dto.Warehouse.Rows)
                    {
                        WarehouseList.Items.Add(new ListItem(row.Name, row.WarehouseId.ToString()));
                    }
                }

                WarehouseList.DataBind();
            }

            // bind merchants
            if (MerchantList.Items.Count <= 1)
            {
                CatalogEntryDto merchants = CatalogContext.Current.GetMerchantsDto();
                if (merchants.Merchant != null)
                {
                    foreach (CatalogEntryDto.MerchantRow row in merchants.Merchant.Rows)
                    {
                        MerchantList.Items.Add(new ListItem(row.Name, row.MerchantId.ToString()));
                    }
                }
                MerchantList.DataBind();
            }

            // bind tax categories
            if (TaxList.Items.Count <= 1)
            {
                CatalogTaxDto taxes = CatalogTaxManager.GetTaxCategories();
                if (taxes.TaxCategory != null)
                {
                    foreach (CatalogTaxDto.TaxCategoryRow row in taxes.TaxCategory.Rows)
                    {
                        TaxList.Items.Add(new ListItem(row.Name, row.TaxCategoryId.ToString()));
                    }
                }
                TaxList.DataBind();
            }
        }
Example #20
0
 /// <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);
 }
        /// <summary>
        /// Get entry row from a line item
        /// </summary>
        /// <param name="lineItem">line item</param>
        protected static CatalogEntryDto.CatalogEntryRow GetEntryRowForLineItem(LineItem lineItem)
        {
            var responseGroup = new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Variations);

            CatalogEntryDto entryDto = CatalogContext.Current.GetCatalogEntryDto(lineItem.Code, responseGroup);

            return(entryDto.CatalogEntry.FirstOrDefault());
        }
Example #22
0
 private static CatalogEntryDto.CatalogEntryRow GetCatalogEntry(CatalogEntryDto entryDto)
 {
     if (entryDto == null)
     {
         throw new ArgumentNullException("entryDto");
     }
     return(entryDto.CatalogEntry.FirstOrDefault());
 }
Example #23
0
        /// <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;
                    }
                }
            }
        }
Example #24
0
        /// <summary>
        /// Loads the fresh entry.
        /// </summary>
        /// <returns></returns>
        private CatalogEntryDto LoadFreshEntry()
        {
            CatalogEntryDto entry = LoadEntry();

            // persist in session
            Session[_CatalogEntryDtoString] = entry;

            return(entry);
        }
Example #25
0
        /// <summary>
        /// Loads the items.
        /// </summary>
        /// <param name="iStartIndex">Start index of the i.</param>
        /// <param name="iNumItems">The i num items.</param>
        /// <param name="sFilter">The s filter.</param>
        private void LoadItems(int iStartIndex, int iNumItems, string sFilter)
        {
            // This method filters which entries to display in the search results.
            // By default the system displays only variations for product variations. So for instance
            // product can not have sub products and any entry for all other types of products. So
            // for instance package can have other packages and related items.
            // This behaviour can be customized by modifying the following IF statement.
            string entryType = EntryType.Variation.ToString();

            if (RelationTypeId == EntryRelationType.ProductVariation.ToString())
            {
                entryType = EntryType.Variation.ToString();
            }
            else
            {
                entryType = String.Empty;
            }

            CatalogSearchParameters pars    = new CatalogSearchParameters();
            CatalogSearchOptions    options = new CatalogSearchOptions();

            options.RecordsToRetrieve = iNumItems;
            options.Namespace         = "Mediachase.Commerce.Catalog";
            options.StartingRecord    = iStartIndex;
            options.ReturnTotalCount  = true;
            pars.SqlWhereClause       = String.Format("[CatalogEntry].Name like '%{0}%' OR [CatalogEntry].Code like '%{0}%'", sFilter);
            if (!String.IsNullOrEmpty(entryType))
            {
                pars.SqlWhereClause = pars.SqlWhereClause + String.Format(" AND ClassTypeId='{0}'", entryType);
            }

            // Add catalogs
            CatalogDto catalogDto = CatalogContext.Current.GetCatalogDto();

            foreach (CatalogDto.CatalogRow catalogRow in catalogDto.Catalog)
            {
                pars.CatalogNames.Add(catalogRow.Name);
            }

            int             totalRecords = 0;
            CatalogEntryDto dto          = CatalogContext.Current.FindItemsDto(pars, options, ref totalRecords);

            //CatalogEntryDto dto = CatalogContext.Current.GetCatalogEntriesDto(String.Format("%{0}%", sFilter), entryType);

            ItemsFilter.Items.Clear();

            foreach (CatalogEntryDto.CatalogEntryRow row in dto.CatalogEntry)
            {
                ComboBoxItem item = new ComboBoxItem(row.Name);
                item.Value   = row.CatalogEntryId.ToString();
                item["icon"] = Page.ResolveClientUrl(String.Format("~/app_themes/Default/images/icons/{0}.gif", row.ClassTypeId));
                ItemsFilter.Items.Add(item);
            }

            ItemsFilter.ItemCount = totalRecords;
        }
Example #26
0
        /// <summary>
        /// Moves the node entry.
        /// </summary>
        /// <param name="catalogId">The catalog id.</param>
        /// <param name="catalogNodeId">The catalog node id.</param>
        /// <param name="catalogEntryId">The catalog entry id.</param>
        /// <param name="targetCatalogId">The target catalog id.</param>
        /// <param name="targetCatalogNodeId">The target catalog node id.</param>
        private void MoveNodeEntry(int catalogId, int catalogNodeId, int catalogEntryId, int targetCatalogId, int targetCatalogNodeId)
        {
            if (catalogId != targetCatalogId)
            {
                CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(catalogEntryId);
                if (catalogEntryDto.CatalogEntry.Count > 0)
                {
                    catalogEntryDto.CatalogEntry[0].CatalogId = targetCatalogId;
                    CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);
                }
            }

            bool addNewRow = false;

            if (catalogId != targetCatalogId || catalogNodeId != targetCatalogNodeId)
            {
                if (catalogNodeId > 0)
                {
                    CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(catalogId, catalogNodeId, catalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));
                    if (catalogRelationDto.NodeEntryRelation.Count > 0)
                    {
                        if (targetCatalogNodeId > 0)
                        {
                            catalogRelationDto.NodeEntryRelation[0].CatalogId     = targetCatalogId;
                            catalogRelationDto.NodeEntryRelation[0].CatalogNodeId = targetCatalogNodeId;
                        }
                        else
                        {
                            catalogRelationDto.NodeEntryRelation[0].Delete();
                        }
                        CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto);
                    }
                    else if (targetCatalogNodeId > 0)
                    {
                        addNewRow = true;
                    }
                }
                else if (targetCatalogNodeId > 0)
                {
                    addNewRow = true;
                }

                if (addNewRow)
                {
                    CatalogRelationDto newCatalogRelationDto    = new CatalogRelationDto();
                    CatalogRelationDto.NodeEntryRelationRow row = newCatalogRelationDto.NodeEntryRelation.NewNodeEntryRelationRow();
                    row.CatalogId      = targetCatalogId;
                    row.CatalogNodeId  = targetCatalogNodeId;
                    row.CatalogEntryId = catalogEntryId;
                    row.SortOrder      = 0;
                    newCatalogRelationDto.NodeEntryRelation.AddNodeEntryRelationRow(row);
                    CatalogContext.Current.SaveCatalogRelationDto(newCatalogRelationDto);
                }
            }
        }
Example #27
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);
        }
Example #28
0
        /// <summary>
        /// Loads the context.
        /// </summary>
        private void LoadContext()
        {
            CatalogEntryDto       entry       = null;
            CatalogRelationDto    relation    = null;
            CatalogAssociationDto association = null;

            if (!this.IsPostBack && (!this.Request.QueryString.ToString().Contains("Callback=yes")))             // load fresh on initial load
            {
                entry       = LoadFreshEntry();
                relation    = LoadFreshRelation();
                association = LoadFreshAssociation();

                // if Dtos not loaded, create empty Dtos
                CreateEmptyDtos(ref entry, ref relation, ref association, true);
            }
            else             // load from session
            {
                entry = (CatalogEntryDto)Session[_CatalogEntryDtoString];

                if (entry == null)
                {
                    entry = LoadFreshEntry();
                }

                association = (CatalogAssociationDto)Session[_CatalogAssociationDtoString];

                if (association == null)
                {
                    association = LoadFreshAssociation();
                }

                relation = (CatalogRelationDto)Session[_CatalogRelationDtoString];

                if (relation == null)
                {
                    relation = LoadFreshRelation();
                }
            }

            if (CatalogEntryId > 0 && entry.CatalogEntry.Count == 0)
            {
                Response.Redirect("ContentFrame.aspx?_a=Catalog&_v=Catalog-List");
            }

            // Put a dictionary key that can be used by other tabs
            IDictionary dic = new ListDictionary();

            dic.Add(_CatalogEntryDtoString, entry);
            dic.Add(_CatalogRelationDtoString, relation);
            dic.Add(_CatalogAssociationDtoString, association);

            // Call tabs load context
            ViewControl.LoadContext(dic);
        }
Example #29
0
        public IEnumerable <CatalogEntryDto.VariationRow> GetVariations(int productId)
        {
            ICatalogSystem            catalog          = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance <ICatalogSystem>();
            CatalogEntryResponseGroup responseGroup    = new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull);
            CatalogEntryDto           variationEntries = catalog.GetCatalogEntriesDto(productId,
                                                                                      string.Empty,
                                                                                      string.Empty,
                                                                                      responseGroup);

            return(variationEntries.Variation.ToList());
        }
Example #30
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);
        }
Example #31
0
        /// <summary>
        /// Loads the context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void LoadContext(IDictionary context)
        {
            _CatalogEntryDto = (CatalogEntryDto)context[_CatalogEntryDtoString];

            _CatalogCurrency = (string)context[_CatalogCurrencyString];
            if (String.IsNullOrEmpty(_CatalogCurrency))
            {
                _CatalogCurrency = CommonSettingsManager.GetDefaultCurrency();
            }
            _CatalogCurrency = _CatalogCurrency.ToUpper();
        }
Example #32
0
        /// <summary>
        /// Handles the BookmarkNavigation event of the MyReportViewer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Microsoft.Reporting.WebForms.BookmarkNavigationEventArgs"/> instance containing the event data.</param>
        protected void MyReportViewer_BookmarkNavigation(object sender, BookmarkNavigationEventArgs e)
        {
            CatalogEntryDto dto = CatalogContext.Current.GetCatalogEntryDto(e.BookmarkId);

            if (dto.CatalogEntry.Count > 0)
            {
                e.Cancel = true;
                Response.Redirect(ManagementHelper.GetEntryUrl(dto.CatalogEntry[0].CatalogEntryId, dto.CatalogEntry[0].ClassTypeId));
            }

            e.Cancel = true;
        }
Example #33
0
        public void UpdateSearchDocument(ref SearchDocument document, CatalogEntryDto.CatalogEntryRow entry, string language)
        {
            var sw = new Stopwatch();
            sw.Start();
            var contentLink = _referenceConverter.GetContentLink(entry.Code);
            var productContent = _contentLoader.Get<FashionProduct>(contentLink);
            var variants = _contentLoader.GetItems(productContent.GetVariants(_relationRepository), CultureInfo.GetCultureInfo(language)).OfType<FashionVariant>().ToList();

            AddPrices(document, variants);
            AddColors(document, variants);
            AddSizes(document, variants);
            AddCodes(document, variants);
            document.Add(new SearchField("code", productContent.Code, new[] { SearchField.Store.YES, SearchField.IncludeInDefaultSearch.YES }));
            document.Add(new SearchField("displayname", productContent.DisplayName));
            document.Add(new SearchField("image_url", _assetUrlResolver.GetAssetUrl<IContentImage>(productContent)));
            document.Add(new SearchField("content_link", productContent.ContentLink.ToString()));
            document.Add(new SearchField("created", productContent.Created.ToString("yyyyMMddhhmmss")));
            document.Add(new SearchField("brand", productContent.Brand));
            document.Add(new SearchField("top_category_name", GetTopCategory(productContent).DisplayName));

            sw.Stop();
            _log.Debug(string.Format("Indexing of {0} for {1} took {2}", productContent.Code, language, sw.Elapsed.Milliseconds));
        }
Example #34
0
        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())
                );
            }
        }
 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;
 }
 private static CatalogEntryDto.CatalogEntryRow GetCatalogEntry(CatalogEntryDto entryDto)
 {
     if (entryDto == null)
     {
         throw new ArgumentNullException("entryDto");
     }
     return entryDto.CatalogEntry.FirstOrDefault();
 }
 private static IEnumerable<CatalogEntryDto.VariationRow> GetEntryVariations(CatalogEntryDto.CatalogEntryRow catalogEntry)
 {
     if (catalogEntry == null)
     {
         throw new ArgumentNullException("catalogEntry");
     }
     return catalogEntry.GetVariationRows();
 }
        protected Money? GetItemPrice(CatalogEntryDto.CatalogEntryRow entry, LineItem lineItem, CustomerContact customerContact)
        {
            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>() { new Currency(lineItem.Parent.Parent.BillingCurrency) },
                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 null;
            }
            else
            {
                return priceValue.UnitPrice;
            }
        }
 /// <summary>
 /// Check catalog entry's tracking inventory was enable or not.
 /// </summary>
 /// <param name="catalogEntry">Catalog entry.</param>
 private bool InventoryTrackingEnabled(CatalogEntryDto.CatalogEntryRow catalogEntry)
 {
     var entryVariations = catalogEntry.GetVariationRows();
     var variation = entryVariations.FirstOrDefault();
     return variation != null && variation.TrackInventory;
 }