Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Actually it isn't showing any updateRelation method for linksRepository
Source and target is also missing from productvariation class("It has been replaced by parent and child attributes, I guess.").
That's true, Source and Target were obsoleted and replaced by Parent and Child. The code is heavily outdated, I will let Commerce team knows.
You should be using IRelationRepository instead of ILinksRepository.
Hello Quan,
i still can't use this code cause it still have some errors in this code.
Can you please give me a latest version of this code?
Which code is not working for you. Outside the IRelationRepository issue, I think only this code needs update (AppContext.Current.ApplicationId is no longer needed)
var priceDetailValue = new PriceDetailValue
{
CatalogKey = new CatalogKey(variation.Code),
MarketId = new MarketId("US"),
CustomerPricing = CustomerPricing.AllCustomers,
ValidFrom = DateTime.UtcNow,
UnitPrice = new Money(1m, Currency.USD)
};
priceDetailService.Save(priceDetailValue);
https://world.episerver.com/documentation/developer-guides/commerce/catalogs/Importing-catalog-data/
Some methods used in this code are not working(like:- _linksRepository.UpdateRelation)
private readonly IContentRepository contentRepository; private readonly ILinksRepository linksRepository; private readonly IInventoryService inventoryService; private readonly IPriceDetailService priceDetailService; private void AddEntry() { ContentReference parentCategoryLink; // Get a reference to the node you want to add the product to. // Add product var product = contentRepository.GetDefault<MyCustomProduct>(parentCategoryLink, CultureInfo.GetCultureInfo("en-US")); product.Name = "Product name"; product.Code = "123-456"; product.Publisher = "Episerver"; contentRepository.Save(product, SaveAction.Publish, AccessLevel.NoAccess); // Add variation var variation = contentRepository.GetDefault<MyCustomVariation>(parentCategoryLink, CultureInfo.GetCultureInfo("en-US")); variation.Name = "Variation name"; variation.Code = "654-321"; variation.Type = "Paperback"; variation.MaxQuantity = 50; contentRepository.Save(variation, SaveAction.Publish, AccessLevel.NoAccess); // Add relation between product and variant var newVariation = new ProductVariation { SortOrder = 1, Source = product.ContentLink, Target = variation.ContentLink }; linksRepository.UpdateRelation(newVariation); // Add inventory information var inventoryRecord = new InventoryRecord { CatalogEntryCode = variation.Code, PurchaseAvailableQuantity = 10, PurchaseAvailableUtc = DateTime.UtcNow, WarehouseCode = "default" }; inventoryService.Insert(new[] { inventoryRecord }); // Add price information var priceDetailValue = new PriceDetailValue { CatalogKey = new CatalogKey(AppContext.Current.ApplicationId, variation.Code), MarketId = new MarketId("US"), CustomerPricing = CustomerPricing.AllCustomers, ValidFrom = DateTime.UtcNow, UnitPrice = new Money(1m, Currency.USD) }; priceDetailService.Save(priceDetailValue); }