Developer forum

Forum » Swift » Express Buy App can't get GetProduct() to return anything on view model?

Express Buy App can't get GetProduct() to return anything on view model?

Kevin Steffer
Kevin Steffer
Reply

Today we struggled with getting specific ProductFields into the "Cart Summary" view.

And we found out that the Extension Method GetProduct() on the CartOrderlineViewModel always return null. Maybe something is out of context the way the Express Buy App is used. Thinking about a form being posted and its using the Model.Cart from a PageViewModel?

Example og your GetProductLink that also doesn't work:
https://github.com/dynamicweb/Swift/blob/53596033e6b27234973b1a28131f1432e80e0506/Swift/Files/Templates/Designs/Swift/Swift_CartSummary.cshtml#L56

We made a workaround and added a custom call to ViewModelFactory to get our productViewModel.

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Kevin

We will look into it. The GetProduct on the orderlineviewmodel does use som context from the customercenter - so that might be it in this case.

We will check it out.

BR Nicolai

 
Stefan Winther Dynamicweb Employee
Stefan Winther
Reply

Hi Kevin,

Yeah you are right - the problem is in the CustomerExperienceCenterFrontend.ProductViewModelSettings -

OrderLineViewModelExtensions (GetProduct) is marked with ThreadStatic attribute, but by every request the thread is randomly changed, so previously created settings are lost.

We can add this to the CartSummary.cshtml - to ensure we get the correct context every time an async request is made:

var productViewModelSettings = new ProductViewModelSettings();
productViewModelSettings.CurrencyCode = Dynamicweb.Ecommerce.Common.Context.Currency.Code;
productViewModelSettings.CountryCode = Dynamicweb.Ecommerce.Common.Context.Country.Code2;
productViewModelSettings.LanguageId = Dynamicweb.Ecommerce.Common.Context.LanguageID;
productViewModelSettings.EnsureFilledPropertiesExist();

​Then creating the product viewmodel - instead of using the GetProduct() method
var productViewModel = ViewModelFactory.CreateView(productViewModelSettings, orderline.ProductID, orderline.ProductVariantID);

Hope this aligns with your workaround :)
/Stefan 

 
Kevin Steffer
Kevin Steffer
Reply

@Stefan - that was our workaround yes.

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

I think we have found a permanent solution for the extension method that will fix this at the core. Still in progress but on its way.

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply

Hi Kevin 

The permanent solution now in release 9.17.1
Get this from the download section https://doc.dynamicweb.dk/downloads/dynamicweb-9

Kind Regards
Care Support 
Kristian Kirkholt

 

You must be logged in to post in the forum