So I'm writing a CSV import, as I have 40k products. I'll share in the other thread when I'm done.. Creating the products within catalog/collection etc has been no problem. Easy really, loving the services!
However, when I add a product via code with a detached data type it basically breaks the whole backoffice View Products (click on a collection etc).
Here is how I am adding my product, basic services setup -
var productService = MerchelloContext.Current.Services.ProductService;
var productVariantService = MerchelloContext.Current.Services.ProductService;
var entityService = MerchelloContext.Current.Services.EntityCollectionService;
var detachedContentService = MerchelloContext.Current.Services.DetachedContentTypeService;
var contentTypeService = Services.ContentTypeService;
Set up warehouse and catalog
var warehouse = merchServices.WarehouseService.GetDefaultWarehouse();
var catalog = warehouse.WarehouseCatalogs.FirstOrDefault(x => x.Name == "PrimaryCatalog");
product.AddToCatalogInventory(catalog);
//Not sure if there is a nicer way of doing this, didn't see a way to grab by name
var bagCollection = entityService.GetAll().FirstOrDefault(a => a.Name == "Bags");
//save it
productService.Save(product, false);
//add to collections
product.AddToCollection(bagCollection);
Grab my content type (basic type created in Umbraco back office)
var contentType = contentTypeService.GetContentType("ProductApparel");
add detached content for "ProductApparel"
var detachedContent = new ProductVariantDetachedContent(
product.ProductVariantKey,
detachedContentType,
"en-US",
new DetachedDataValuesCollection(
new[]
{
new KeyValuePair<string, string>(
"AnotherValue",
"\"12345678\""),
new KeyValuePair<string, string>(
"InternalNumber",
"\"AB1234\""),
new KeyValuePair<string, string>(
"availableSizes",
"\"XS-4XL\""),
}))
{CanBeRendered = true};
//add it to current product
product.DetachedContents.Add(detachedContent);
//save
productService.Save(product, false);
This all works great.. And when I view the product from the backoffice, it works only once. I click on "Bags" and I see my product. I view extended content, and the values are populated as I would expect. But, if I click off and back to "Bags" collection, I get the empty error slide out from the right. (An error occurred etc)..
Past this point, I can't see any products due to crashes - show stopper. In order to even delete it and continue working, I have to call this first, then everything functions properly.
Problem:1 In detached content section how can we find "detachedContentType".
Problem:2 By using createproductwith key instead of create product, i am getting the same error in backend that "Request error: The URL returned a 404 (not found): /umbraco/backoffice/UmbracoApi/Media/GetById".
Problem:3 All works fine and i am able to get all detached properties via getpropertyvalue, issue is whenever i am fetching the product by urlslug got an error of 404 and when i saved the extended content from backend ,it start working.
View products crashes after dynamically adding a product with data type
Hey all,
So I'm writing a CSV import, as I have 40k products. I'll share in the other thread when I'm done.. Creating the products within catalog/collection etc has been no problem. Easy really, loving the services!
However, when I add a product via code with a detached data type it basically breaks the whole backoffice View Products (click on a collection etc).
Here is how I am adding my product, basic services setup -
Set up warehouse and catalog
Create a product
Add it to Catalog & Collection
Grab my content type (basic type created in Umbraco back office)
add detached content for "ProductApparel"
This all works great.. And when I view the product from the backoffice, it works only once. I click on "Bags" and I see my product. I view extended content, and the values are populated as I would expect. But, if I click off and back to "Bags" collection, I get the empty error slide out from the right. (An error occurred etc)..
Past this point, I can't see any products due to crashes - show stopper. In order to even delete it and continue working, I have to call this first, then everything functions properly.
Firebug console is showing a problem with PostGetCollectionEntities.. I wish I knew what Null was attempting to be casted to an Int32..
"NetworkError: 500 Internal Server Error - http://localhost:51982/umbraco/backoffice/Merchello/EntityCollectionApi/PostGetCollectionEntities"
Sorry this is so long!! Any other advice on how to trouble shoot this would be awesome!
Something is null, when it shouldn't be.. Just not sure how I should go about hunting it down! Or maybe I'm missing something in my product add?
Thanks in advance! Awesome work Merchello team!
Alright, I figured it out.. Guess I just had to type this out to realize my error.
The Product Key was "00000-000--000000-0000".. Simply changed the product add to
instead of
Doesn't really explain the NULL -> Int32 conversion log error, but lesson learned to always assign a key?
Problem:1 In detached content section how can we find "detachedContentType".
Problem:2 By using createproductwith key instead of create product, i am getting the same error in backend that "Request error: The URL returned a 404 (not found): /umbraco/backoffice/UmbracoApi/Media/GetById".
Problem:3 All works fine and i am able to get all detached properties via getpropertyvalue, issue is whenever i am fetching the product by urlslug got an error of 404 and when i saved the extended content from backend ,it start working.
is working on a reply...