I'm importing a lot of products using the API, and everything seems to show up fine in the tree, but when I click on a product I get this error in the back-office:
[NullReferenceException: Object reference not set to an instance of an object.]
UCommerce.Presentation.Presenters.Catalog.EditProductPresenter.BindView() +1261
UCommerce.Presentation.Presenters.Catalog.EditProductPresenter.View_Load(Object sender, EventArgs e) +15
System.EventHandler.Invoke(Object sender, EventArgs e) +0
umbraco.BasePages.BasePage.OnLoad(EventArgs e) +18
System.Web.UI.Control.LoadRecursive() +70
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3063
I'm creating products, setting a definition, relating them to a category, giving them a description, adding a custom property and creating a price for them. What am I missing? I'm not getting any errors when creating the products, so...
API created products fail in back-office
I'm importing a lot of products using the API, and everything seems to show up fine in the tree, but when I click on a product I get this error in the back-office:
[NullReferenceException: Object reference not set to an instance of an object.] UCommerce.Presentation.Presenters.Catalog.EditProductPresenter.BindView() +1261 UCommerce.Presentation.Presenters.Catalog.EditProductPresenter.View_Load(Object sender, EventArgs e) +15 System.EventHandler.Invoke(Object sender, EventArgs e) +0 umbraco.BasePages.BasePage.OnLoad(EventArgs e) +18 System.Web.UI.Control.LoadRecursive() +70 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3063I'm creating products, setting a definition, relating them to a category, giving them a description, adding a custom property and creating a price for them. What am I missing? I'm not getting any errors when creating the products, so...
The code that imports the products are here:
foreach (var variant in product.Variants) {
newProduct.Name = product.DisplayName;
newProduct.CreatedBy = newProduct.ModifiedBy = "System";
newProduct.CreatedOn = newProduct.ModifiedOn = DateTime.UtcNow;
newProduct.Sku = product.ProductId;
newProduct.VariantSku = variant.VariantId;
newProduct.ProductDefinition = statelessSession.CreateCriteria<ProductDefinition>().Add(Restrictions.Eq("Name", "Jewelry")).List<ProductDefinition>().First();
statelessSession.Insert(newProduct);
CategoryProductRelation cpr = new CategoryProductRelation();
cpr.Category = category;
cpr.Product = newProduct;
statelessSession.Insert(cpr);
ProductDescription desc = new ProductDescription();
desc.CultureCode = culture;
desc.DisplayName = product.DisplayName;
desc.ShortDescription = variant.Description;
desc.Product = newProduct;
statelessSession.Insert(desc);
ProductDescriptionProperty color = new ProductDescriptionProperty();
color.ProductDefinitionField = statelessSession.CreateCriteria<ProductDefinitionField>().Add(Restrictions.Eq("Name", "Color")).List<ProductDefinitionField>().First();
color.ProductDescription = desc;
color.Value = variant.Color;
statelessSession.Insert(color);
foreach (KeyValuePair<String, ProductPrice> pair in variant.Prices) {
Currency curr = statelessSession.CreateCriteria<Currency>().Add(Restrictions.Eq("ISOCode", pair.Key)).List<Currency>().First();
if (curr != null) {
PriceGroup pg = statelessSession.CreateCriteria<PriceGroup>().Add(Restrictions.Eq("CurrencyId", curr.Id)).List<PriceGroup>().First();
if (pg != null) {
PriceGroupPrice pgp = new PriceGroupPrice();
pgp.PriceGroup = pg;
pgp.Product = newProduct;
pgp.Price = pair.Value.Price;
statelessSession.Insert(pgp);
}
}
}
}
Turns out this was some bad data written to product families (variant SKU was set, which doesn't make sense on a product family).
I've added a fix which prevents the errors for happening again in V3.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.