Setting tax category for an variant/sku programatically

I'm building a scheduled job which which creates variants/skus and I'm not sure how to set the tax category for each variant/sku.

Code as follows:

CatalogEntryDto entryDto = CatalogContext.Current.GetCatalogEntryDto(myEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

            if (entryDto.CatalogEntry.Count > 0)
            {
                CatalogEntryDto.VariationRow[] variationRows = entryDto.CatalogEntry[0].GetVariationRows();

                if (variationRows.Length > 0)
                {                                                                                                
                    CatalogTaxDto categories = CatalogTaxManager.GetTaxCategories();

                    if (categories.TaxCategory.Count > 0)
                    {                       
                        variationRows[0].TaxCategoryId = categories.TaxCategory[0].TaxCategoryId;
                    }                  
                }
            }

It goes through the code and sets the taxcategoryid, but it is not set when I go to that specific variant in Catalogue view. Do I need to save it somehow or set something more than the id? The documentation I find is for getting the values, not for setting, so something is missing here.

Help appreciated.

/J

#118566 Mar 10, 2015 11:01
  • Member since: 2011

    Hi,

    You need to call CatalogContext.Current.SaveCatalogEntry(catalogEntryDto) to save the changes.

    Regards.

    /Q

    #118573 Mar 10, 2015 11:57
  • Great thanks Quan!

    #118588 Mar 10, 2015 15:56
  • Hi,

    How do you set tax category  on packages? 


    regards

    Pawel

    #185109 Nov 09, 2017 15:13
  • Member since: 2011

    We suggest to use the new content APIs, and PackageContent implements IPricing, which has TaxCategoryId property that you can set. 

    #185248 Nov 13, 2017 15:24
  • Thanks!  will try it out! 

    #185254 Nov 13, 2017 16:21