Exemplo n.º 1
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();
            }
        }
 public IEnumerable <CatalogEntryDto.CatalogItemSeoRow> GetCatalogItemSeoRows(CatalogEntryDto.CatalogEntryRow entry)
 {
     return(entry.GetCatalogItemSeoRows() ?? Enumerable.Empty <CatalogEntryDto.CatalogItemSeoRow>());
 }