Product Status In Backend UI incorrect

Posted by Community Admin on 04-Aug-2018 19:05

Product Status In Backend UI incorrect

All Replies

Posted by Community Admin on 15-Jun-2015 00:00

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);​

Posted by Community Admin on 15-Jun-2015 00:00

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.

Posted by Community Admin on 17-Jun-2015 00:00

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));
            ​

This thread is closed