コード例 #1
0
        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;
                        }
                    }
                }
            }
        }
コード例 #2
0
 private static IEnumerable <CatalogEntryDto.VariationRow> GetEntryVariations(CatalogEntryDto.CatalogEntryRow catalogEntry)
 {
     if (catalogEntry == null)
     {
         throw new ArgumentNullException("catalogEntry");
     }
     return(catalogEntry.GetVariationRows());
 }
        /// <summary>
        /// Check catalog entry's tracking inventory was enable or not.
        /// </summary>
        /// <param name="catalogEntry">Catalog entry.</param>
        private bool InventoryTrackingEnabled(CatalogEntryDto.CatalogEntryRow catalogEntry)
        {
            if (catalogEntry == null)
            {
                return(false);
            }

            var entryVariations = catalogEntry.GetVariationRows();
            var variation       = entryVariations.FirstOrDefault();

            return(variation != null && variation.TrackInventory);
        }
コード例 #4
0
ファイル: CatalogIndexBuilder.cs プロジェクト: hdgardner/ECF
        /// <summary>
        /// Gets the price.
        /// </summary>
        /// <param name="entryRow">The entry row.</param>
        /// <param name="languageCode">The language code.</param>
        /// <returns></returns>
        private decimal GetPrice(CatalogEntryDto.CatalogEntryRow entryRow, string defaultCurrency, string languageCode)
        {
            string  currencyCode = new RegionInfo(languageCode).ISOCurrencySymbol;
            decimal price        = -1;

            CatalogEntryDto.VariationRow[] varRows = entryRow.GetVariationRows();
            if (varRows.Length > 0 && defaultCurrency.Equals(currencyCode, StringComparison.OrdinalIgnoreCase))
            {
                price = varRows[0].ListPrice;
            }

            CatalogEntryDto.SalePriceRow[] saleRows = entryRow.GetSalePriceRows();
            if (saleRows != null)
            {
                // We only get sale price which is assigned to all customers, and has no quantity restrictions
                foreach (CatalogEntryDto.SalePriceRow priceRow in saleRows)
                {
                    if (!priceRow.Currency.Equals(currencyCode, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    // Check inventory first
                    if (priceRow.MinQuantity > 0)
                    {
                        continue; // didn't meet min quantity requirements
                    }
                    // Check dates
                    if (priceRow.StartDate > FrameworkContext.Current.CurrentDateTime || priceRow.EndDate < FrameworkContext.Current.CurrentDateTime)
                    {
                        continue;                                                             // falls outside of acceptable range
                    }
                    if ((SaleType.TypeKey)priceRow.SaleType == SaleType.TypeKey.AllCustomers) // no need to check, applies to everyone
                    {
                        price = priceRow.UnitPrice;
                        break;
                    }
                }
            }

            return(price);
        }
        private void PopulateVariationInfo(CatalogEntryDto.CatalogEntryRow entryRow, LineItem lineItem, List <LineItem> lineItemsToRemove)
        {
            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)
                {
                    var   billingCurrency = new Currency(lineItem.Parent.Parent.BillingCurrency);
                    Money oldListPrice    = new Money(billingCurrency.Round(lineItem.ListPrice), 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 (OrderGroup.ProviderId.ToLower().Equals("frontend") && OrderGroup is Orders.Cart)
                        {
                            lineItem.PlacedPrice = newListPrice.Value.Amount;
                        }
                    }
                }
                else
                {
                    AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(),
                                   String.Format("Item \"{0}\" has been removed from the cart. The line item doesn't have price associated.",
                                                 lineItem.DisplayName));
                    lineItemsToRemove.Add(lineItem);
                }
            }
        }
コード例 #6
0
ファイル: CatalogIndexBuilder.cs プロジェクト: hdgardner/ECF
        /// <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));
                    }
                }
            }
        }
コード例 #7
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();
            }
        }
