Can you inspect sale price row in object "dto"? What is the status of the data row?
EPiServer Support solution (It worked for me):
Pricing has changed in R3 to use a pricing service instead (to better deal with markets). Try this code and see if it works better:
CatalogEntryDto.CatalogEntryRow dtoRow = CatalogContext.Current.GetCatalogEntryDto([ENTRYCODE]).CatalogEntry.FirstOrDefault();
CatalogKey ck = new CatalogKey(dtoRow);
PriceValue ipv = new PriceValue();
Currency currency = new Currency("SEK");
ipv.CatalogKey = ck;
ipv.CustomerPricing = CustomerPricing.AllCustomers;
ipv.MarketId = MarketId.Default.Value;
ipv.MinQuantity = 10;
ipv.UnitPrice = new Money(101, currency);
ipv.ValidFrom = DateTime.Now.AddDays(-1);
ipv.ValidUntil = DateTime.Now.AddYears(1);
List<PriceValue> list = new List<PriceValue>();
list.Add(ipv);
IPriceService priceService = ServiceLocator.Current.GetInstance<IPriceService>();
var p1 = priceService.GetCatalogEntryPrices(ck); // get all existing prices and add to the list
priceService.SetCatalogEntryPrices(new CatalogKey(dtoRow), list); // if done like this all previous prices are gone
Using: Commerce 1 R3a
Hi,
I'am creating an import module to import a catalog in the Commerce, all works well except for the sales price.
The save function doesn't throw an error, but it also doesn't store the salesprice.
dto.HasChanges() is true
After storing the dto, the id of the priceRow id = -1
No exception but also no stored pricerow
SQL profiler shows Update Inventory, Varation and CatalogEntry but no update or insert of the sales price.
Decompiled code doesen't seem to store SalesPrice after calling the method SaveCatalogEntry.
So the big question, how do i store the sales price?
//Helper method of my import module
private static CatalogEntryDto.CatalogEntryRow SetVariation(Product product, MetaDataContext metaDataContext, IEnumerable<string> languageCodes, int catalogId, int metaClassId, CatalogEntryDto dto)
{
//EntryRow
var entryRow = dto.CatalogEntry.Count == 0
? dto.CatalogEntry.NewCatalogEntryRow()
: dto.CatalogEntry[0];
SetVariationEntryRow(product, entryRow, catalogId, metaClassId);
if (entryRow.RowState == DataRowState.Detached)
dto.CatalogEntry.AddCatalogEntryRow(entryRow);
//InventoryRow
var inventoryRow = dto.Inventory.Count == 0
? dto.Inventory.NewInventoryRow()
: dto.Inventory[0];
SetInventoryRow(product, inventoryRow);
if (inventoryRow.RowState == DataRowState.Detached) dto.Inventory.AddInventoryRow(inventoryRow);
//VariationRow
var variationRow = dto.Variation.Count == 0
? dto.Variation.NewVariationRow()
: dto.Variation[0];
SetVariationRow(product, variationRow, entryRow.CatalogEntryId);
if (variationRow.RowState == DataRowState.Detached) dto.Variation.AddVariationRow(variationRow);
//PriceRow
var priceRow = dto.SalePrice.Count == 0
? dto.SalePrice.NewSalePriceRow()
: dto.SalePrice[0];
SetPriceRow(product, priceRow);
if (priceRow.RowState == DataRowState.Detached) dto.SalePrice.AddSalePriceRow(priceRow);
//All values are stored, except for the pricerow
//Save Variation Entry
CatalogContext.Current.SaveCatalogEntry(dto);
//NodeRelationRow
SaveNodeRelation(product, catalogId, entryRow.CatalogEntryId);
//Variation Meta data
SetVariationMetaData(product, metaDataContext, languageCodes, entryRow.CatalogEntryId, metaClassId);
return entryRow;
}
//Helper method of my import module
private static void SetPriceRow(Product product, CatalogEntryDto.SalePriceRow priceRow)
{
if (product == null) throw new ArgumentNullException("product");
if (priceRow == null) throw new ArgumentNullException("priceRow");
try
{
priceRow.SaleCode = "";
priceRow.Currency = "EUR";
priceRow.ItemCode = product.Id.ToString(CultureInfo.InvariantCulture);
priceRow.UnitPrice = product.Price;
priceRow.MinQuantity = 0;
priceRow.SaleType = 0;
priceRow.StartDate = DateTime.Now.ToUniversalTime();
priceRow.EndDate = DateTime.Now.AddYears(5).ToUniversalTime();
}
catch (Exception ex)
{
throw new ApplicationException(String.Format("Unable to set price row for product {0}.", product.Name), ex);
}
}
//Decompiled code of Mediachase library
internal void Save()
{
if (this.CurrentDto.CatalogEntry == null)
{
return;
}
if (this.CurrentDto.CatalogEntry.Count == 0)
{
return;
}
DataCommand cmd = CatalogDataHelper.CreateDataCommand();
using (TransactionScope transactionScope = new TransactionScope())
{
DataHelper.SaveDataSetSimple(CatalogContext.MetaDataContext, cmd, this.CurrentDto, new string[]
{
"CatalogEntry",
"CatalogItemSeo",
"CatalogItemAsset",
"Variation",
"Inventory",
"Merchant",
"CatalogAssociation"
});
transactionScope.Complete();
}
}