Modifying content through code...why so different?

Posted by Community Admin on 05-Aug-2018 01:46

Modifying content through code...why so different?

All Replies

Posted by Community Admin on 04-Oct-2013 00:00

Other content requires a whole checkout, checkin process
www.sitefinity.com/.../modifying-content-items

...but ecomm just says get the item then call a workflow method...?  Is that legit and tested?
www.sitefinity.com/.../modifying-products

Posted by Community Admin on 04-Oct-2013 00:00

...also after trying this it seems it doesn't even work

Even modifying it to be the lifecycle syntax doesn't work

Posted by Community Admin on 08-Oct-2013 00:00

Hello Steve,

I have verified that this code is tested. The eCommerce code however, expects that the product is correctly in Draft before you call the method that modifies it.

Regards,
Atanas Valchev
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 09-Oct-2013 00:00

This code isn't changing my data at all...

public void UpdateProduct(AbleProduct product)
    CatalogManager manager = CatalogManager.GetManager();
    ProductType productType = manager.GetProductTypes().Where(t => t.Title == "General product").SingleOrDefault();
 
    if (productType == null)
    
        return;     // Product Type does not exist
    
 
    Product master = this.SitefinityProductList.Where(x => x.GetValue<decimal>("AbleProductID") == product.Id && x.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master).SingleOrDefault();
 
    if (master != null)
    
        if (product.InStock != master.Inventory)
        
            Product temp = manager.Lifecycle.CheckOut(master) as Product;
 
            master.Inventory = product.InStock;
            //masterProduct.Sku = product.Sku;
            //masterProduct.Weight = product.Weight;
            master.Price = product.Price;
            master.Featured = product.IsFeatured;
            //manager.Provider.RecompileItemUrls(masterProduct);
 
            master = manager.Lifecycle.CheckIn(temp) as Product;
            manager.Lifecycle.Publish(master);
 
            manager.SaveChanges();
        
    

No errors though...

Posted by Community Admin on 13-Oct-2013 00:00

Hi Steve,

I did a few tests with the following and it works as expected:

protected void Page_Load(object sender, EventArgs e)
       
           var catMan = CatalogManager.GetManager();
           var masterP = catMan.GetProducts().Where(p => p.Title == "Nasko" && p.Status==ContentLifecycleStatus.Master).FirstOrDefault();
           EditProduct(masterP.Id,"NaskoModified","DescriptionModified");
 
       
       public static void EditProduct(Guid productId, string newTitle, string newDescription)
       
           CatalogManager catalogManager = CatalogManager.GetManager();
 
           Product product = catalogManager.GetProduct(productId);
           if (product != null)
           
 
 
               product.Description = newDescription;
               product.Title = newTitle;
               product.UrlName = Regex.Replace(newTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
 
               catalogManager.RecompileItemUrls<Product>(product);
               catalogManager.SaveChanges();
 
               var contextBag = new Dictionary<string, string>();
               contextBag.Add("ContentType", product.GetType().FullName);
 
               string workflowOperation = "Publish";
 
               WorkflowManager.MessageWorkflow(product.Id,
                   product.GetType(),
                   "OpenAccessDataProvider",
                   workflowOperation,
                   false,
                   contextBag);
                
           
       
 

Regards,
Atanas Valchev
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed