public async Task <ItemType> AddItem(CommerceContext commerceContext, SellableItem sellableItem) { using (CommandActivity.Start(commerceContext, this)) { var ebayItemComponent = sellableItem.GetComponent <EbayItemComponent>(); try { // Instantiate the call wrapper class var apiCall = new AddFixedPriceItemCall(await this.GetEbayContext(commerceContext)); var item = await this.PrepareItem(commerceContext, sellableItem); // Send the call to eBay and get the results var feeTypeCollection = apiCall.AddFixedPriceItem(item); foreach (var feeItem in feeTypeCollection) { var fee = feeItem as FeeType; ebayItemComponent.Fees.Add(new AwardedAdjustment { Adjustment = new Money(fee.Fee.currencyID.ToString(), System.Convert.ToDecimal(fee.Fee.Value)), AdjustmentType = "Fee", Name = fee.Name }); } ebayItemComponent.History.Add(new HistoryEntryModel { EventMessage = "Listing Added", EventUser = commerceContext.CurrentCsrId() }); ebayItemComponent.EbayId = item.ItemID; ebayItemComponent.Status = "Listed"; sellableItem.GetComponent <TransientListMembershipsComponent>().Memberships.Add("Ebay_Listed"); await commerceContext.AddMessage("Info", "EbayCommand.AddItem", new object[] { item.ItemID }, $"Item Listed:{item.ItemID}"); return(item); } catch (Exception ex) { if (ex.Message.Contains("It looks like this listing is for an item you already have on eBay")) { var existingId = ex.Message.Substring(ex.Message.IndexOf("(") + 1); existingId = existingId.Substring(0, existingId.IndexOf(")")); await commerceContext.AddMessage("Warn", "EbayCommand.AddItem", new object[] { existingId }, $"ExistingId:{existingId}-ComponentId:{ebayItemComponent.EbayId}"); ebayItemComponent.EbayId = existingId; ebayItemComponent.Status = "Listed"; ebayItemComponent.History.Add(new HistoryEntryModel { EventMessage = "Existing Listing Linked", EventUser = commerceContext.CurrentCsrId() }); sellableItem.GetComponent <TransientListMembershipsComponent>().Memberships.Add("Ebay_Listed"); } else { commerceContext.Logger.LogError($"Ebay.AddItem.Exception: Message={ex.Message}"); await commerceContext.AddMessage("Error", "Ebay.AddItem.Exception", new object[] { ex }, ex.Message); ebayItemComponent.History.Add(new HistoryEntryModel { EventMessage = $"Error-{ex.Message}", EventUser = commerceContext.CurrentCsrId() }); } } return(new ItemType()); } }
private async Task AddSellableItemParentCategories(EntityView entityView, SellableItem entity, CommercePipelineExecutionContext context) { var viewsPolicy = context.GetPolicy <KnownCatalogViewsPolicy>(); if (entity == null || !entityView.Name.Equals(viewsPolicy.Master, StringComparison.OrdinalIgnoreCase) && !entityView.Name.Equals(viewsPolicy.Details, StringComparison.OrdinalIgnoreCase) && !entityView.Name.Equals(viewsPolicy.ConnectSellableItem, StringComparison.OrdinalIgnoreCase)) { return; } var parentCategoriesEntityView = new EntityView { Name = viewsPolicy.ParentCategories, EntityId = entity.Id, EntityVersion = entity.EntityVersion, UiHint = "Table" }; await this.SetListMetadata(parentCategoriesEntityView, viewsPolicy.ParentCategories, "PaginateCatalogItemList", context); var allCategories = await this.Commander.Pipeline <IGetCategoriesPipeline>().Run(new GetCategoriesArgument(" "), context); if (allCategories != null && !string.IsNullOrEmpty(entity.ParentCategoryList)) { var parentCategories = allCategories.Where(category => entity.ParentCategoryList.Split('|').Any(id => id.Equals(category.SitecoreId, StringComparison.OrdinalIgnoreCase))); foreach (var category in parentCategories) { var categoryView = new EntityView { EntityId = entity.Id, ItemId = category.Id, EntityVersion = category.EntityVersion, Name = viewsPolicy.Summary }; var viewProperty = new ViewProperty { Name = "Id", RawValue = category.Id, IsReadOnly = true, UiType = "EntityLink" }; categoryView.Properties.Add(viewProperty); var viewProperty1 = new ViewProperty { Name = "Name", RawValue = category.Name, IsReadOnly = true, }; categoryView.Properties.Add(viewProperty1); var viewProperty2 = new ViewProperty { Name = "DisplayName", RawValue = category.DisplayName, IsReadOnly = true }; categoryView.Properties.Add(viewProperty2); var viewProperty3 = new ViewProperty { Name = "Description", RawValue = category.Description ?? string.Empty, IsReadOnly = true }; categoryView.Properties.Add(viewProperty3); parentCategoriesEntityView.ChildViews.Add(categoryView); } } entityView.ChildViews.Add(parentCategoriesEntityView); }
public async Task <bool> EndItemListing(CommerceContext commerceContext, SellableItem sellableItem, string reason) { using (var activity = CommandActivity.Start(commerceContext, this)) { //Instantiate the call wrapper class try { var apiCall = new EndItemCall(await GetEbayContext(commerceContext)); if (sellableItem.HasComponent <EbayItemComponent>()) { var ebayItemComponent = sellableItem.GetComponent <EbayItemComponent>(); var reasonCodeType = EndReasonCodeType.NotAvailable; switch (reason) { case "NotAvailable": reasonCodeType = EndReasonCodeType.NotAvailable; break; case "CustomCode": reasonCodeType = EndReasonCodeType.CustomCode; break; case "Incorrect": reasonCodeType = EndReasonCodeType.Incorrect; break; case "LostOrBroken": reasonCodeType = EndReasonCodeType.LostOrBroken; break; case "OtherListingError": reasonCodeType = EndReasonCodeType.OtherListingError; break; case "SellToHighBidder": reasonCodeType = EndReasonCodeType.SellToHighBidder; break; case "Sold": reasonCodeType = EndReasonCodeType.Sold; break; default: reasonCodeType = EndReasonCodeType.CustomCode; break; } if (string.IsNullOrEmpty(ebayItemComponent.EbayId)) { ebayItemComponent.Status = "LostSync"; } else { if (ebayItemComponent.Status != "Ended") { //Call Ebay and End the Item Listing try { apiCall.EndItem(ebayItemComponent.EbayId, reasonCodeType); ebayItemComponent.Status = "Ended"; } catch (Exception ex) { if (ex.Message == "The auction has already been closed.") { //Capture a case where the listing has expired naturally and it can now no longer be ended. reason = "Expired"; ebayItemComponent.Status = "Ended"; } else { commerceContext.Logger.LogError(ex, $"EbayCommand.EndItemListing.Exception: Message={ex.Message}"); await commerceContext.AddMessage("Error", "EbayCommand.EndItemListing", new [] { ex }, ex.Message).ConfigureAwait(false); } } } } ebayItemComponent.ReasonEnded = reason; ebayItemComponent.History.Add(new HistoryEntryModel { EventMessage = "Listing Ended", EventUser = commerceContext.CurrentCsrId() }); sellableItem.GetComponent <TransientListMembershipsComponent>().Memberships.Add("Ebay_Ended"); var persistResult = await this._commerceCommander.PersistEntity(commerceContext, sellableItem).ConfigureAwait(false); var listRemoveResult = await this._commerceCommander.Command <ListCommander>() .RemoveItemsFromList(commerceContext, "Ebay_Listed", new List <String>() { sellableItem.Id }).ConfigureAwait(false); } } catch (Exception ex) { commerceContext.Logger.LogError($"Ebay.EndItemListing.Exception: Message={ex.Message}"); await commerceContext.AddMessage("Error", "Ebay.EndItemListing.Exception", new Object[] { ex }, ex.Message).ConfigureAwait(false); } return(true); } }
private void CopyCategoryAddressAdded(CommerceContext commerceContext, SellableItem existingItem, List <string> associationsToCreate) { var transientData = existingItem.GetPolicy <TransientImportSellableItemDataPolicy>(); transientData.ParentAssociationsToCreateList = transientData.ParentAssociationsToCreateList.Where(a => associationsToCreate.Contains(a.ParentSitecoreId)).ToList(); }
public async Task AddEntityProperties(CommercePipelineExecutionContext context, EntityView entityView, EntityView detailsView, SellableItem entity, bool isAddAction, bool isEditAction, string viewName) { var policy = context.GetPolicy <KnownCatalogViewsPolicy>(); var itemId = entityView.ItemId; if (!string.IsNullOrEmpty(itemId)) { detailsView.ItemId = itemId; } var variation = entity.GetVariation(itemId); var flag1 = variation != null; var properties1 = detailsView.Properties; var viewProperty1 = new ViewProperty { Name = flag1 ? "VariantId" : "ProductId", RawValue = flag1 ? variation.Id : entity?.ProductId ?? string.Empty, IsReadOnly = !isAddAction, IsRequired = isAddAction | isEditAction, IsHidden = false }; properties1.Add(viewProperty1); var properties2 = detailsView.Properties; var viewProperty2 = new ViewProperty { Name = "Name", RawValue = variation != null ? variation.Name : entity?.Name ?? string.Empty, IsReadOnly = !isAddAction, IsRequired = isAddAction, IsHidden = !isAddAction }; properties2.Add(viewProperty2); var properties3 = detailsView.Properties; var viewProperty3 = new ViewProperty { Name = "DisplayName", RawValue = variation != null ? variation.DisplayName : entity?.DisplayName ?? string.Empty, IsReadOnly = !isAddAction && !isEditAction, IsRequired = isAddAction | isEditAction, IsHidden = false }; properties3.Add(viewProperty3); if (!isAddAction && !isEditAction) { var definitions = new List <string>(); if (entity != null && entity.HasComponent <CatalogsComponent>()) { entity.GetComponent <CatalogsComponent>().Catalogs.Where(c => !string.IsNullOrEmpty(c.ItemDefinition)).ForEach(c => definitions.Add( $"{c.Name} - {c.ItemDefinition}")); } var properties4 = detailsView.Properties; var viewProperty4 = new ViewProperty { Name = "ItemDefinitions", RawValue = definitions, IsReadOnly = true, IsRequired = false, UiType = "List", OriginalType = "List" }; properties4.Add(viewProperty4); } var properties5 = detailsView.Properties; var viewProperty5 = new ViewProperty { Name = "Description", RawValue = variation != null ? variation.Description : entity?.Description ?? string.Empty, IsReadOnly = !isAddAction && !isEditAction, IsRequired = false, IsHidden = false }; properties5.Add(viewProperty5); var properties6 = detailsView.Properties; var viewProperty6 = new ViewProperty { Name = "Brand", RawValue = entity?.Brand ?? string.Empty, IsReadOnly = ((isAddAction ? 0 : (!isEditAction ? 1 : 0)) | (flag1 ? 1 : 0)) != 0, IsRequired = false, IsHidden = false }; properties6.Add(viewProperty6); var properties7 = detailsView.Properties; var viewProperty7 = new ViewProperty { Name = "Manufacturer", RawValue = entity?.Manufacturer ?? string.Empty, IsReadOnly = ((isAddAction ? 0 : (!isEditAction ? 1 : 0)) | (flag1 ? 1 : 0)) != 0, IsRequired = false, IsHidden = false }; properties7.Add(viewProperty7); var properties8 = detailsView.Properties; var viewProperty8 = new ViewProperty { Name = "TypeOfGood", RawValue = entity?.TypeOfGood ?? string.Empty, IsReadOnly = ((isAddAction ? 0 : (!isEditAction ? 1 : 0)) | (flag1 ? 1 : 0)) != 0, IsRequired = false, IsHidden = false }; properties8.Add(viewProperty8); var source = ((variation?.Tags ?? entity?.Tags) ?? new List <Tag>()).Select(x => x.Name); var properties9 = detailsView.Properties; var viewProperty9 = new ViewProperty { Name = "Tags", RawValue = source.ToArray(), IsReadOnly = !isAddAction && !isEditAction, IsRequired = false, IsHidden = false, UiType = isEditAction | isAddAction ? "Tags" : "List", OriginalType = "List" }; properties9.Add(viewProperty9); var flag2 = entityView.Name.Equals(policy.ConnectSellableItem, StringComparison.OrdinalIgnoreCase); if (flag2) { var properties4 = detailsView.Properties; var viewProperty4 = new ViewProperty { Name = "VariationProperties", RawValue = string.Empty, IsReadOnly = true, IsRequired = false, IsHidden = false }; properties4.Add(viewProperty4); var properties10 = detailsView.Properties; var viewProperty10 = new ViewProperty { Name = "SitecoreId", RawValue = entity?.SitecoreId ?? string.Empty, IsReadOnly = true, IsRequired = false, IsHidden = true }; properties10.Add(viewProperty10); var properties11 = detailsView.Properties; var viewProperty11 = new ViewProperty { Name = "ParentCatalogList", RawValue = entity?.ParentCatalogList ?? string.Empty, IsReadOnly = true, IsRequired = false, IsHidden = true }; properties11.Add(viewProperty11); var properties12 = detailsView.Properties; var viewProperty12 = new ViewProperty { Name = "ParentCategoryList", RawValue = entity?.ParentCategoryList ?? string.Empty, IsReadOnly = true, IsRequired = false, IsHidden = true }; properties12.Add(viewProperty12); } if (isAddAction || isEditAction) { return; } var dictionary = new Dictionary <string, object>(); var entityView1 = new EntityView { DisplayName = "Identifiers", Name = "Identifiers", UiHint = "Flat", EntityId = entityView.EntityId, EntityVersion = entityView.EntityVersion, ItemId = itemId }; var entityView2 = entityView1; if (entity != null && entity.HasComponent <IdentifiersComponent>(itemId) | flag2) { var component = entity.GetComponent <IdentifiersComponent>(itemId); dictionary.Add("ISBN", component.ISBN); dictionary.Add("LEICode", component.LEICode); dictionary.Add("SKU", component.SKU); dictionary.Add("TaxID", component.TaxID); dictionary.Add("gtin8", component.gtin8); dictionary.Add("gtin12", component.gtin12); dictionary.Add("gtin13", component.gtin13); dictionary.Add("mbm", component.mbm); dictionary.Add("ISSN", component.ISSN); foreach (var keyValuePair in dictionary) { var properties4 = entityView2.Properties; var viewProperty4 = new ViewProperty { Name = keyValuePair.Key, RawValue = keyValuePair.Value ?? string.Empty, IsReadOnly = true, IsRequired = false, IsHidden = false }; properties4.Add(viewProperty4); } } var entityView3 = new EntityView { DisplayName = "Display Properties", Name = "DisplayProperties", UiHint = "Flat", EntityId = entityView.EntityId, EntityVersion = entityView.EntityVersion, ItemId = itemId }; var entityView4 = entityView3; dictionary.Clear(); if (entity != null && entity.HasComponent <DisplayPropertiesComponent>(itemId) | flag2) { var component = entity.GetComponent <DisplayPropertiesComponent>(itemId); var properties4 = entityView4.Properties; var viewProperty4 = new ViewProperty { Name = "Color", RawValue = component.Color ?? string.Empty, IsReadOnly = true, IsRequired = false, IsHidden = false }; properties4.Add(viewProperty4); var properties10 = entityView4.Properties; var viewProperty10 = new ViewProperty { Name = "Size", RawValue = component.Size ?? string.Empty, IsReadOnly = true, IsRequired = false, IsHidden = false }; properties10.Add(viewProperty10); var properties11 = entityView4.Properties; var viewProperty11 = new ViewProperty { Name = "DisambiguatingDescription", RawValue = component.DisambiguatingDescription ?? string.Empty, IsReadOnly = true, IsRequired = false, IsHidden = false }; properties11.Add(viewProperty11); var properties12 = entityView4.Properties; var viewProperty12 = new ViewProperty { Name = "DisplayOnSite", RawValue = component.DisplayOnSite, IsReadOnly = true, IsRequired = false, IsHidden = false }; properties12.Add(viewProperty12); var properties13 = entityView4.Properties; var viewProperty13 = new ViewProperty { Name = "DisplayInProductList", RawValue = component.DisplayInProductList, IsReadOnly = true, IsRequired = false, IsHidden = false }; properties13.Add(viewProperty13); var properties14 = entityView4.Properties; var viewProperty14 = new ViewProperty { Name = "Style", RawValue = component.Style, IsReadOnly = true, IsRequired = false, IsHidden = false }; properties14.Add(viewProperty14); } var entityView5 = new EntityView { DisplayName = "Images", Name = "Images", UiHint = "Table", EntityId = entityView.EntityId, EntityVersion = entityView.EntityVersion, ItemId = itemId }; var entityView6 = entityView5; var entityView7 = new EntityView { DisplayName = "Item Specifications", Name = "ItemSpecifications", UiHint = "Flat", EntityId = entityView.EntityId, EntityVersion = entityView.EntityVersion, ItemId = itemId }; var entityView8 = entityView7; dictionary.Clear(); if (entity != null && entity.HasComponent <ItemSpecificationsComponent>(itemId) | flag2) { var component = entity.GetComponent <ItemSpecificationsComponent>(itemId); if (component.AreaServed == null) { component.AreaServed = new GeoLocation(); } var city = component.AreaServed.City; var region = component.AreaServed.Region; var postalCode = component.AreaServed.PostalCode; var str1 = string.IsNullOrWhiteSpace(region) ? "" : ", " + region; var str2 = string.IsNullOrWhiteSpace(postalCode) ? "" : ", " + postalCode; var str3 = $"{city}{str1}{str2}".TrimStart(','); dictionary.Add("AreaServed", str3); if (flag2) { dictionary.Add("Weight", component.Weight); dictionary.Add("WeightUnitOfMeasure", component.WeightUnitOfMeasure); dictionary.Add("Length", component.Length); dictionary.Add("Width", component.Width); dictionary.Add("Height", component.Height); dictionary.Add("DimensionsUnitOfMeasure", component.DimensionsUnitOfMeasure); dictionary.Add("SizeOnDisk", component.Weight); dictionary.Add("SizeOnDiskUnitOfMeasure", component.WeightUnitOfMeasure); } else { dictionary.Add("Weight", $"{component.Weight} {component.WeightUnitOfMeasure}"); var str4 = string.Format("{0}{3}x{1}{3}x{2}{3}", component.Width, component.Height, component.Length, component.DimensionsUnitOfMeasure); dictionary.Add("Dimensions", str4); dictionary.Add("DigitalProperties", $"{component.SizeOnDisk} {component.SizeOnDiskUnitOfMeasure}"); } foreach (var keyValuePair in dictionary) { var properties4 = entityView8.Properties; var viewProperty4 = new ViewProperty { Name = keyValuePair.Key, RawValue = keyValuePair.Value, IsReadOnly = true, IsRequired = false, IsHidden = false }; properties4.Add(viewProperty4); } } this.AddSellableItemPricing(entityView, entity, variation, context); AddSellableItemVariations(entityView, entity, context); await AddSellableItemParentCategories(entityView, entity, context); entityView.ChildViews.Add(entityView2); entityView.ChildViews.Add(entityView4); entityView.ChildViews.Add(entityView6); entityView.ChildViews.Add(entityView8); if (!entityView.Name.Equals("Variant", StringComparison.OrdinalIgnoreCase)) { return; } var properties15 = entityView.Properties; var viewProperty15 = new ViewProperty { DisplayName = "DisplayName", Name = "DisplayName", RawValue = variation?.DisplayName }; properties15.Add(viewProperty15); }
private void CopyCatalog(SellableItem itemNewData, SellableItem item) { item.ParentCatalogList = itemNewData.ParentCatalogList; }
private void CopyListPrice(SellableItem itemNewData, SellableItem item) { item.RemovePolicy(typeof(ListPricingPolicy)); item.Policies.Add(itemNewData.GetPolicy <ListPricingPolicy>()); }
private async Task UpsertSellableItem(SellableItem item, CommercePipelineExecutionContext context) { if (string.IsNullOrEmpty(item.ProductId)) { item.ProductId = item.Id.SimplifyEntityName().ProposeValidId(); } if (string.IsNullOrEmpty(item.FriendlyId)) { item.FriendlyId = item.Id.SimplifyEntityName(); } if (string.IsNullOrEmpty(item.SitecoreId)) { item.SitecoreId = GuidUtils.GetDeterministicGuidString(item.Id); } var entity = await _findEntityPipeline.Run(new FindEntityArgument(typeof(SellableItem), item.Id), context).ConfigureAwait(false); if (entity == null) { await _persistEntityPipeline.Run(new PersistEntityArgument(item), context).ConfigureAwait(false); return; } if (!(entity is SellableItem)) { return; } var existingSellableItem = entity as SellableItem; // Try to merge the items. existingSellableItem.Name = item.Name; foreach (var policy in item.Policies) { if (existingSellableItem.HasPolicy(policy.GetType())) { existingSellableItem.RemovePolicy(policy.GetType()); } existingSellableItem.SetPolicy(policy); } if (item.HasComponent<ItemVariationsComponent>()) { var variations = existingSellableItem.GetComponent<ItemVariationsComponent>(); foreach (var variation in item.GetComponent<ItemVariationsComponent>().ChildComponents.OfType<ItemVariationComponent>()) { var existingVariation = existingSellableItem.GetVariation(variation.Id); if (existingVariation != null) { existingVariation.Name = variation.Name; foreach (var policy in variation.Policies) { if (existingVariation.Policies.Any(x => x.GetType() == policy.GetType())) { existingVariation.RemovePolicy(policy.GetType()); } existingVariation.SetPolicy(policy); } } else { variations.ChildComponents.Add(variation); } } } await _persistEntityPipeline.Run(new PersistEntityArgument(existingSellableItem), context).ConfigureAwait(false); }
/// <summary> /// Bootstraps the appliances. /// </summary> /// <param name="context">The context.</param> /// <returns>A <see cref="Task"/></returns> private async Task BootstrapAppliances(CommercePipelineExecutionContext context) { var item = new SellableItem(new List<Component> { new ItemVariationsComponent { ChildComponents = new List<Component> { new ItemVariationComponent(new List<Policy> { new ListPricingPolicy(new List<Money> { new Money("USD", 3029.99M), new Money("CAD", 3030.99M) }) }) { Id = "56042591", Name = "Habitat Viva 4-Door 34.0 Cubic Foot Refrigerator w/ Ice Maker and Wifi (Stainless)", ChildComponents = new List<Component> { //new PhysicalItemComponent() } }, new ItemVariationComponent(new List<Policy> { new ListPricingPolicy(new List<Money> { new Money("USD", 3029.99M), new Money("CAD", 3030.99M) }) }) { Id = "56042592", Name = "Habitat Viva 4-Door 34.0 Cubic Foot Refrigerator w/ Ice Maker and Wifi (Black)", ChildComponents = new List<Component> { //new PhysicalItemComponent() } }, new ItemVariationComponent(new List<Policy> { new ListPricingPolicy(new List<Money> { new Money("USD", 3029.99M), new Money("CAD", 3030.99M) }) }) { Id = "56042593", Name = "Habitat Viva 4-Door 34.0 Cubic Foot Refrigerator w/ Ice Maker and Wifi (White)", ChildComponents = new List<Component> { //new PhysicalItemComponent() } } } } }, new List<Policy> { new ListPricingPolicy(new List<Money> {new Money("USD", 2302.79M), new Money("CAD", 2303.79M)}) }) { Id = $"{CommerceEntity.IdPrefix<SellableItem>()}6042591", Name = "Habitat Viva 4-Door 34.0 Cubic Foot Refrigerator with Ice Maker and Wifi" }; await UpsertSellableItem(item, context).ConfigureAwait(false); }
/// <summary> /// Bootstraps the computers. /// </summary> /// <param name="context">The context.</param> /// <returns>A <see cref="Task"/></returns> private async Task BootstrapComputers(CommercePipelineExecutionContext context) { var item = new SellableItem(new List<Component> { new ItemVariationsComponent { ChildComponents = new List<Component> { new ItemVariationComponent(new List<Policy> { new ListPricingPolicy( new List<Money> {new Money("USD", 429.00M), new Money("CAD", 430.00M)}) }) { Id = "56042179", Name = "Mira 15.6 Laptop—4GB Memory, 1TB Hard Drive", ChildComponents = new List<Component> { //new PhysicalItemComponent() } } } } }, new List<Policy> { new ListPricingPolicy(new List<Money> {new Money("USD", 429.00M), new Money("CAD", 430.00M)}) }) { Id = $"{CommerceEntity.IdPrefix<SellableItem>()}6042179", Name = "Mira 15.6 Laptop—4GB Memory, 1TB Hard Drive" }; await UpsertSellableItem(item, context).ConfigureAwait(false); item = new SellableItem(new List<Component> { new ItemVariationsComponent { ChildComponents = new List<Component> { new ItemVariationComponent(new List<Policy> { new ListPricingPolicy(new List<Money> { new Money("USD", 989.00M), new Money("CAD", 990.00M) }) }) { Id = "56042190", Name = "Fusion 13.3” 2-in-1—8GB Memory, 256GB Hard Drive", ChildComponents = new List<Component> { //new PhysicalItemComponent() } } } } }, new List<Policy> { new ListPricingPolicy(new List<Money> {new Money("USD", 989.00M), new Money("CAD", 990.00M)}) }) { Id = $"{CommerceEntity.IdPrefix<SellableItem>()}6042190", Name = "Fusion 13.3” 2-in-1—8GB Memory, 256GB Hard Drive" }; await UpsertSellableItem(item, context).ConfigureAwait(false); item = new SellableItem(new List<Component> { new ItemVariationsComponent { ChildComponents = new List<Component> { new ItemVariationComponent(new List<Policy> { new ListPricingPolicy(new List<Money> { new Money("USD", 289.00M), new Money("CAD", 290.00M) }) }) { Id = "56042178", Name = "Mira 15.6 Laptop—4GB Memory, 500GB Hard Drive", ChildComponents = new List<Component> { //new PhysicalItemComponent() } } } } }, new List<Policy> { new ListPricingPolicy(new List<Money> {new Money("USD", 289.00M), new Money("CAD", 290.00M)}) }) { Id = $"{CommerceEntity.IdPrefix<SellableItem>()}6042178", Name = "Mira 15.6 Laptop—4GB Memory, 500GB Hard Drive" }; await UpsertSellableItem(item, context).ConfigureAwait(false); }
/// <summary> /// Bootstraps the gift cards. /// </summary> /// <param name="context">The context.</param> /// <returns>A <see cref="Task"/></returns> private async Task BootstrapGiftCards(CommercePipelineExecutionContext context) { var giftCardSellableItem = new SellableItem(new List<Component>(), new List<Policy> { new AvailabilityAlwaysPolicy() }) { Id = $"{CommerceEntity.IdPrefix<SellableItem>()}GiftCardV2", ProductId = "DefaultGiftCardV2", Name = "Default GiftCard V2" //Components = new List<Component> //{ // new ListMembershipsComponent { Memberships = new List<string> { CommerceEntity.ListName<SellableItem>() } } //} }; await UpsertSellableItem(giftCardSellableItem, context).ConfigureAwait(false); var giftCard = new SellableItem(new List<Component> { new ItemVariationsComponent { ChildComponents = new List<Component> { new ItemVariationComponent(new List<Policy> { new AvailabilityAlwaysPolicy(), new ListPricingPolicy( new List<Money> {new Money("USD", 25M), new Money("CAD", 26M)}) }) { Id = "56042986", Name = "Gift Card" }, new ItemVariationComponent(new List<Policy> { new AvailabilityAlwaysPolicy(), new ListPricingPolicy( new List<Money> {new Money("USD", 50M), new Money("CAD", 51M)}) }) { Id = "56042987", Name = "Gift Card" }, new ItemVariationComponent(new List<Policy> { new AvailabilityAlwaysPolicy(), new ListPricingPolicy( new List<Money> {new Money("USD", 100M), new Money("CAD", 101M)}) }) { Id = "56042988", Name = "Gift Card" } } } }, new List<Policy> { new AvailabilityAlwaysPolicy() }) { Id = $"{CommerceEntity.IdPrefix<SellableItem>()}6042986", ProductId = "GiftCard", Name = "Default GiftCard" }; await UpsertSellableItem(giftCard, context).ConfigureAwait(false); }
/// <summary> /// Bootstraps the computers. /// </summary> /// <param name="context">The context.</param> /// <returns>A <see cref="Task"/></returns> private async Task BootstrapComputers(CommercePipelineExecutionContext context) { var item = new SellableItem { Components = new List <Component> { new CatalogComponent { Name = "Habitat_Mater" }, new ListMembershipsComponent { Memberships = new List <string> { CommerceEntity.ListName <SellableItem>() } }, new ItemVariationsComponent { ChildComponents = new List <Component> { new ItemVariationComponent { Id = "56042179", Name = "Mira 15.6 Laptop—4GB Memory, 1TB Hard Drive", Policies = new List <Policy> { new ListPricingPolicy(new List <Money> { new Money("USD", 429.00M), new Money("CAD", 430.00M) }) }, ChildComponents = new List <Component> { new PhysicalItemComponent() } } } } }, Policies = new List <Policy> { new ListPricingPolicy(new List <Money> { new Money("USD", 429.00M), new Money("CAD", 430.00M) }) }, Id = $"{CommerceEntity.IdPrefix<SellableItem>()}6042179", Name = "Mira 15.6 Laptop—4GB Memory, 1TB Hard Drive" }; await this._persistEntityPipeline.Run(new PersistEntityArgument(item), context); item = new SellableItem { Components = new List <Component> { new CatalogComponent { Name = "Habitat_Mater" }, new ListMembershipsComponent { Memberships = new List <string> { CommerceEntity.ListName <SellableItem>() } }, new ItemVariationsComponent { ChildComponents = new List <Component> { new ItemVariationComponent { Id = "56042190", Name = "Fusion 13.3” 2-in-1—8GB Memory, 256GB Hard Drive", Policies = new List <Policy> { new ListPricingPolicy(new List <Money> { new Money("USD", 989.00M), new Money("CAD", 990.00M) }) }, ChildComponents = new List <Component> { new PhysicalItemComponent() } } } } }, Policies = new List <Policy> { new ListPricingPolicy(new List <Money> { new Money("USD", 989.00M), new Money("CAD", 990.00M) }) }, Id = $"{CommerceEntity.IdPrefix<SellableItem>()}6042190", Name = "Fusion 13.3” 2-in-1—8GB Memory, 256GB Hard Drive" }; await this._persistEntityPipeline.Run(new PersistEntityArgument(item), context); item = new SellableItem { Components = new List <Component> { new CatalogComponent { Name = "Habitat_Mater" }, new ListMembershipsComponent { Memberships = new List <string> { CommerceEntity.ListName <SellableItem>() } }, new ItemVariationsComponent { ChildComponents = new List <Component> { new ItemVariationComponent { Id = "56042178", Name = "Mira 15.6 Laptop—4GB Memory, 500GB Hard Drive", Policies = new List <Policy> { new ListPricingPolicy(new List <Money> { new Money("USD", 289.00M), new Money("CAD", 290.00M) }) }, ChildComponents = new List <Component> { new PhysicalItemComponent() } } } } }, Policies = new List <Policy> { new ListPricingPolicy(new List <Money> { new Money("USD", 289.00M), new Money("CAD", 290.00M) }) }, Id = $"{CommerceEntity.IdPrefix<SellableItem>()}6042178", Name = "Mira 15.6 Laptop—4GB Memory, 500GB Hard Drive" }; await this._persistEntityPipeline.Run(new PersistEntityArgument(item), context); }
/// <summary> /// Bootstraps the cameras. /// </summary> /// <param name="context">The context.</param> /// <returns>a <see cref="Task"/></returns> private async Task BootstrapCameras(CommercePipelineExecutionContext context) { var item = new SellableItem { Components = new List <Component> { new CatalogComponent { Name = "Habitat_Mater" }, new ListMembershipsComponent { Memberships = new List <string> { CommerceEntity.ListName <SellableItem>() } }, new ItemVariationsComponent { ChildComponents = new List <Component> { new ItemVariationComponent { Id = "57042124", Name = "Optix HD Mini Action Camcorder with Remote (White)", Policies = new List <Policy> { new ListPricingPolicy(new List <Money> { new Money("USD", 189.99M), new Money("CAD", 190.99M) }) }, ChildComponents = new List <Component> { new PhysicalItemComponent() } }, new ItemVariationComponent { Id = "57042125", Name = "Optix HD Mini Action Camcorder with Remote (Orange)", Policies = new List <Policy> { new ListPricingPolicy(new List <Money> { new Money("USD", 189.99M), new Money("CAD", 190.99M) }) }, ChildComponents = new List <Component> { new PhysicalItemComponent() } } } } }, Policies = new List <Policy> { new ListPricingPolicy(new List <Money> { new Money("USD", 117.79M), new Money("CAD", 118.79M) }) }, Id = $"{CommerceEntity.IdPrefix<SellableItem>()}7042124", Name = "Optix HD Mini Action Camcorder with Remote" }; await this._persistEntityPipeline.Run(new PersistEntityArgument(item), context); }
/// <summary> /// Bootstraps the appliances. /// </summary> /// <param name="context">The context.</param> /// <returns>A <see cref="Task"/></returns> private async Task BootstrapAppliances(CommercePipelineExecutionContext context) { var item = new SellableItem { Components = new List <Component> { new CatalogComponent { Name = "Habitat_Mater" }, new ListMembershipsComponent { Memberships = new List <string> { CommerceEntity.ListName <SellableItem>() } }, new ItemVariationsComponent { ChildComponents = new List <Component> { new ItemVariationComponent { Id = "56042591", Name = "Habitat Viva 4-Door 34.0 Cubic Foot Refrigerator w/ Ice Maker and Wifi (Stainless)", Policies = new List <Policy> { new ListPricingPolicy(new List <Money> { new Money("USD", 3029.99M), new Money("CAD", 3030.99M) }) }, ChildComponents = new List <Component> { new PhysicalItemComponent() } }, new ItemVariationComponent { Id = "56042592", Name = "Habitat Viva 4-Door 34.0 Cubic Foot Refrigerator w/ Ice Maker and Wifi (Black)", Policies = new List <Policy> { new ListPricingPolicy(new List <Money> { new Money("USD", 3029.99M), new Money("CAD", 3030.99M) }) }, ChildComponents = new List <Component> { new PhysicalItemComponent() } }, new ItemVariationComponent { Id = "56042593", Name = "Habitat Viva 4-Door 34.0 Cubic Foot Refrigerator w/ Ice Maker and Wifi (White)", Policies = new List <Policy> { new ListPricingPolicy(new List <Money> { new Money("USD", 3029.99M), new Money("CAD", 3030.99M) }) }, ChildComponents = new List <Component> { new PhysicalItemComponent() } } } } }, Policies = new List <Policy> { new ListPricingPolicy(new List <Money> { new Money("USD", 2302.79M), new Money("CAD", 2303.79M) }) }, Id = $"{CommerceEntity.IdPrefix<SellableItem>()}6042591", Name = "Habitat Viva 4-Door 34.0 Cubic Foot Refrigerator with Ice Maker and Wifi" }; await this._persistEntityPipeline.Run(new PersistEntityArgument(item), context); }
public TrackingFieldArgument(SellableItem sellableItem, string parentCategoryName, Tracking trackingField) { SellableItem = sellableItem; ParentCategoryName = parentCategoryName; TrackingField = trackingField; }
private async Task CreateExampleBundles(CommercePipelineExecutionContext context) { // First bundle SellableItem bundle1 = await _commerceCommander.Command <CreateBundleCommand>().Process( context.CommerceContext, "Static", "6001001", "SmartWiFiBundle", "Smart WiFi Bundle", string.Empty, string.Empty, string.Empty, string.Empty, new[] { "smart", "wifi", "bundle" }, new List <BundleItem> { new BundleItem { SellableItemId = "Entity-SellableItem-6042964|56042964", Quantity = 1 }, new BundleItem { SellableItemId = "Entity-SellableItem-6042971|56042971", Quantity = 1 } }).ConfigureAwait(false); // Set image and list price for bundle bundle1.GetComponent <ImagesComponent>().Images.Add("65703328-1456-48da-a693-bad910d7d1fe"); bundle1.SetPolicy( new ListPricingPolicy( new List <Money> { new Money("USD", 200.00M), new Money("CAD", 250.00M) })); await _commerceCommander.Pipeline <IPersistEntityPipeline>() .Run(new PersistEntityArgument(bundle1), context).ConfigureAwait(false); // Associate bundle to parent category await _commerceCommander.Command <AssociateSellableItemToParentCommand>().Process( context.CommerceContext, "Entity-Catalog-Habitat_Master", "Entity-Category-Habitat_Master-Connected home", bundle1.Id).ConfigureAwait(false); // Second bundle SellableItem bundle2 = await _commerceCommander.Command <CreateBundleCommand>().Process( context.CommerceContext, "Static", "6001002", "ActivityTrackerCameraBundle", "Activity Tracker & Camera Bundle", "Sample bundle containting two activity trackers and two cameras.", "Striva Wearables", string.Empty, string.Empty, new[] { "activitytracker", "camera", "bundle" }, new List <BundleItem> { new BundleItem { SellableItemId = "Entity-SellableItem-6042896|56042896", Quantity = 2 }, new BundleItem { SellableItemId = "Entity-SellableItem-7042066|57042066", Quantity = 2 } }).ConfigureAwait(false); // Set image and list price for bundle bundle2.GetComponent <ImagesComponent>().Images.Add("003c9ee5-2d97-4a6c-bb9e-24e110cd7645"); bundle2.SetPolicy( new ListPricingPolicy( new List <Money> { new Money("USD", 220.00M), new Money("CAD", 280.00M) })); await _commerceCommander.Pipeline <IPersistEntityPipeline>() .Run(new PersistEntityArgument(bundle2), context).ConfigureAwait(false); // Associate bundle to parent category await _commerceCommander.Command <AssociateSellableItemToParentCommand>().Process( context.CommerceContext, "Entity-Catalog-Habitat_Master", "Entity-Category-Habitat_Master-Fitness Activity Trackers", bundle2.Id).ConfigureAwait(false); // Third bundle SellableItem bundle3 = await _commerceCommander.Command <CreateBundleCommand>().Process( context.CommerceContext, "Static", "6001003", "RefrigeratorFlipPhoneBundle", "Refrigerator & Flip Phone Bundle", "Sample bundle containting a refrigerator and two flip phones.", "Viva Refrigerators", string.Empty, string.Empty, new[] { "refrigerator", "flipphone", "bundle" }, new List <BundleItem> { new BundleItem { SellableItemId = "Entity-SellableItem-6042567|56042568", Quantity = 1 }, new BundleItem { SellableItemId = "Entity-SellableItem-6042331|56042331", Quantity = 2 }, new BundleItem { SellableItemId = "Entity-SellableItem-6042896|56042896", Quantity = 3 }, new BundleItem { SellableItemId = "Entity-SellableItem-7042066|57042066", Quantity = 4 } }).ConfigureAwait(false); // Set image and list price for bundle bundle3.GetComponent <ImagesComponent>().Images.Add("372d8bc6-6888-4375-91c1-f3bee2d31558"); bundle3.SetPolicy( new ListPricingPolicy( new List <Money> { new Money("USD", 10.00M), new Money("CAD", 20.00M) })); await _commerceCommander.Pipeline <IPersistEntityPipeline>() .Run(new PersistEntityArgument(bundle3), context).ConfigureAwait(false); // Associate bundle to parent category await _commerceCommander.Command <AssociateSellableItemToParentCommand>().Process( context.CommerceContext, "Entity-Catalog-Habitat_Master", "Entity-Category-Habitat_Master-Appliances", bundle3.Id).ConfigureAwait(false); // Fourth bundle with digital items SellableItem bundle4 = await _commerceCommander.Command <CreateBundleCommand>().Process( context.CommerceContext, "Static", "6001004", "GiftCardAndSubscriptionBundle", "Gift Card & Subscription Bundle", "Sample bundle containting a gift card and two subscriptions.", string.Empty, string.Empty, string.Empty, new[] { "bundle", "giftcard", "entitlement" }, new List <BundleItem> { new BundleItem { SellableItemId = "Entity-SellableItem-6042986|56042987", Quantity = 1 }, new BundleItem { SellableItemId = "Entity-SellableItem-6042453|56042453", Quantity = 2 } }).ConfigureAwait(false); // Set image and list price for bundle bundle4.GetComponent <ImagesComponent>().Images.Add("7b57e6e0-a4ef-417e-809c-572f2e30aef7"); bundle4.SetPolicy( new ListPricingPolicy( new List <Money> { new Money("USD", 10.00M), new Money("CAD", 20.00M) })); await _commerceCommander.Pipeline <IPersistEntityPipeline>() .Run(new PersistEntityArgument(bundle4), context).ConfigureAwait(false); // Associate bundle to parent category await _commerceCommander.Command <AssociateSellableItemToParentCommand>().Process( context.CommerceContext, "Entity-Catalog-Habitat_Master", "Entity-Category-Habitat_Master-eGift Cards and Gift Wrapping", bundle4.Id).ConfigureAwait(false); // Preorderable bundle SellableItem bundle5 = await _commerceCommander.Command <CreateBundleCommand>().Process( context.CommerceContext, "Static", "6001005", "PreorderableBundle", "Preorderable Bundle", "Sample bundle containting a phone and headphones.", string.Empty, string.Empty, string.Empty, new[] { "bundle" }, new List <BundleItem> { new BundleItem { SellableItemId = "Entity-SellableItem-6042305|56042305", Quantity = 1 }, new BundleItem { SellableItemId = "Entity-SellableItem-6042059|56042059", Quantity = 1 } }).ConfigureAwait(false); // Set image and list price for bundle bundle5.GetComponent <ImagesComponent>().Images.Add("b0b07d7b-ddaf-4798-8eb9-af7f570af3fe"); bundle5.SetPolicy( new ListPricingPolicy( new List <Money> { new Money("USD", 44.99M), new Money("CAD", 59.99M) })); await _commerceCommander.Pipeline <IPersistEntityPipeline>() .Run(new PersistEntityArgument(bundle5), context).ConfigureAwait(false); // Associate bundle to parent category await _commerceCommander.Command <AssociateSellableItemToParentCommand>().Process( context.CommerceContext, "Entity-Catalog-Habitat_Master", "Entity-Category-Habitat_Master-Phones", bundle5.Id).ConfigureAwait(false); // Backorderable bundle SellableItem bundle6 = await _commerceCommander.Command <CreateBundleCommand>().Process( context.CommerceContext, "Static", "6001006", "BackorderableBundle", "Backorderable Bundle", "Sample bundle containting a phone and headphones.", string.Empty, string.Empty, string.Empty, new[] { "bundle" }, new List <BundleItem> { new BundleItem { SellableItemId = "Entity-SellableItem-6042305|56042305", Quantity = 1 }, new BundleItem { SellableItemId = "Entity-SellableItem-6042058|56042058", Quantity = 1 } }).ConfigureAwait(false); // Set image and list price for bundle bundle6.GetComponent <ImagesComponent>().Images.Add("b0b07d7b-ddaf-4798-8eb9-af7f570af3fe"); bundle6.SetPolicy( new ListPricingPolicy( new List <Money> { new Money("USD", 44.99M), new Money("CAD", 59.99M) })); await _commerceCommander.Pipeline <IPersistEntityPipeline>() .Run(new PersistEntityArgument(bundle6), context).ConfigureAwait(false); // Associate bundle to parent category await _commerceCommander.Command <AssociateSellableItemToParentCommand>().Process( context.CommerceContext, "Entity-Catalog-Habitat_Master", "Entity-Category-Habitat_Master-Phones", bundle6.Id).ConfigureAwait(false); // Backorderable bundle SellableItem bundle7 = await _commerceCommander.Command <CreateBundleCommand>().Process( context.CommerceContext, "Static", "6001007", "PreorderableBackorderableBundle", "Preorderable / Backorderable Bundle", "Sample bundle containting headphones.", string.Empty, string.Empty, string.Empty, new[] { "bundle" }, new List <BundleItem> { new BundleItem { SellableItemId = "Entity-SellableItem-6042058|56042058", Quantity = 1 }, new BundleItem { SellableItemId = "Entity-SellableItem-6042059|56042059", Quantity = 1 } }).ConfigureAwait(false); // Set image and list price for bundle bundle7.GetComponent <ImagesComponent>().Images.Add("b0b07d7b-ddaf-4798-8eb9-af7f570af3fe"); bundle7.SetPolicy( new ListPricingPolicy( new List <Money> { new Money("USD", 44.99M), new Money("CAD", 59.99M) })); await _commerceCommander.Pipeline <IPersistEntityPipeline>() .Run(new PersistEntityArgument(bundle7), context).ConfigureAwait(false); // Associate bundle to parent category await _commerceCommander.Command <AssociateSellableItemToParentCommand>().Process( context.CommerceContext, "Entity-Catalog-Habitat_Master", "Entity-Category-Habitat_Master-Audio", bundle7.Id).ConfigureAwait(false); // Eigth bundle with a gift card only SellableItem bundle8 = await _commerceCommander.Command <CreateBundleCommand>().Process( context.CommerceContext, "Static", "6001008", "GiftCardBundle", "Gift Card Bundle", "Sample bundle containting a gift card.", string.Empty, string.Empty, string.Empty, new[] { "bundle", "entitlement", "giftcard" }, new List <BundleItem> { new BundleItem { SellableItemId = "Entity-SellableItem-6042986|56042987", Quantity = 1 } }).ConfigureAwait(false); // Set image and list price for bundle bundle8.GetComponent <ImagesComponent>().Images.Add("7b57e6e0-a4ef-417e-809c-572f2e30aef7"); bundle8.SetPolicy( new ListPricingPolicy( new List <Money> { new Money("USD", 40.00M), new Money("CAD", 50.00M) })); await _commerceCommander.Pipeline <IPersistEntityPipeline>() .Run(new PersistEntityArgument(bundle8), context).ConfigureAwait(false); // Associate bundle to parent category await _commerceCommander.Command <AssociateSellableItemToParentCommand>().Process( context.CommerceContext, "Entity-Catalog-Habitat_Master", "Entity-Category-Habitat_Master-eGift Cards and Gift Wrapping", bundle8.Id).ConfigureAwait(false); // Warranty bundle SellableItem bundle9 = await _commerceCommander.Command <CreateBundleCommand>().Process( context.CommerceContext, "Static", "6001009", "WarrantyBundle", "Warranty Bundle", "Sample bundle containting a warranty.", string.Empty, string.Empty, string.Empty, new[] { "bundle", "warranty" }, new List <BundleItem> { new BundleItem { SellableItemId = "Entity-SellableItem-7042259|57042259", Quantity = 1 } }).ConfigureAwait(false); // Set image and list price for bundle bundle9.GetComponent <ImagesComponent>().Images.Add("eebf49f2-74df-4fe6-b77f-f2d1d447827c"); bundle9.SetPolicy( new ListPricingPolicy( new List <Money> { new Money("USD", 150.00M), new Money("CAD", 200.00M) })); await _commerceCommander.Pipeline <IPersistEntityPipeline>() .Run(new PersistEntityArgument(bundle9), context).ConfigureAwait(false); // Associate bundle to parent category await _commerceCommander.Command <AssociateSellableItemToParentCommand>().Process( context.CommerceContext, "Entity-Catalog-Habitat_Master", "Entity-Category-Habitat_Master-eGift Cards and Gift Wrapping", bundle9.Id).ConfigureAwait(false); // Service bundle SellableItem bundle10 = await _commerceCommander.Command <CreateBundleCommand>().Process( context.CommerceContext, "Static", "6001010", "ServiceBundle", "Service Bundle", "Sample bundle containting a service.", string.Empty, string.Empty, string.Empty, new[] { "bundle", "service" }, new List <BundleItem> { new BundleItem { SellableItemId = "Entity-SellableItem-6042418|56042418", Quantity = 1 } }).ConfigureAwait(false); // Set image and list price for bundle bundle10.GetComponent <ImagesComponent>().Images.Add("8b59fe2a-c234-4f92-b84b-7515411bf46e"); bundle10.SetPolicy( new ListPricingPolicy( new List <Money> { new Money("USD", 150.00M), new Money("CAD", 200.00M) })); await _commerceCommander.Pipeline <IPersistEntityPipeline>() .Run(new PersistEntityArgument(bundle10), context).ConfigureAwait(false); // Associate bundle to parent category await _commerceCommander.Command <AssociateSellableItemToParentCommand>().Process( context.CommerceContext, "Entity-Catalog-Habitat_Master", "Entity-Category-Habitat_Master-eGift Cards and Gift Wrapping", bundle10.Id).ConfigureAwait(false); // Subscription bundle SellableItem bundle11 = await _commerceCommander.Command <CreateBundleCommand>().Process( context.CommerceContext, "Static", "6001011", "SubscriptionBundle", "Subscription Bundle", "Sample bundle containting a subscription.", string.Empty, string.Empty, string.Empty, new[] { "bundle", "subscription" }, new List <BundleItem> { new BundleItem { SellableItemId = "Entity-SellableItem-6042453|56042453", Quantity = 1 } }).ConfigureAwait(false); // Set image and list price for bundle bundle11.GetComponent <ImagesComponent>().Images.Add("22d74215-8e5f-4de3-a9d6-ece3042bd64c"); bundle11.SetPolicy( new ListPricingPolicy( new List <Money> { new Money("USD", 10.00M), new Money("CAD", 15.00M) })); await _commerceCommander.Pipeline <IPersistEntityPipeline>() .Run(new PersistEntityArgument(bundle11), context).ConfigureAwait(false); // Associate bundle to parent category await _commerceCommander.Command <AssociateSellableItemToParentCommand>().Process( context.CommerceContext, "Entity-Catalog-Habitat_Master", "Entity-Category-Habitat_Master-eGift Cards and Gift Wrapping", bundle11.Id).ConfigureAwait(false); }
/// <summary> /// The run. /// </summary> /// <param name="arg"> /// The argument. /// </param> /// <param name="context"> /// The context. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public override async Task <string> Run(string arg, CommercePipelineExecutionContext context) { var artifactSet = "Environment.Habitat.SellableItems-1.0"; // Check if this environment has subscribed to this Artifact Set if (!context.GetPolicy <EnvironmentInitializationPolicy>() .InitialArtifactSets.Contains(artifactSet)) { return(arg); } context.Logger.LogInformation($"{this.Name}.InitializingArtifactSet: ArtifactSet={artifactSet}"); // DEFAULT SUBSCRIPTION SELLABLE ITEM TEMPLATE var itemId = $"{CommerceEntity.IdPrefix<SellableItem>()}Subscription"; var findResult = await this._findEntityPipeline.Run(new FindEntityArgument(typeof(SellableItem), itemId, false), context.CommerceContext.GetPipelineContextOptions()); if (findResult == null) { var subscriptionSellableItem = new SellableItem { Id = itemId, Name = "Default Subscription", Policies = new List <Policy> { new AvailabilityAlwaysPolicy() }, Components = new List <Component> { new ListMembershipsComponent { Memberships = new List <string> { CommerceEntity.ListName <SellableItem>() } } } }; await this._persistEntityPipeline.Run(new PersistEntityArgument(subscriptionSellableItem), context); } // DEFAULT INSTALLATION SELLABLE ITEM TEMPLATE itemId = $"{CommerceEntity.IdPrefix<SellableItem>()}Installation"; findResult = await this._findEntityPipeline.Run(new FindEntityArgument(typeof(SellableItem), itemId, false), context.CommerceContext.GetPipelineContextOptions()); if (findResult == null) { var installationSellableItem = new SellableItem { Id = itemId, Name = "Default Installation", Policies = new List <Policy> { new AvailabilityAlwaysPolicy() }, Components = new List <Component> { new ListMembershipsComponent { Memberships = new List <string> { CommerceEntity.ListName <SellableItem>() } } } }; await this._persistEntityPipeline.Run(new PersistEntityArgument(installationSellableItem), context); } // DEFAULT WARRANTY SELLABLE ITEM TEMPLATE itemId = $"{CommerceEntity.IdPrefix<SellableItem>()}Warranty"; findResult = await this._findEntityPipeline.Run(new FindEntityArgument(typeof(SellableItem), itemId, false), context.CommerceContext.GetPipelineContextOptions()); if (findResult == null) { var warrantySellableItem = new SellableItem { Id = itemId, Name = "Default Warranty", Policies = new List <Policy> { new AvailabilityAlwaysPolicy() }, Components = new List <Component> { new ListMembershipsComponent { Memberships = new List <string> { CommerceEntity.ListName <SellableItem>() } } } }; await this._persistEntityPipeline.Run(new PersistEntityArgument(warrantySellableItem), context); } return(arg); }
protected async virtual Task AddSiteReadyStatusProperties(EntityView siteReadyStatusView, string catalogName, SellableItem sellableItem, string variantId, CommercePipelineExecutionContext context) { var catalog = await Commander.Command <GetCatalogCommand>().Process(context.CommerceContext, catalogName).ConfigureAwait(false); var priceBookName = catalog?.PriceBookName; var inventorySetName = catalog?.DefaultInventorySetName; var publishStatus = GetPublishedStatus(sellableItem); var enabledStatus = GetEnabledStatus(sellableItem, variantId); var pricingStatus = GetPricingStatus(sellableItem, variantId); var inventoryStatus = await GetInventoryStatus(inventorySetName, sellableItem, variantId, context).ConfigureAwait(false); var inventoryAvailability = ToInventoryAvailability(inventoryStatus); var complete = publishStatus && enabledStatus && pricingStatus && inventoryAvailability; var icon = sellableItem.IsBundle ? "question" : complete ? "check" : "delete"; var view = new EntityView { Name = "Catalog Item Status", Icon = icon }; view.Properties.Add(new ViewProperty() { Name = "Catalog", Value = catalogName }); view.Properties.Add(new ViewProperty() { Name = "Published Status", RawValue = publishStatus }); view.Properties.Add(new ViewProperty() { Name = "Enabled Status", RawValue = sellableItem.IsBundle ? "Not Implemented" : enabledStatus.ToString().ToLower() }); view.Properties.Add(new ViewProperty() { Name = "Price Status", RawValue = pricingStatus }); view.Properties.Add(new ViewProperty() { Name = "Default Currency", RawValue = context.CommerceContext.CurrentCurrency() }); view.Properties.Add(new ViewProperty() { Name = "Price Book Name", RawValue = priceBookName }); view.Properties.Add(new ViewProperty() { Name = "Inventory Availability", RawValue = sellableItem.IsBundle ? "Not Implemented" : inventoryAvailability.ToString().ToLower() }); view.Properties.Add(new ViewProperty() { Name = "Inventory Set Name", RawValue = inventorySetName }); siteReadyStatusView.ChildViews.Add(view); }
private void CopyImages(SellableItem itemNewData, SellableItem item) { item.RemoveComponent(typeof(ImagesComponent)); item.Components.Add(itemNewData.GetComponent <ImagesComponent>()); }
protected async virtual Task AddInventoryStatusProperties(EntityView inventoryStatusView, string catalogName, SellableItem sellableItem, string variantId, CommercePipelineExecutionContext context) { var catalog = await Commander.Command <GetCatalogCommand>().Process(context.CommerceContext, catalogName).ConfigureAwait(false); var inventorySetName = catalog?.DefaultInventorySetName; if (catalog == null || string.IsNullOrWhiteSpace(catalog.DefaultInventorySetName)) { return; } var inventoryStatus = await GetInventoryStatus(inventorySetName, sellableItem, variantId, context).ConfigureAwait(false); var icon = sellableItem.IsBundle ? "question" : inventoryStatus != Engine.CatalogConstants.InventoryStatus.NotAvailable && inventoryStatus != Engine.CatalogConstants.InventoryStatus.OutOfStock ? "check" : "delete"; var view = new EntityView { Name = "Catalog Item Status", Icon = icon }; view.Properties.Add(new ViewProperty() { Name = "Inventory Set Name", Value = inventorySetName }); view.Properties.Add(new ViewProperty() { Name = "Inventory Status", RawValue = inventoryStatus }); inventoryStatusView.ChildViews.Add(view); }
private async Task CopyCategory(CommerceContext commerceContext, IEnumerable <CatalogContextModel> catalogContextList, SellableItem itemNewData, SellableItem item) { var existingCategoryList = string.IsNullOrEmpty(item.ParentCategoryList) ? new string[0] : item.ParentCategoryList.Split('|'); var newCategoryList = string.IsNullOrEmpty(itemNewData.ParentCategoryList) ? new string[0] : itemNewData.ParentCategoryList.Split('|'); var associationsToCreate = newCategoryList.Except(existingCategoryList).ToList(); var associationsToRemove = existingCategoryList.Except(newCategoryList).ToList(); CopyCategoryAddressAdded(commerceContext, item, associationsToCreate); await CopyCategoryAddressRemoved(commerceContext, item, associationsToRemove); item.ParentCategoryList = itemNewData.ParentCategoryList; }
protected virtual bool GetPublishedStatus(SellableItem sellableItem) { return(sellableItem.Published); }
private async Task CopyCategoryAddressRemoved(CommerceContext commerceContext, SellableItem existingItem, List <string> associationsToRemove) { if (associationsToRemove == null || associationsToRemove.Count().Equals(0)) { return; } var transientData = existingItem.GetPolicy <TransientImportSellableItemDataPolicy>(); var allCatalogs = commerceContext.GetObject <IEnumerable <Sitecore.Commerce.Plugin.Catalog.Catalog> >(); if (allCatalogs == null) { allCatalogs = await Command <GetCatalogsCommand>().Process(commerceContext); commerceContext.AddObject(allCatalogs); } var existingCatalogSitecoreIdList = existingItem.ParentCatalogList.Split('|'); var catalogNameList = new List <string>(); foreach (var catalogSitecoreId in existingCatalogSitecoreIdList) { var catalog = allCatalogs.FirstOrDefault(c => c.SitecoreId.Equals(catalogSitecoreId)); catalogNameList.Add(catalog.Name); } var catalogContextList = await Command <GetCatalogContextCommand>().Process(commerceContext, catalogNameList); foreach (var categoryToRemoveSitecoreId in associationsToRemove) { bool found = false; foreach (var catalogContext in catalogContextList) { catalogContext.CategoriesBySitecoreId.TryGetValue(categoryToRemoveSitecoreId, out Category category); if (category != null) { transientData.ParentAssociationsToRemoveList.Add(new CatalogItemParentAssociationModel(existingItem.Id, catalogContext.Catalog.Id, category)); found = true; break; } } if (!found) { commerceContext.Logger.LogWarning($"Unable to find category with SitecoreId {categoryToRemoveSitecoreId}. We need to disacciate it from SellableItem {existingItem.Id}"); } } }
protected async virtual Task <string> GetInventoryStatus(string inventorySetName, SellableItem sellableItem, string variantId, CommercePipelineExecutionContext context) { if (sellableItem.IsBundle) { // TODO: Implement support for bundle return("Not Supported"); } if (sellableItem.HasPolicy <AvailabilityAlwaysPolicy>()) { return(Engine.CatalogConstants.InventoryStatus.Perpetual); } if (string.IsNullOrWhiteSpace(variantId) && !string.IsNullOrWhiteSpace(inventorySetName)) { var inventoryInformation = await Commander.Command <GetInventoryInformationCommand>().Process(context.CommerceContext, inventorySetName, sellableItem.ProductId).ConfigureAwait(false); if (inventoryInformation != null) { return(this.ToInventoryStatus(inventoryInformation)); } } if (string.IsNullOrWhiteSpace(variantId)) { var variants = sellableItem.GetComponent <ItemVariationsComponent>().GetComponents <ItemVariationComponent>(); var allNotAvailable = true; foreach (var variant in variants) { var status = await GetVariantInventoryStatus(variant, inventorySetName, context).ConfigureAwait(false); allNotAvailable &= status.Equals(Engine.CatalogConstants.InventoryStatus.NotAvailable, StringComparison.InvariantCultureIgnoreCase); if (status.Equals(Engine.CatalogConstants.InventoryStatus.NotAvailable, StringComparison.InvariantCultureIgnoreCase) || status.Equals(Engine.CatalogConstants.InventoryStatus.OutOfStock, StringComparison.InvariantCultureIgnoreCase)) { continue; } return(status); } return(allNotAvailable ? Engine.CatalogConstants.InventoryStatus.NotAvailable : Engine.CatalogConstants.InventoryStatus.OutOfStock); } else { var variant = sellableItem.GetVariation(variantId); return(await GetVariantInventoryStatus(variant, inventorySetName, context).ConfigureAwait(false)); } }
private void AddSellableItemPricing(EntityView entityView, SellableItem entity, ItemVariationComponent variation, CommercePipelineExecutionContext context) { var policy = context.GetPolicy <KnownCatalogViewsPolicy>(); var entityView1 = new EntityView { Name = policy.SellableItemPricing, EntityId = entityView.EntityId, EntityVersion = entityView.EntityVersion, ItemId = variation != null ? variation.Id : string.Empty, UiHint = "Flat" }; var entityView2 = entityView1; var entityView3 = new EntityView { Name = policy.SellableItemListPricing, EntityId = entityView.EntityId, EntityVersion = entityView.EntityVersion, ItemId = variation != null ? variation.Id : string.Empty, UiHint = "Table" }; var entityView4 = entityView3; if (entity != null) { var str = variation != null?variation.GetPolicy <PriceCardPolicy>().PriceCardName : entity.GetPolicy <PriceCardPolicy>().PriceCardName; var properties1 = entityView2.Properties; var viewProperty1 = new ViewProperty { Name = "PriceCardName", RawValue = str ?? string.Empty, IsReadOnly = true, IsRequired = false, IsHidden = false }; properties1.Add(viewProperty1); foreach (var price in (variation != null ? variation.GetPolicy <ListPricingPolicy>() : entity.GetPolicy <ListPricingPolicy>()).Prices) { var entityView5 = new EntityView { Name = context.GetPolicy <KnownCatalogViewsPolicy>().Summary, EntityId = entityView.EntityId, ItemId = (variation != null ? variation.Id : string.Empty) + "|" + price.CurrencyCode, UiHint = "Flat" }; var entityView6 = entityView5; var properties2 = entityView6.Properties; var viewProperty2 = new ViewProperty { Name = "Currency", RawValue = price.CurrencyCode }; properties2.Add(viewProperty2); var properties3 = entityView6.Properties; var viewProperty3 = new ViewProperty { Name = "ListPrice", RawValue = price.Amount }; properties3.Add(viewProperty3); entityView4.ChildViews.Add(entityView6); } } entityView2.ChildViews.Add(entityView4); entityView.ChildViews.Add(entityView2); }
private static async Task GetProductId(CommercePipelineExecutionContext context, GetProductsToUpdateInventoryBlock getProductsToUpdateInventoryBlock, string catalogSitecoreId, List <string> productIds, SellableItem item) { if (item.ParentCatalogList == catalogSitecoreId) { CommerceEntity entity = await getProductsToUpdateInventoryBlock._findEntityPipeline.Run(new FindEntityArgument(typeof(SellableItem), item.Id, false), context); if ((entity is SellableItem)) { SellableItem sellableItem = entity as SellableItem; var variants = sellableItem.GetComponent <ItemVariationsComponent>(); if (variants != null && variants.ChildComponents.Count > 0) { foreach (ItemVariationComponent variant in variants.ChildComponents) { var variantData = variant; productIds.Add($"{item.Id}|{variantData.Id}"); } } else { productIds.Add($"{item.Id}"); } } } }
public async Task <ItemType> PrepareItem(CommerceContext commerceContext, SellableItem sellableItem) { using (var activity = CommandActivity.Start(commerceContext, this)) { //Instantiate the call wrapper class var apiCall = new AddFixedPriceItemCall(await GetEbayContext(commerceContext).ConfigureAwait(false)); var item = await this._commerceCommander.Pipeline <IPrepareEbayItemPipeline>().Run(sellableItem, commerceContext.PipelineContextOptions).ConfigureAwait(false); item.Description = sellableItem.Description; item.Title = sellableItem.DisplayName; item.SubTitle = "Test Item"; var listPricingPolicy = sellableItem.GetPolicy <ListPricingPolicy>(); var listPrice = listPricingPolicy.Prices.FirstOrDefault(); item.StartPrice = new AmountType { currencyID = CurrencyCodeType.USD, Value = System.Convert.ToDouble(listPrice.Amount, System.Globalization.CultureInfo.InvariantCulture) }; item.ConditionID = 1000; //new item.PaymentMethods = new BuyerPaymentMethodCodeTypeCollection(); item.PaymentMethods.Add(BuyerPaymentMethodCodeType.PayPal); item.PaymentMethods.Add(BuyerPaymentMethodCodeType.VisaMC); item.PayPalEmailAddress = "*****@*****.**"; item.PostalCode = "98014"; item.DispatchTimeMax = 3; item.ShippingDetails = new ShippingDetailsType(); item.ShippingDetails.ShippingServiceOptions = new ShippingServiceOptionsTypeCollection(); item.ShippingDetails.ShippingType = ShippingTypeCodeType.Flat; ShippingServiceOptionsType shipservice1 = new ShippingServiceOptionsType(); shipservice1.ShippingService = "USPSPriority"; shipservice1.ShippingServicePriority = 1; shipservice1.ShippingServiceCost = new AmountType(); shipservice1.ShippingServiceCost.currencyID = CurrencyCodeType.USD; shipservice1.ShippingServiceCost.Value = 5.0; shipservice1.ShippingServiceAdditionalCost = new AmountType(); shipservice1.ShippingServiceAdditionalCost.currencyID = CurrencyCodeType.USD; shipservice1.ShippingServiceAdditionalCost.Value = 1.0; item.ShippingDetails.ShippingServiceOptions.Add(shipservice1); //ShippingServiceOptionsType shipservice2 = new ShippingServiceOptionsType(); //shipservice2.ShippingService = "US_Regular"; //shipservice2.ShippingServicePriority = 2; //shipservice2.ShippingServiceCost = new AmountType(); //shipservice2.ShippingServiceCost.currencyID = CurrencyCodeType.USD; //shipservice2.ShippingServiceCost.Value = 1.0; //shipservice2.ShippingServiceAdditionalCost = new AmountType(); //shipservice2.ShippingServiceAdditionalCost.currencyID = CurrencyCodeType.USD; //shipservice2.ShippingServiceAdditionalCost.Value = 1.0; //item.ShippingDetails.ShippingServiceOptions.Add(shipservice2); //item.Variations. item.ReturnPolicy = new ReturnPolicyType { ReturnsAcceptedOption = "ReturnsAccepted" }; //Add pictures item.PictureDetails = new PictureDetailsType(); //Specify GalleryType item.PictureDetails.GalleryType = GalleryTypeCodeType.None; item.PictureDetails.GalleryTypeSpecified = true; return(item); } }
public override async Task <bool> Run(SellableItemInventorySetsArgument argument, CommercePipelineExecutionContext context) { AssociateStoreInventoryToSellablteItemBlock associateStoreInventoryToSellablteItemBlock = this; Condition.Requires(argument).IsNotNull(string.Format("{0}: The argument can not be null", argument)); string sellableItemId = argument.SellableItemId; CommerceEntity entity = await associateStoreInventoryToSellablteItemBlock._findEntityPipeline.Run(new FindEntityArgument(typeof(SellableItem), sellableItemId, false), context).ConfigureAwait(false); CommercePipelineExecutionContext executionContext; if (!(entity is SellableItem)) { executionContext = context; CommerceContext commerceContext = context.CommerceContext; string validationError = context.GetPolicy <KnownResultCodes>().ValidationError; string commerceTermKey = "EntityNotFound"; object[] args = new object[1] { argument.SellableItemId }; string defaultMessage = string.Format("Entity {0} was not found.", argument.SellableItemId); executionContext.Abort(await commerceContext.AddMessage(validationError, commerceTermKey, args, defaultMessage).ConfigureAwait(false), context); executionContext = null; return(false); } SellableItem sellableItem = entity as SellableItem; if ((string.IsNullOrEmpty(argument.VariationId)) & sellableItem.HasComponent <ItemVariationsComponent>()) { executionContext = context; executionContext.Abort(await context.CommerceContext.AddMessage(context.GetPolicy <KnownResultCodes>().ValidationError, "AssociateInventoryWithVariant", new object[0], "Can not associate inventory to the base sellable item. Use one of the variants instead.").ConfigureAwait(false), context); executionContext = null; return(false); } ItemVariationComponent sellableItemVariation = null; if (argument.VariationId != null) { sellableItemVariation = sellableItem.GetVariation(argument.VariationId); if (!string.IsNullOrEmpty(argument.VariationId) && sellableItemVariation == null) { executionContext = context; CommerceContext commerceContext = context.CommerceContext; string validationError = context.GetPolicy <KnownResultCodes>().ValidationError; string commerceTermKey = "ItemNotFound"; object[] args = new object[1] { argument.VariationId }; string defaultMessage = string.Format("Item '{0}' was not found.", argument.VariationId); executionContext.Abort(await commerceContext.AddMessage(validationError, commerceTermKey, args, defaultMessage).ConfigureAwait(false), context); executionContext = null; return(false); } } List <InventoryAssociation> inventoryAssociations = new List <InventoryAssociation>(); foreach (var inventorySetId in argument.InventorySetIds) { bool isUpdate = false; Random rnd = new Random(); InventoryInformation inventoryInformation = await associateStoreInventoryToSellablteItemBlock._getInventoryInformationCommand .Process(context.CommerceContext, inventorySetId, argument.SellableItemId, argument.VariationId, false) .ConfigureAwait(false); IFindEntitiesInListPipeline entitiesInListPipeline = associateStoreInventoryToSellablteItemBlock._findEntitiesInListPipeline; FindEntitiesInListArgument entitiesInListArgument1 = new FindEntitiesInListArgument(typeof(SellableItem), string.Format("{0}-{1}", "InventorySetToInventoryInformation", inventorySetId.SimplifyEntityName()), 0, int.MaxValue); entitiesInListArgument1.LoadEntities = false; CommercePipelineExecutionContext context1 = context; FindEntitiesInListArgument entitiesInListArgument2 = await entitiesInListPipeline.Run(entitiesInListArgument1, context1).ConfigureAwait(false); if (inventoryInformation != null && entitiesInListArgument2 != null) { List <ListEntityReference> entityReferences = entitiesInListArgument2.EntityReferences.ToList(); string id = inventoryInformation.Id; if (entityReferences != null && entityReferences.Any(er => er.EntityId == id)) { inventoryInformation.Quantity = rnd.Next(50); isUpdate = true; } } if (!isUpdate) { string inventorySetName = string.Format("{0}-{1}", inventorySetId.SimplifyEntityName(), sellableItem.ProductId); if (!string.IsNullOrEmpty(argument.VariationId)) { inventorySetName += string.Format("-{0}", argument.VariationId); } InventoryInformation inventoryInformation1 = new InventoryInformation(); inventoryInformation1.Id = string.Format("{0}{1}", CommerceEntity.IdPrefix <InventoryInformation>(), inventorySetName); inventoryInformation1.FriendlyId = inventorySetName; EntityReference entityReference1 = new EntityReference(inventorySetId, ""); inventoryInformation1.InventorySet = entityReference1; EntityReference entityReference2 = new EntityReference(argument.SellableItemId, ""); inventoryInformation1.SellableItem = entityReference2; string variationId = argument.VariationId; inventoryInformation1.VariationId = variationId; inventoryInformation1.Quantity = rnd.Next(50); inventoryInformation = inventoryInformation1; } inventoryInformation.GetComponent <TransientListMembershipsComponent>().Memberships.Add(CommerceEntity.ListName <InventoryInformation>()); PersistEntityArgument persistEntityArgument1 = await associateStoreInventoryToSellablteItemBlock._persistEntityPipeline.Run(new PersistEntityArgument((CommerceEntity)inventoryInformation), context).ConfigureAwait(false); RelationshipArgument relationshipArgument = await associateStoreInventoryToSellablteItemBlock._createRelationshipPipeline.Run(new RelationshipArgument(inventorySetId, inventoryInformation.Id, "InventorySetToInventoryInformation"), context).ConfigureAwait(false); InventoryAssociation inventoryAssociation = new InventoryAssociation() { InventoryInformation = new EntityReference(inventoryInformation.Id, ""), InventorySet = new EntityReference(inventorySetId, "") }; inventoryAssociations.Add(inventoryAssociation); } (sellableItemVariation != null ? sellableItemVariation.GetComponent <InventoryComponent>() : sellableItem.GetComponent <InventoryComponent>()).InventoryAssociations.AddRange(inventoryAssociations); PersistEntityArgument persistEntityArgument2 = await associateStoreInventoryToSellablteItemBlock._persistEntityPipeline.Run(new PersistEntityArgument(sellableItem), context).ConfigureAwait(false); return(true); }
public async Task <ItemType> RelistItem(CommerceContext commerceContext, SellableItem sellableItem) { using (var activity = CommandActivity.Start(commerceContext, this)) { //Instantiate the call wrapper class var apiCall = new RelistItemCall(await GetEbayContext(commerceContext).ConfigureAwait(false)); if (sellableItem.HasComponent <EbayItemComponent>()) { var ebayItemComponent = sellableItem.GetComponent <EbayItemComponent>(); try { var item = await PrepareItem(commerceContext, sellableItem); item.ItemID = ebayItemComponent.EbayId; //item.ListingDuration = "Days_" + 10; //Send the call to eBay and get the results var feeResult = apiCall.RelistItem(item, new StringCollection()); ebayItemComponent.EbayId = item.ItemID; ebayItemComponent.Status = "Listed"; sellableItem.GetComponent <TransientListMembershipsComponent>().Memberships.Add("Ebay_Listed"); foreach (var feeItem in feeResult) { var fee = feeItem as FeeType; ebayItemComponent.Fees.Add(new AwardedAdjustment { Adjustment = new Money(fee.Fee.currencyID.ToString(), System.Convert.ToDecimal(fee.Fee.Value)), AdjustmentType = "Fee", Name = fee.Name }); } ebayItemComponent.History.Add(new HistoryEntryModel { EventMessage = "Listing Relisted", EventUser = commerceContext.CurrentCsrId() }); return(item); } catch (Exception ex) { if (ex.Message.Contains("It looks like this listing is for an item you already have on eBay")) { var existingId = ex.Message.Substring(ex.Message.IndexOf("(") + 1); existingId = existingId.Substring(0, existingId.IndexOf(")")); await commerceContext.AddMessage("Warn", "Ebay.RelistItem", new Object[] { }, $"ExistingId:{existingId}-ComponentId:{ebayItemComponent.EbayId}").ConfigureAwait(false); ebayItemComponent.EbayId = existingId; ebayItemComponent.Status = "Listed"; sellableItem.GetComponent <TransientListMembershipsComponent>().Memberships.Add("Ebay_Listed"); } else { commerceContext.Logger.LogError($"Ebay.RelistItem.Exception: Message={ex.Message}"); await commerceContext.AddMessage("Error", "Ebay.RelistItem.Exception", new Object[] { ex }, ex.Message).ConfigureAwait(false); } } } else { commerceContext.Logger.LogError($"EbayCommand.RelistItem.Exception: Message=ebayCommand.RelistItem.NoEbayItemComponent"); await commerceContext.AddMessage("Error", "Ebay.RelistItem.Exception", new Object[] { }, "ebayCommand.RelistItem.NoEbayItemComponent").ConfigureAwait(false); } return(new ItemType()); } }
public async Task <ItemType> PrepareItem(CommerceContext commerceContext, SellableItem sellableItem) { ShippingServiceOptionsType shipservice1 = new ShippingServiceOptionsType { ShippingService = "USPSPriority", ShippingServicePriority = 1, ShippingServiceCost = new AmountType { currencyID = CurrencyCodeType.USD, Value = 5.0 } }; using (CommandActivity.Start(commerceContext, this)) { var item = await this._commerceCommander.Pipeline <IPrepareEbayItemPipeline>().Run(sellableItem, commerceContext.GetPipelineContextOptions()); item.Description = sellableItem.Description; item.Title = sellableItem.DisplayName; item.SubTitle = "Test Item"; var listPricingPolicy = sellableItem.GetPolicy <ListPricingPolicy>(); var listPrice = listPricingPolicy.Prices.FirstOrDefault(); item.StartPrice = new AmountType { currencyID = CurrencyCodeType.USD, Value = System.Convert.ToDouble(listPrice.Amount) }; item.ConditionID = 1000; item.PaymentMethods = new BuyerPaymentMethodCodeTypeCollection { BuyerPaymentMethodCodeType.PayPal, BuyerPaymentMethodCodeType.VisaMC }; item.PayPalEmailAddress = "*****@*****.**"; item.PostalCode = "98014"; item.DispatchTimeMax = 3; item.ShippingDetails = new ShippingDetailsType { ShippingServiceOptions = new ShippingServiceOptionsTypeCollection(), ShippingType = ShippingTypeCodeType.Flat }; shipservice1.ShippingServiceAdditionalCost = new AmountType { currencyID = CurrencyCodeType.USD, Value = 1.0 }; item.ShippingDetails.ShippingServiceOptions.Add(shipservice1); item.ReturnPolicy = new ReturnPolicyType { ReturnsAcceptedOption = "ReturnsAccepted" }; // Add pictures item.PictureDetails = new PictureDetailsType { GalleryType = GalleryTypeCodeType.None, GalleryTypeSpecified = true }; return(item); } }