コード例 #8
0
    /// <summary>
    /// Binds the batch control.
    /// </summary>
    private void BindData()
    {
        CatalogEntryDto.VariationRow[] variationRows = null;

        CatalogEntryDto.CatalogEntryRow item = (CatalogEntryDto.CatalogEntryRow)DataItem;

        if (IsMetaField)
        {
            int             MetaClassId = item.MetaClassId;
            int             ObjectId    = item.CatalogEntryId;
            MetaDataContext MDContext   = CatalogContext.MetaDataContext;

            MetaControls.EnableViewState = false;
            if (MetaControls.Controls.Count > 0)
            {
                return;
            }

            MetaControls.Controls.Clear();

            MetaClass mc = MetaClass.Load(MDContext, MetaClassId);

            if (mc == null)
            {
                return;
            }

            MDContext.UseCurrentUICulture = false;
            MDContext.Language            = LanguageCode;

            MetaObject metaObj = null;
            if (ObjectId > 0)
            {
                metaObj = MetaObject.Load(MDContext, ObjectId, mc);
                if (metaObj == null)
                {
                    metaObj = MetaObject.NewObject(MDContext, ObjectId, MetaClassId, FrameworkContext.Current.Profile.UserName);
                    metaObj.AcceptChanges(MDContext);
                }
            }
            MDContext.UseCurrentUICulture = true;


            MetaField mf = MetaField.Load(MDContext, FieldName);
            if (mf.IsUser)
            {
                string  controlName = ResolveMetaControl(mc, mf);
                Control ctrl        = MetaControls.FindControl(mf.Name);

                if (ctrl == null)
                {
                    ctrl = Page.LoadControl(controlName);
                    MetaControls.Controls.Add(ctrl);
                }


                CoreBaseUserControl coreCtrl = ctrl as CoreBaseUserControl;
                if (coreCtrl != null)
                {
                    coreCtrl.MDContext = MDContext;
                }

                //ctrl.ID = String.Format("{0}-{1}", mf.Name, index.ToString());

                ((IMetaControl)ctrl).MetaField = mf;
                if (metaObj != null && metaObj[mf.Name] != null)
                {
                    ((IMetaControl)ctrl).MetaObject = metaObj;
                }

                ((IMetaControl)ctrl).LanguageCode    = LanguageCode;
                ((IMetaControl)ctrl).ValidationGroup = String.Empty;

                ctrl.DataBind();
            }
        }
        else
        {
            switch (FieldName)
            {
            case "Name":
            case "Code":
                tbItem.Visible = true;
                tbItem.Text    = (string)item[FieldName];
                break;

            case "StartDate":
            case "EndDate":
                cdpItem.Visible = true;
                cdpItem.Value   = (DateTime)item[FieldName];
                break;

            case "TemplateName":
                ddlItem.Visible = true;
                TemplateDto templates = DictionaryManager.GetTemplateDto();
                if (templates.main_Templates.Count > 0)
                {
                    DataView view = templates.main_Templates.DefaultView;
                    view.RowFilter         = "TemplateType = 'entry'";
                    ddlItem.DataTextField  = "FriendlyName";
                    ddlItem.DataValueField = "Name";
                    ddlItem.DataSource     = view;
                    ddlItem.DataBind();
                }
                ManagementHelper.SelectListItem2(ddlItem, item.TemplateName);
                break;

            case "SortOrder":
                tbItem.Visible = true;
                CatalogRelationDto relationDto = CatalogContext.Current.GetCatalogRelationDto(item.CatalogId, CatalogNodeId, item.CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));
                if (relationDto.NodeEntryRelation.Count > 0)
                {
                    tbItem.Text = relationDto.NodeEntryRelation[0].SortOrder.ToString();
                }
                break;

            case "IsActive":
                becItem.Visible    = true;
                becItem.IsSelected = item.IsActive;
                break;

            case "ListPrice":
                tbItem.Visible = true;
                variationRows  = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    tbItem.Text = variationRows[0].ListPrice.ToString("#0.00");
                }
                break;

            case "TaxCategoryId":
                ddlItem.Visible = true;
                ddlItem.Items.Add(new ListItem(Resources.CatalogStrings.Entry_Select_Tax_Category, "0"));
                CatalogTaxDto taxes = CatalogTaxManager.GetTaxCategories();
                if (taxes.TaxCategory != null)
                {
                    foreach (CatalogTaxDto.TaxCategoryRow row in taxes.TaxCategory.Rows)
                    {
                        ddlItem.Items.Add(new ListItem(row.Name, row.TaxCategoryId.ToString()));
                    }
                }
                ddlItem.DataBind();
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    ManagementHelper.SelectListItem2(ddlItem, variationRows[0].TaxCategoryId);
                }
                break;

            case "TrackInventory":
                becItem.Visible = true;
                variationRows   = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    becItem.IsSelected = variationRows[0].TrackInventory;
                }
                break;

            case "MerchantId":
                ddlItem.Visible = true;
                ddlItem.Items.Insert(0, new ListItem(Resources.CatalogStrings.Entry_Select_Merchant, ""));
                CatalogEntryDto merchants = CatalogContext.Current.GetMerchantsDto();
                if (merchants.Merchant != null)
                {
                    foreach (CatalogEntryDto.MerchantRow row in merchants.Merchant.Rows)
                    {
                        ddlItem.Items.Add(new ListItem(row.Name, row.MerchantId.ToString()));
                    }
                }
                ddlItem.DataBind();
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0 && !variationRows[0].IsMerchantIdNull())
                {
                    ManagementHelper.SelectListItem2(ddlItem, variationRows[0].MerchantId);
                }
                break;

            case "WarehouseId":
                ddlItem.Visible = true;
                ddlItem.Items.Insert(0, new ListItem(Resources.CatalogStrings.Entry_Select_Warehouse, "0"));
                WarehouseDto warehouses = WarehouseManager.GetWarehouseDto();
                if (warehouses.Warehouse != null)
                {
                    foreach (WarehouseDto.WarehouseRow row in warehouses.Warehouse.Rows)
                    {
                        ddlItem.Items.Add(new ListItem(row.Name, row.WarehouseId.ToString()));
                    }
                }
                ddlItem.DataBind();
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    ManagementHelper.SelectListItem2(ddlItem, variationRows[0].WarehouseId);
                }
                break;

            case "PackageId":
                ddlItem.Visible = true;
                ddlItem.Items.Insert(0, new ListItem(Resources.CatalogStrings.Entry_Select_Package, "0"));
                ShippingMethodDto shippingDto = ShippingManager.GetShippingPackages();
                if (shippingDto.Package != null)
                {
                    foreach (ShippingMethodDto.PackageRow row in shippingDto.Package.Rows)
                    {
                        ddlItem.Items.Add(new ListItem(row.Name, row.PackageId.ToString()));
                    }
                }
                ddlItem.DataBind();
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    ManagementHelper.SelectListItem2(ddlItem, variationRows[0].PackageId);
                }
                break;

            case "Weight":
            case "MinQuantity":
            case "MaxQuantity":
                tbItem.Visible = true;
                variationRows  = item.GetVariationRows();
                if (variationRows.Length > 0 && variationRows[0][FieldName] != DBNull.Value)
                {
                    tbItem.Text = variationRows[0][FieldName].ToString();
                }
                break;

            case "InStockQuantity":
            case "ReservedQuantity":
            case "ReorderMinQuantity":
            case "PreorderQuantity":
            case "BackorderQuantity":
                tbItem.Visible = true;
                if (item.InventoryRow != null && item.InventoryRow[FieldName] != DBNull.Value)
                {
                    tbItem.Text = item.InventoryRow[FieldName].ToString();
                }
                break;

            case "AllowBackorder":
            case "AllowPreorder":
                becItem.Visible = true;
                if (item.InventoryRow != null)
                {
                    becItem.IsSelected = (bool)item.InventoryRow[FieldName];
                }
                break;

            case "InventoryStatus":
                ddlItem.Visible = true;
                ddlItem.Items.Insert(0, new ListItem(Resources.SharedStrings.Disabled, "0"));
                ddlItem.Items.Insert(0, new ListItem(Resources.SharedStrings.Enabled, "1"));
                ddlItem.Items.Insert(0, new ListItem(Resources.SharedStrings.Ignored, "2"));
                ddlItem.DataBind();
                if (item.InventoryRow != null)
                {
                    ManagementHelper.SelectListItem2(ddlItem, item.InventoryRow.InventoryStatus);
                }
                break;

            case "PreorderAvailabilityDate":
            case "BackorderAvailabilityDate":
                cdpItem.Visible = true;
                if (item.InventoryRow != null)
                {
                    cdpItem.Value = (DateTime)item.InventoryRow[FieldName];
                }
                break;
            }
        }
    }
