Product Status In Backend UI incorrect
Hello All,
I am updating products via the api. Everything is working except one thing. If I change the price for product 'a' from 3.00 to 4.00 it works. When I query the api the live version is at 3.00 and the master version is at 4.00. The problem is that if you go to the backend and go to the product screen for 'a' it shows the new price of 4.00 but it also shows the product as Published. It should show as Draft.
This is the code that I am using:
CatalogManager catalogManager = CatalogManager.GetManager();
Product productToUpdate = catalogManager.GetProduct(incomingProduct.Sku, ContentLifecycleStatus.Master);
if (productToUpdate != null)
productToUpdate.Title = incomingProduct.Title;
productToUpdate.Price = incomingProduct.Price;
productToUpdate.Weight = incomingProduct.Weight;
catalogManager.RecompileItemUrls<Product>(productToUpdate);
catalogManager.SaveChanges();
var contextBag = new Dictionary<string, string>();
contextBag.Add("ContentType", productToUpdate.GetType().FullName);
string workflowOperation = "Draft";
WorkflowManager.MessageWorkflow(productToUpdate.Id,
productToUpdate.GetType(),
"OpenAccessDataProvider",
workflowOperation,
false,
contextBag);
More detail.
The problem is only with a product that has been previously published. A new product is showing correctly (draft). However if an existing product has been previously published it is showing as published when it should say draft.
Well I got an answer to support. You need to change the way update by checking out the item, modifying it. Then checking it in:
CatalogManager catalogManager = CatalogManager.GetManager();
Product productToUpdate = catalogManager.GetProduct(incomingProduct.Sku, ContentLifecycleStatus.Master);
if (productToUpdate != null)
var productCheckedOut = catalogManager.Lifecycle.CheckOut(productToUpdate) as Product;
productCheckedOut.ApprovalWorkflowState = new Telerik.Sitefinity.Model.Lstring("Draft");
productCheckedOut.Title = incomingProduct.Title;
productCheckedOut.Price = incomingProduct.Price;
productCheckedOut.Weight = incomingProduct.Weight;
ILifecycleDataItem productCheckedIn = catalogManager.Lifecycle.CheckIn(productCheckedOut);
catalogManager.SetUIStatus();
catalogManager.RecompileItemUrls<Product>(productToUpdate);
catalogManager.SaveChanges();
else
throw new Exception(string.Format(SR.UnableToLoadProduct, incomingProduct.Sku));