I was trying to import catalog data so i used this code provided by episerver but it isn't working.

Ash
Ash
Vote:
 

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);
  }
#217272
Feb 20, 2020 6:14
Vote:
 

Ash, what is not working? Are you getting error or something?

#217274
Feb 20, 2020 6:32
Ash
Vote:
 

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.").

#217277
Feb 20, 2020 6:56
Vote:
 

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.

#217279
Feb 20, 2020 7:59
Ash
Vote:
 

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?

#217520
Feb 25, 2020 5:17
Vote:
 

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);
#217523
Feb 25, 2020 7:59
Ash
Vote:
 

Hello Quan 

My code has successfully running on my machine but there is a problem in catalog manager, Products aren't visible to me.

#217664
Feb 27, 2020 6:21
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.