コード例 #9
0
    /// <summary>
    /// Updates static field
    /// </summary>
    /// <param name="item">The data item.</param>
    /// <returns></returns>
    private void UpdateStaticField(CatalogEntryDto.CatalogEntryRow item)
    {
        CatalogEntryDto dto = new CatalogEntryDto();

        CatalogEntryDto.VariationRow[] variationRows = null;

        decimal decimalValue = 0;
        int     intValue     = 0;
        double  doubleValue  = 0;

        switch (FieldName)
        {
        case "Name":
            item.Name = tbItem.Text;
            dto.CatalogEntry.ImportRow(item);
            break;

        case "StartDate":
            item.StartDate = cdpItem.Value;
            dto.CatalogEntry.ImportRow(item);
            break;

        case "EndDate":
            item.EndDate = cdpItem.Value;
            dto.CatalogEntry.ImportRow(item);
            break;

        case "TemplateName":
            item.TemplateName = ddlItem.SelectedValue;
            dto.CatalogEntry.ImportRow(item);
            break;

        case "Code":
            if (item.InventoryRow != null)
            {
                CatalogEntryDto.InventoryRow inventoryRow = item.InventoryRow;
                inventoryRow.SkuId = tbItem.Text;
                dto.Inventory.ImportRow(inventoryRow);
            }
            item.Code = tbItem.Text;
            dto.CatalogEntry.ImportRow(item);
            break;

        case "SortOrder":
            intValue = -1;
            if (Int32.TryParse(tbItem.Text, out intValue))
            {
                CatalogRelationDto relationDto = CatalogContext.Current.GetCatalogRelationDto(item.CatalogId, CatalogNodeId, item.CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry));
                // Update relations
                foreach (CatalogRelationDto.NodeEntryRelationRow row in relationDto.NodeEntryRelation)
                {
                    row.SortOrder = intValue;
                }
                if (relationDto.HasChanges())
                {
                    CatalogContext.Current.SaveCatalogRelationDto(relationDto);
                }
            }
            break;

        case "IsActive":
            item.IsActive = becItem.IsSelected;
            dto.CatalogEntry.ImportRow(item);
            break;

        case "ListPrice":
            decimalValue = 0;
            if (Decimal.TryParse(tbItem.Text, out decimalValue))
            {
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    variationRows[0].ListPrice = decimalValue;
                    dto.CatalogEntry.ImportRow(item);
                    dto.Variation.ImportRow(variationRows[0]);
                }
            }
            break;

        case "TrackInventory":
            variationRows = item.GetVariationRows();
            if (variationRows.Length > 0)
            {
                variationRows[0].TrackInventory = becItem.IsSelected;
                dto.CatalogEntry.ImportRow(item);
                dto.Variation.ImportRow(variationRows[0]);
            }
            break;

        case "MerchantId":
            if (!String.IsNullOrEmpty(ddlItem.SelectedValue))
            {
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    variationRows[0].MerchantId = new Guid(ddlItem.SelectedValue);
                    dto.CatalogEntry.ImportRow(item);
                    dto.Variation.ImportRow(variationRows[0]);
                }
            }
            break;

        case "Weight":
            doubleValue = 0;
            if (Double.TryParse(tbItem.Text, out doubleValue))
            {
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    variationRows[0].Weight = doubleValue;
                    dto.CatalogEntry.ImportRow(item);
                    dto.Variation.ImportRow(variationRows[0]);
                }
            }
            break;

        case "TaxCategoryId":
        case "WarehouseId":
        case "PackageId":
            if (!String.IsNullOrEmpty(ddlItem.SelectedValue))
            {
                intValue = 0;
                if (Int32.TryParse(ddlItem.SelectedValue, out intValue))
                {
                    variationRows = item.GetVariationRows();
                    if (variationRows.Length > 0)
                    {
                        variationRows[0][FieldName] = intValue;
                        dto.CatalogEntry.ImportRow(item);
                        dto.Variation.ImportRow(variationRows[0]);
                    }
                }
            }
            break;

        case "MinQuantity":
        case "MaxQuantity":
            decimalValue = 1;
            if (Decimal.TryParse(tbItem.Text, out decimalValue))
            {
                variationRows = item.GetVariationRows();
                if (variationRows.Length > 0)
                {
                    variationRows[0][FieldName] = decimalValue;
                    dto.CatalogEntry.ImportRow(item);
                    dto.Variation.ImportRow(variationRows[0]);
                }
            }
            break;

        case "InStockQuantity":
        case "ReservedQuantity":
        case "ReorderMinQuantity":
        case "PreorderQuantity":
        case "BackorderQuantity":
            decimalValue = 0;
            if (Decimal.TryParse(tbItem.Text, out decimalValue))
            {
                if (item.InventoryRow != null)
                {
                    item.InventoryRow[FieldName] = decimalValue;
                    dto.CatalogEntry.ImportRow(item);
                    dto.Inventory.ImportRow(item.InventoryRow);
                }
            }
            break;

        case "AllowBackorder":
        case "AllowPreorder":
            if (item.InventoryRow != null)
            {
                item.InventoryRow[FieldName] = becItem.IsSelected;
                dto.CatalogEntry.ImportRow(item);
                dto.Inventory.ImportRow(item.InventoryRow);
            }
            break;

        case "InventoryStatus":
            if (!String.IsNullOrEmpty(ddlItem.SelectedValue))
            {
                intValue = 0;
                if (Int32.TryParse(ddlItem.SelectedValue, out intValue))
                {
                    if (item.InventoryRow != null)
                    {
                        item.InventoryRow[FieldName] = intValue;
                        dto.CatalogEntry.ImportRow(item);
                        dto.Inventory.ImportRow(item.InventoryRow);
                    }
                }
            }
            break;

        case "PreorderAvailabilityDate":
        case "BackorderAvailabilityDate":
            if (item.InventoryRow != null)
            {
                item.InventoryRow[FieldName] = cdpItem.Value;
                dto.CatalogEntry.ImportRow(item);
                dto.Inventory.ImportRow(item.InventoryRow);
            }
            break;
        }

        if (dto.HasChanges())
        {
            CatalogContext.Current.SaveCatalogEntry(dto);
        }
    }
