AddToCartWidget error after 5.3 upgrade - Ecommerce - Ecommerce - Progress Community

AddToCartWidget error after 5.3 upgrade

 Ecommerce

AddToCartWidget error after 5.3 upgrade

  • AddToCartWidget error after 5.3 upgrade
  • Hi there!

    I have an Ecommerce site where I have used the AddToCart widget in Product listing views. After upgrading to 5.3 all these pages produces an error:

    Server Error in '/' Application.
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
     
    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
     
    Source Error:
     
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
     
    Stack Trace:
     
     
    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Sitefinity.Modules.Ecommerce.Orders.Web.UI.AddToCartWidget.InitializeControls(GenericContainer container) +19
       Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +81
       System.Web.UI.Control.EnsureChildControls() +181
       System.Web.UI.Control.PreRenderRecursiveInternal() +59
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Control.PreRenderRecursiveInternal() +221
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4200
     
     
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

    When I comment out the AddToCartWidget the page renders just fine.

    I just can't see what's changed since 5.2 to create this error.

    Anyone with any insights into this?

    Thanks,
    OC

  • Hmm....
    This looks like a bug.

    I've now tried to use the default product Thumbnails temlpate and the default out-of-the-box AddToCartWidget, just in case this was related to my own templates. But the result is the same error.

    Any one else upgraded an eCommerce site to 5.3?

    OC
  • Hello,

    We have tested upgrades regarding the Ecommerce module and haven't got an issue like that. I think it is specific problem for your project but to find the bug more information is needed as Jochem said. Could you provide us with the upgrade log in order to get the upgrade error if any. Can you share more details about your project? Is it Multilingual? Have you done any custom development? Any information would be helpful. 

    If you can send us you project and database in support ticket we will be able to easily locate the issue.

    All the best,
    Stoimen Stoimenov
    the Telerik team
    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
  • Hi there,

    The site is multi-lingual and localized. It worked just fine in 5.2. I'm using my own templates both for the Product list widget and the Buy now widget.

    But I also tried to use a template called "Thumbnails", that I beleive to be a default out-of-the-box one, along with the default Add to cart Widget. The error is produces also with the default widgets.

    OC 
  • Hey Ole,

    Have done a client 5.2 upgrade without any problems (no BuyNow widgets, standard shippable products) and after reading your post also took a 5.2.3700 test site with BuyNow widgets and upgraded it and it seems to function without any problem.

    The test-site I played with uses the BuyNow widget with a normal generic product, perhaps you're using variations? Localized? Or some special form of Attributes that may cause issues?

    I'd be more than happy to re-upgrade the test-site to verify the bug...
    Jochem

  • Hello Ole,

    We will continue helping you with this service request in the support ticket you have submitted.

    Kind regards,
    Randy Hodge
    the Telerik team
    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
  • Hello,

    was there a solution? Because I have the same problem...

    Kind regards,

  • Bob,

    I've just run on 5.2 so far. But I picked up this again two days ago, and the support team have now my projects and databases for investigation. They have not replyed yet, but I'll update the thred with their findings.

    It is very strange, but I think it must have something to do with the inventory. That's the only new thing in 5.3. I'm not using it, I have my own inventory from my backend system.

    OC

  • Hello OC,

    thank you for your reply. Here the same situation, don't use the inventory... simple scenario.

    Also an upgrade to 5.4 doesn't fix the issue.

    Is it possible to keep us informed through the forum? Thanks in advance...

    bob

  • Bob / Ole,

    Call me an idiot, but I'd love to try and find out what's causing it - any change either of you is willing to toss a broken project my way ?

    Jochem

  • not at all... :)

    but I'm afraid I can't give you the project... I'll see if I can reproduce the problem...

    thanks

  • Jochem,

    I'll PM you on LinkedIn with download and login credentials.

    OC

  • @Ole,

    Thanks, I've got it up and running - send you an email with the details so far.
    Jochem

  • Hello,

    I found a (hopefully temporary) workaround...
    I inherited the AddToCartWidget and removed some checks:

    public class CustomAddToCartWidget : AddToCartWidget
        protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
        
            this.SwitchVisibilityBasedOnInventory(this.GetProductVariations());
            this.QuantityControl.Text = "1";
            this.CssClass = "sfAddToCartWrp";
            this.AddToCartButton.Command += new CommandEventHandler(CustomAddToCartButton_Command);
        
     
        private void CustomAddToCartButton_Command(object sender, CommandEventArgs e)
        
            int quantity = int.Parse(this.QuantityControl.Text);
            IShoppingCartAdder shoppingCartAdder = (IShoppingCartAdder)new ShoppingCartAdder();
            string defaultCurrency = Config.Get<EcommerceConfig>().DefaultCurrency;
            OptionsDetails optionDetails = GetOptionDetails();
     
            try
            
                shoppingCartAdder.AddItemToShoppingCart((IOrdersControl)this, (ICartOrderManager)this.OrdersManager, this.Product, optionDetails, quantity, defaultCurrency, new Guid?());
                this.AddedToCartMessage.ShowPositiveMessage(Res.Get<OrdersResources>("AddedToCart"));
                this.SwitchVisibilityBasedOnInventory(GetProductVariations());
            
            catch (ArgumentException ex)
            
                //EcommerceLogger.LogException((Exception)ex);
                this.AddedToCartMessage.ShowNegativeMessage(ex.Message);
            
            catch (Exception ex)
            
                //EcommerceLogger.LogException(ex);
                this.AddedToCartMessage.ShowNegativeMessage(Res.Get<OrdersResources>("NotAddedToCart"));
            
            if (!this.AddToCartRedirectPageId.HasValue)
                return;
            this.Page.Response.Redirect(EcommerceControlExtensions.GetPageNodeUrl((IEcommerceControl)this, this.AddToCartRedirectPageId.Value, false));
        
     
        private List<ProductVariation> GetProductVariations()
        
            List<ProductVariationDetail> variationDetails = this.GetOptionDetails().ProductVariationDetails;
            if (variationDetails != null)
                return Enumerable.ToList<ProductVariation>(Enumerable.Select<ProductVariationDetail, ProductVariation>((IEnumerable<ProductVariationDetail>)variationDetails, (Func<ProductVariationDetail, ProductVariation>)(pvd => pvd.ProductVariationParent)));
            else
                return (List<ProductVariation>)null;
        
     
        private OptionsDetails GetOptionDetails()
        
            Control parent = this.Parent;
            OptionsDetails optionsDetails = new OptionsDetails();
            foreach (Control control in parent.Controls)
            
                if (control.GetType().Name == "ProductOptionsControl")
                    return ((ProductOptionsControl)control).SelectedOptions;
            
            return optionsDetails;
        

    And used this control in my template.

    For the moment this seems to work, but I'll have to map this to a new template to modify some markup. Some issues with the validators.

    bye