Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <summary>
        /// Adds the price fields.
        /// </summary>
        /// <param name="doc">The doc.</param>
        /// <param name="entryRow">The entry row.</param>
        /// <param name="defaultCurrency">The default currency.</param>
        private void AddPriceFields(Document doc, CatalogEntryDto.CatalogEntryRow entryRow, string defaultCurrency)
        {
            CatalogEntryDto.VariationRow[] varRows = entryRow.GetVariationRows();
            if (varRows.Length > 0)
            {
                if (!varRows[0].IsListPriceNull())
                {
                    doc.Add(new Field(String.Format("ListPrice{0}", defaultCurrency), ConvertStringToSortable(varRows[0].ListPrice), Field.Store.NO, Field.Index.UN_TOKENIZED));
                    doc.Add(new Field(String.Format("ListPrice{0}-Value", defaultCurrency), varRows[0].ListPrice.ToString(), Field.Store.YES, Field.Index.NO));
                }
            }

            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)
                {
                    // 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
                    {
                        doc.Add(new Field(String.Format("SalePrice{0}", priceRow.Currency), ConvertStringToSortable(priceRow.UnitPrice), Field.Store.NO, Field.Index.UN_TOKENIZED));
                        doc.Add(new Field(String.Format("SalePrice{0}-Value", priceRow.Currency), priceRow.UnitPrice.ToString(), Field.Store.YES, Field.Index.NO));
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Entry"/> class.
        /// </summary>
        /// <param name="input">The input.</param>
        public Entry(CatalogEntryDto.CatalogEntryRow input)
        {
            // Populate basic parameters
            this.CatalogEntryId  = input.CatalogEntryId;
            this.ID              = input.Code;
            this.EntryType       = input.ClassTypeId;
            this.Name            = input.Name;
            this.IsActive        = input.IsActive;
            this.StartDate       = input.StartDate;
            this.EndDate         = input.EndDate;
            this.DisplayTemplate = input.TemplateName;
            this.MetaClassId     = input.MetaClassId;

            // Populate attributes
            this.ItemAttributes = new ItemAttributes();

            // Cycle through columns
            ObjectHelper.CreateAttributes(this.ItemAttributes, input);

            // Populate variations
            CatalogEntryDto.VariationRow[] variationRows = input.GetVariationRows();
            if (variationRows.Length > 0)
            {
                string currencyCode = "USD";
                string weightCode   = "LBS";

                // Get catalog info
                CatalogDto catalogDto = CatalogContext.Current.GetCatalogDto(input.CatalogId);
                if (catalogDto.Catalog.Count != 0)
                {
                    currencyCode = catalogDto.Catalog[0].DefaultCurrency;
                    weightCode   = catalogDto.Catalog[0].WeightBase;
                }

                foreach (CatalogEntryDto.VariationRow variationRow in variationRows)
                {
                    this.ItemAttributes.ListPrice   = ObjectHelper.CreatePrice(variationRow.ListPrice, currencyCode);
                    this.ItemAttributes.Weight      = ObjectHelper.CreateUnitsAttribute(weightCode, variationRow.Weight.ToString());
                    this.ItemAttributes.MinQuantity = variationRow.MinQuantity;
                    this.ItemAttributes.MaxQuantity = variationRow.MaxQuantity;
                }
            }

            // Populate sale prices
            CatalogEntryDto.SalePriceRow[] priceRows = input.GetSalePriceRows();
            if (priceRows.Length > 0)
            {
                List <SalePrice> priceList = new List <SalePrice>();
                foreach (CatalogEntryDto.SalePriceRow priceRow in priceRows)
                {
                    SalePrice price = new SalePrice();
                    if (!priceRow.IsEndDateNull())
                    {
                        price.EndDate = priceRow.EndDate;
                    }

                    price.MinQuantity = priceRow.MinQuantity;
                    if (!priceRow.IsSaleCodeNull())
                    {
                        price.SaleCode = priceRow.SaleCode;
                    }

                    price.SaleType  = SaleType.GetKey(priceRow.SaleType);
                    price.StartDate = priceRow.StartDate;
                    price.UnitPrice = ObjectHelper.CreatePrice(priceRow.UnitPrice, priceRow.Currency);
                    priceList.Add(price);
                }

                this.SalePrices           = new SalePrices();
                this.SalePrices.SalePrice = priceList.ToArray();
            }

            // Populate Inventory
            if (input.InventoryRow != null)
            {
                this.Inventory = new Inventory();
                this.Inventory.AllowBackorder            = input.InventoryRow.AllowBackorder;
                this.Inventory.BackorderAvailabilityDate = input.InventoryRow.BackorderAvailabilityDate;
                this.Inventory.BackorderQuantity         = input.InventoryRow.BackorderQuantity;
                this.Inventory.InStockQuantity           = input.InventoryRow.InStockQuantity;

                if (input.InventoryRow.InventoryStatus == 0)
                {
                    this.Inventory.InventoryStatus = "Disabled";
                }
                else if (input.InventoryRow.InventoryStatus == 1)
                {
                    this.Inventory.InventoryStatus = "Enabled";
                }
                else if (input.InventoryRow.InventoryStatus == 2)
                {
                    this.Inventory.InventoryStatus = "Ignored";
                }

                this.Inventory.AllowPreorder            = input.InventoryRow.AllowPreorder;
                this.Inventory.PreorderAvailabilityDate = input.InventoryRow.PreorderAvailabilityDate;
                this.Inventory.PreorderQuantity         = input.InventoryRow.PreorderQuantity;
                this.Inventory.ReorderMinQuantity       = input.InventoryRow.ReorderMinQuantity;
                this.Inventory.ReservedQuantity         = input.InventoryRow.ReservedQuantity;
            }

            // Populate Associations (basic names)
            CatalogEntryDto.CatalogAssociationRow[] associationRows = input.GetCatalogAssociationRows();
            if (associationRows.Length > 0)
            {
                List <Association> associationList = new List <Association>();

                foreach (CatalogEntryDto.CatalogAssociationRow associationRow in associationRows)
                {
                    Association association = new Association();

                    if (!associationRow.IsAssociationDescriptionNull())
                    {
                        association.Description = associationRow.AssociationDescription;
                    }

                    association.Name = associationRow.AssociationName;
                    associationList.Add(association);
                }

                this.Associations = associationList.ToArray();
            }

            // Populate SEO
            CatalogEntryDto.CatalogItemSeoRow[] seoRows = input.GetCatalogItemSeoRows();
            if (seoRows.Length > 0)
            {
                ArrayList seoList = new ArrayList();
                foreach (CatalogEntryDto.CatalogItemSeoRow seoRow in seoRows)
                {
                    Seo seo = new Seo();
                    if (!seoRow.IsDescriptionNull())
                    {
                        seo.Description = seoRow.Description;
                    }

                    if (!seoRow.IsKeywordsNull())
                    {
                        seo.Keywords = seoRow.Keywords;
                    }

                    seo.LanguageCode = seoRow.LanguageCode;

                    if (!seoRow.IsTitleNull())
                    {
                        seo.Title = seoRow.Title;
                    }

                    seo.Uri = seoRow.Uri;
                    seoList.Add(seo);
                }

                this.SeoInfo = (Seo[])seoList.ToArray(typeof(Seo));
            }

            // Populate Assets
            CatalogEntryDto.CatalogItemAssetRow[] assetRows = input.GetCatalogItemAssetRows();
            if (assetRows.Length > 0)
            {
                List <ItemAsset> assets = new List <ItemAsset>();
                foreach (CatalogEntryDto.CatalogItemAssetRow assetRow in assetRows)
                {
                    ItemAsset asset = new ItemAsset();
                    asset.AssetKey  = assetRow.AssetKey;
                    asset.AssetType = assetRow.AssetType;

                    if (!assetRow.IsGroupNameNull())
                    {
                        asset.GroupName = assetRow.GroupName;
                    }

                    asset.SortOrder = assetRow.SortOrder;
                    assets.Add(asset);
                }

                this.Assets = assets.ToArray();
            }

            // Populate Relation Info
            if (input.Table.Columns.Contains("RelationTypeId"))
            {
                this.RelationInfo              = new RelationInfo();
                this.RelationInfo.Quantity     = Decimal.Parse(input["Quantity"].ToString());
                this.RelationInfo.RelationType = input["RelationTypeId"].ToString();
                this.RelationInfo.SortOrder    = Int32.Parse(input["SortOrder"].ToString());
                RelationInfo.GroupName         = input["GroupName"].ToString();
            }
        }
        /// <summary>
        /// Gets the item price.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <param name="lineItem">The line item.</param>
        /// <param name="account">The account.</param>
        /// <returns></returns>
        private decimal?GetItemPrice(CatalogEntryDto.CatalogEntryRow entry, LineItem lineItem, Account account)
        {
            decimal?price = null;

            CatalogEntryDto.SalePriceRow[] priceRows = entry.GetSalePriceRows();

            string currencyCode = lineItem.Parent.Parent.BillingCurrency;

            // Determine price by using tiers
            if (priceRows.Length > 0)
            {
                foreach (CatalogEntryDto.SalePriceRow priceRow in priceRows)
                {
                    if (!currencyCode.Equals(priceRow.Currency))
                    {
                        continue;
                    }

                    // Check inventory first
                    if (priceRow.MinQuantity > lineItem.Quantity)
                    {
                        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
                    {
                        if (price == null || price > priceRow.UnitPrice)
                        {
                            price = priceRow.UnitPrice;
                        }
                    }
                    else if ((SaleType.TypeKey)priceRow.SaleType == SaleType.TypeKey.Customer) // check if it applies to a customer
                    {
                        if (account == null)
                        {
                            continue;
                        }

                        MembershipUser user = Membership.GetUser((object)account.ProviderKey);

                        if (user == null)
                        {
                            continue;
                        }

                        // Check sale code
                        if (user.UserName != priceRow.SaleCode)
                        {
                            continue; // didn't match
                        }
                        if (price == null || price > priceRow.UnitPrice)
                        {
                            price = priceRow.UnitPrice;
                        }
                    }
                    else if ((SaleType.TypeKey)priceRow.SaleType == SaleType.TypeKey.CustomerPriceGroup) // check if it applies to a customer
                    {
                        if (account == null)
                        {
                            continue;
                        }

                        // Check sale code
                        if (account.CustomerGroup != priceRow.SaleCode)
                        {
                            continue; // didn't match
                        }
                        if (price == null || price > priceRow.UnitPrice)
                        {
                            price = priceRow.UnitPrice;
                        }
                    }
                    else //NEW CODE
                    {
                        if (priceRow.SaleType.ToString() != string.Empty)
                        {
                            string salePriceTypeKey = string.Empty;

                            //get the sale type name
                            foreach (SalePriceTypeDefinition element in CatalogConfiguration.Instance.SalePriceTypes)
                            {
                                if (element.Value == priceRow.SaleType)
                                {
                                    salePriceTypeKey = element.Key;
                                    break;
                                }
                            }

                            if (HttpContext.Current.Session[salePriceTypeKey] != null)
                            {
                                // Check sale code
                                if ((string)HttpContext.Current.Session[salePriceTypeKey] != priceRow.SaleCode)
                                {
                                    continue; // didn't match
                                }
                                if (price == null || price > priceRow.UnitPrice)
                                {
                                    price = priceRow.UnitPrice;
                                }
                            }
                        }
                    } //END NEW CODE
                }
            }

            return(price);
        }