Modifying content through code...why so different? - Ecommerce - Ecommerce - Progress Community

Modifying content through code...why so different?

 Ecommerce

Modifying content through code...why so different?

  • Modifying content through code...why so different?
  • 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
  • ...also after trying this it seems it doesn't even work

    Even modifying it to be the lifecycle syntax doesn't work
  • 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
  • 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...
  • 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