I'm trying to call the current Merchello basket from an Umbraco Partial View Macro file, so that I can gather info such as current number of items in the current basket etc.. but I can't seem to get it to work with the example code.
I've copied the following code from the Basket.cstml script in the Bazaar example but get this error: Exception: System.InvalidOperationException: The model item passed into the dictionary is of type 'Umbraco.Web.Models.PartialViewMacroModel', but this dictionary requires a model item of type 'Merchello.Bazaar.Models.ViewModels.BasketModel'.
It's strange because the script runs fine when rendered on the basket page itself, but I can't seem to use that little snippet anywhere else! Can anyone offer any help?
This gives the error "The model item passed into the dictionary is of type 'Umbraco.Web.Models.PartialViewMacroModel', but this dictionary requires a model item of type 'Merchello.Bazaar.Models.ViewModels.BasketModel'."
Thanks for the reply, I've tried your suggestion but the same thing happens!
Is there a way to retrieve the basket + contents from any partial view macro? I installed the Bazaar store on a pre-existing dev site so I've been having difficulty trying to call Merchello on my non-Merchello pages. Any advice?
var basketUmbracoNode = Umbraco.TypedContent(BASKETNODEID);
var basketModel = new BasketModel(basketUmbracoNode);
@Html.Partial("BASKETVIEW", basketModel)
I didn't tested the code... but I think it should look kinda like this.
I managed to pass the correct model through to my basket partial thanks to your code! But for some reason when I call the @Model.CurrentCustomer.Basket() method, I get the following error:
System.ArgumentNullException: Value cannot be null. Parameter name: customer at Umbraco.Core.Mandate.That[TException](Boolean condition, Func`1 defer) at Merchello.Web.Workflow.Basket.GetBasket(IMerchelloContext merchelloContext, ICustomerBase customer) in c:\Working Repositories\GitHub\Merchello\src\Merchello.Web\Workflow\Basket.cs:line 107
I feel like I'm close but it's driving me crazy! Can anyone offer some advice?
Retrieving Merchello Basket
Hi,
I'm trying to call the current Merchello basket from an Umbraco Partial View Macro file, so that I can gather info such as current number of items in the current basket etc.. but I can't seem to get it to work with the example code.
I've copied the following code from the Basket.cstml script in the Bazaar example but get this error:
Exception: System.InvalidOperationException: The model item passed into the dictionary is of type 'Umbraco.Web.Models.PartialViewMacroModel', but this dictionary requires a model item of type 'Merchello.Bazaar.Models.ViewModels.BasketModel'.It's strange because the script runs fine when rendered on the basket page itself, but I can't seem to use that little snippet anywhere else! Can anyone offer any help?
Kind Regards
How are you calling the partial macro view?
Hey Tobias,
Thanks for looking, I'm rendering my macro views like so:
Maybe I'm doing something wrong?
Kind Regards
Yeh you have to pass in your model.
Thanks Tobias, that looks like it's probably the answer, but I'm still having some trouble passing the correct model through unfortunately!
My Header script looks like this:
And my Basket.cshtml partial looks like this:
This gives the error "The model item passed into the dictionary is of type 'Umbraco.Web.Models.PartialViewMacroModel', but this dictionary requires a model item of type 'Merchello.Bazaar.Models.ViewModels.BasketModel'."
Can anyone spot what I've done wrong?
Kind Regards
@pronto - You should be using
rather than
Hey Rusty,
Thanks for the reply, I've tried your suggestion but the same thing happens!
Is there a way to retrieve the basket + contents from any partial view macro? I installed the Bazaar store on a pre-existing dev site so I've been having difficulty trying to call Merchello on my non-Merchello pages. Any advice?
Kind Regards
@pronto could you try something like this?
I didn't tested the code... but I think it should look kinda like this.
Hey Tobias,
I managed to pass the correct model through to my basket partial thanks to your code! But for some reason when I call the @Model.CurrentCustomer.Basket() method, I get the following error:
I feel like I'm close but it's driving me crazy! Can anyone offer some advice?
Kind Regards
@pronto
My guess is you've included this code in a view where the CustomerContext is null. If you swap out
with
I bet it kicks.
MerchelloViewPage
Hey Rusty,
Thank you so much man, that's exactly what I needed. Keep up the good work!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.