+1-888-365-2779
Try Now
More in this section

Forums / Ecommerce / Modifying content through code...why so different?

Modifying content through code...why so different?

5 posts, 0 answered
  1. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    04 Oct 2013
    Link to this post
    Other content requires a whole checkout, checkin process
    http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/modules/content-blocks/modifying-content-items

    ...but ecomm just says get the item then call a workflow method...?  Is that legit and tested?
    http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/modules/ecommerce/products/modifying-products
  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    04 Oct 2013 in reply to Steve
    Link to this post
    ...also after trying this it seems it doesn't even work

    Even modifying it to be the lifecycle syntax doesn't work
  3. Atanas Valchev
    Atanas Valchev avatar
    414 posts
    Registered:
    04 Jan 2016
    08 Oct 2013
    Link to this post
    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
  4. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    09 Oct 2013 in reply to Atanas Valchev
    Link to this post
    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...
  5. Atanas Valchev
    Atanas Valchev avatar
    414 posts
    Registered:
    04 Jan 2016
    13 Oct 2013
    Link to this post
    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
5 posts, 0 answered