Is There An Issue With v2.0 And Multiple Variants?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 12 ans
We are building a store with v2.0 and (Almost) everything has been fine throughout, we have added products with a default variant and its working OK.

We have just created a product with multiple variants, and now we are getting the following error?

==============
Object reference not set to an instance of an object.

Line 26:     dataDictPrice.TemplateInfo.HtmlFieldPrefix = string.Format("price_{0}", defaultProductVariant.Id);

[NullReferenceException: Object reference not set to an instance of an object.]
   ASP._Page_Views_Catalog_Product_cshtml.Execute() in d:\websites\Production\MySiteName\htdocs\Views\Catalog\Product.cshtml:26
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +81
   System.Web.WebPages.StartPage.RunPage() +19
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +65
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76
   System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +220
   System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +303
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
   System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +23
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +260
   System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +177
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
   System.Web.Mvc.Controller.ExecuteCore() +116
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8897857
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

==============

Anyone else have this problem?  Also how do I change a product layout template for when it has multiple variants?
Il y a 12 ans
So no one else gets this?
Il y a 12 ans
You won't be able to use version 2 of nopCommerce if you are using Multiple variants for a product, unless you change this line of code

OLD

        var dataDictPrice = new ViewDataDictionary();
        dataDictPrice.TemplateInfo.HtmlFieldPrefix = string.Format("price_{0}", defaultProductVariant.Id);

NEW

    var dataDictPrice = new ViewDataDictionary();
    if (defaultProductVariant != null)
    {
        dataDictPrice.TemplateInfo.HtmlFieldPrefix = string.Format("price_{0}", defaultProductVariant.Id);
    }

Slightly annoying...
Il y a 12 ans
I presume that you made some change to your source code because if you open \Nop.Web\Views\Catalog\Product.cshtml file (version 2.00) downloaded here, you'll see the following code:
@if (!hasMultipleVariants && defaultProductVariant != null)
                    {
                        var dataDictPrice = new ViewDataDictionary();
                        dataDictPrice.TemplateInfo.HtmlFieldPrefix = string.Format("price_{0}", defaultProductVariant.Id);
                        @Html.Partial("_ProductVariantPrice", defaultProductVariant.ProductVariantPrice, dataDictPrice)
                            
                   var dataDictAddToCart = new ViewDataDictionary();
                   dataDictAddToCart.TemplateInfo.HtmlFieldPrefix = string.Format("addtocart_{0}", defaultProductVariant.Id);
                        @Html.Partial("_ProductVariantAddToCart", defaultProductVariant.AddToCart, dataDictPrice)                    
                    }

So it works fine by default
Il y a 12 ans
Hmmm ok now I am confused!

I'll check with my colleague on Monday but I certainly haven't changed anything apart from some extra divs / classes added for styling.

I downloaded this and set it up the day v2.0 came out... Thanks for coming back anyway, whats the ETA on v2.1 with multiple product templates?
Il y a 12 ans
It was released one month ago =)))
Il y a 12 ans
Well that will teach me to have my head down in v2.0 and not keep an eye on here! Is there a road map for v2.2 and rough ETA?  Wondering if I should wait until that is released before trying to upgrade?
Il y a 12 ans
ETA: https://www.nopcommerce.com/boards/t/12031/nopcommerce-22.aspx
Roadmap: 2.10 was an intermediate release (not all planned features were implemented). The roadmap is almost the same as it was for v2.10 (except features already implemented in v2.10). Have a look at the source contol commit historyhere in order to know what is already done
Il y a 12 ans
Awesome thanks... Product templates was a great addition to put back in :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.