コード例 #10
0
        /// <summary>
        /// Validates the items.
        /// </summary>
        private void ValidateItems()
        {
            CatalogRelationDto relationDto = null;
            CatalogDto         catalogDto  = null;
            int oldCatalogId = 0;

            foreach (OrderForm form in OrderGroup.OrderForms)
            {
                foreach (LineItem lineItem in form.LineItems)
                {
                    if (lineItem.CatalogEntryId != "0" && !String.IsNullOrEmpty(lineItem.CatalogEntryId) && !lineItem.CatalogEntryId.StartsWith("@")) // ignore custom entries
                    {
                        CatalogEntryDto entryDto = CatalogContext.Current.GetCatalogEntryDto(lineItem.CatalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

                        if (entryDto.CatalogEntry.Count > 0)
                        {
                            CatalogEntryDto.CatalogEntryRow entryRow = entryDto.CatalogEntry[0];
                            if (entryRow.IsActive && entryRow.StartDate < FrameworkContext.Current.CurrentDateTime && entryRow.EndDate > FrameworkContext.Current.CurrentDateTime)
                            {
                                if (oldCatalogId != entryRow.CatalogId)
                                {
                                    // load these Dtos only if we haven't loaded them before
                                    catalogDto   = CatalogContext.Current.GetCatalogDto(entryRow.CatalogId);
                                    relationDto  = CatalogContext.Current.GetCatalogRelationDto(entryRow.CatalogId, 0, 0, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogEntry));
                                    oldCatalogId = entryRow.CatalogId;
                                }

                                // check if catalog is visible
                                if (catalogDto.Catalog.Count > 0 && catalogDto.Catalog[0].IsActive && catalogDto.Catalog[0].StartDate <FrameworkContext.Current.CurrentDateTime && catalogDto.Catalog[0].EndDate> FrameworkContext.Current.CurrentDateTime)
                                {
                                    // populate item
                                    lineItem.Catalog = catalogDto.Catalog[0].Name;

                                    // get parent entry
                                    if (relationDto.CatalogEntryRelation.Count > 0)
                                    {
                                        CatalogRelationDto.CatalogEntryRelationRow[] entryRelationRows = (CatalogRelationDto.CatalogEntryRelationRow[])relationDto.CatalogEntryRelation.Select(String.Format("ChildEntryId={0}", entryRow.CatalogEntryId));
                                        if (entryRelationRows.Length > 0)
                                        {
                                            CatalogEntryDto parentEntryDto = CatalogContext.Current.GetCatalogEntryDto(entryRelationRows[0].ParentEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));
                                            if (parentEntryDto.CatalogEntry.Count > 0)
                                            {
                                                lineItem.ParentCatalogEntryId = parentEntryDto.CatalogEntry[0].Code;
                                            }
                                        }
                                    }

                                    // Inventory info
                                    CatalogEntryDto.InventoryRow invRow = entryRow.InventoryRow;
                                    if (invRow != null)
                                    {
                                        lineItem.AllowBackordersAndPreorders = invRow.AllowBackorder | invRow.AllowPreorder;
                                        lineItem.BackorderQuantity           = invRow.BackorderQuantity;
                                        lineItem.InStockQuantity             = invRow.InStockQuantity;
                                        lineItem.InventoryStatus             = invRow.InventoryStatus;
                                        lineItem.PreorderQuantity            = invRow.PreorderQuantity;
                                    }

                                    CatalogEntryDto.VariationRow[] varRows = entryRow.GetVariationRows();

                                    if (varRows.Length > 0)
                                    {
                                        CatalogEntryDto.VariationRow varRow = varRows[0];

                                        lineItem.MaxQuantity = varRow.MaxQuantity;
                                        lineItem.MinQuantity = varRow.MinQuantity;

                                        Account account  = ProfileContext.Current.GetAccount(lineItem.Parent.Parent.CustomerId);
                                        decimal?newPrice = GetItemPrice(entryRow, lineItem, account);

                                        if (newPrice == null)
                                        {
                                            newPrice = varRow.ListPrice;
                                        }

                                        // Check the price changes if any
                                        if (lineItem.ListPrice != (decimal)newPrice)
                                        {
                                            Warnings.Add("LineItemPriceChange-" + form.LineItems.IndexOf(lineItem).ToString(), String.Format("Price for \"{0}\" has been changed from {1:c} to {2:c}.", lineItem.DisplayName, lineItem.ListPrice, newPrice));
                                            lineItem.ListPrice = (decimal)newPrice;
                                            //lineItem.PlacedPrice = lineItem.ListPrice;
                                        }
                                    }

                                    continue;
                                }
                                else
                                {
                                    // Go to remove
                                }
                            }
                        }

                        // Remove item if it reached this stage
                        Warnings.Add("LineItemRemoved-" + lineItem.Id.ToString(), String.Format("Item \"{0}\" has been removed from the cart because it is no longer available.", lineItem.DisplayName));

                        // Delete item
                        lineItem.Delete();
                    }
                }
            }
        }