Route-hijacked custom document types throwing an error (Bazaar store)
Hi Rusty,
I'm running the Combined install with v1.10.
The navigation is throwing an object reference not set to instance.. while trying to use my own document types. eg I have created a ProductGroup landing page (which in turn displays multiple ProductGroups).
The offending line is:
if (currentCustomer.IsAnonymous)
My custom controller inherits the RenderMvcController. Should I be inheriting a BazaarControllerBase or similar instead (which would include an instance of a Customer)? I checked the Bazaar source and it looks like I should be, however it doesn't seem to exist in the combined install. Was there a previous way of doing it?
Thanks. Tried inheriting from both MerchelloRenderMvcController and RenderControllerBase - still object not set error I'm afraid
public class CategoriesLandingPageController : MerchelloRenderMvcController
{
public override ActionResult Index(RenderModel model)
{
var viewModel = new CategoriesLandingPage(model.Content) { };
return View(viewModel.ThemeViewPath("CategoriesLandingPage"), viewModel);
}
}
I feel like i'm doing something wrong in my return value
Yes that's correct, and the CategoriesLandingPage (model) is inheriting from MasterModel. The offending line is in the Nav view.
public class CategoriesLandingPageController : MerchelloRenderMvcController
{
public override ActionResult Index(RenderModel model)
{
var viewModel = new CategoriesLandingPage(model.Content) { };
return View(viewModel.ThemeViewPath("CategoriesLandingPage"), viewModel);
}
}
The model isn't particular adding much as you can see
public class CategoriesLandingPage : MasterModel
{
public CategoriesLandingPage(IPublishedContent content)
: base(content)
{
}
}
@functions
{
/// <summary>
/// Returns the customer name or "Account" for the Account link based on login status
/// </summary>
/// <param name="currentCustomer">Mechello's <see cref="ICustomerBase"/></param>
/// <returns>A string label for the Acccoun tab</returns>
/// <remarks>
/// A bit hacky here, but it does the trick.
/// </remarks>
private string GetAccountDropDownName(ICustomerBase currentCustomer)
{
if (currentCustomer.IsAnonymous) return "Account";
var customer = (ICustomer)currentCustomer;
var name = customer.FullName;
if (!string.IsNullOrEmpty(name)) return name;
return "Account";
}
Looking at the Bazaar.dll (1.10), the BazaarProductGroupController calls a ViewModelFactory. I'm unsure about the line 'this.ViewModelFactory.CreateProductGroup(model). In this case, what is 'this'?
namespace Merchello.Bazaar.Controllers
{
[PluginController("Bazaar")]
public class BazaarProductGroupController : RenderControllerBase
{
public override ActionResult Index(RenderModel model)
{
ProductGroupModel productGroup = this.ViewModelFactory.CreateProductGroup(model);
return (ActionResult) this.View(ModelExtensions.ThemeViewPath((IMasterModel) productGroup, "ProductGroup"), (object) productGroup);
}
}
}
Although if you wanted to do it 'correctly' then a new method would need to be created within the ViewModelFactory, returing a base model of some sort instead? Not to worry in this instance - if it was a larger application with lots of different document types then I would be more concerned!
Route-hijacked custom document types throwing an error (Bazaar store)
Hi Rusty,
I'm running the Combined install with v1.10.
The navigation is throwing an object reference not set to instance.. while trying to use my own document types. eg I have created a ProductGroup landing page (which in turn displays multiple ProductGroups).
The offending line is:
My custom controller inherits the RenderMvcController. Should I be inheriting a BazaarControllerBase or similar instead (which would include an instance of a Customer)? I checked the Bazaar source and it looks like I should be, however it doesn't seem to exist in the combined install. Was there a previous way of doing it?
cheers
@Jason
Try inheriting from
so that the customer context is instantiated.
@Rusty
Thanks. Tried inheriting from both MerchelloRenderMvcController and RenderControllerBase - still object not set error I'm afraid
I feel like i'm doing something wrong in my return value
I think 1.10 is using the MasterModel rather than IPublishedContent for the Master.view ...
Does CategoriesLandingPage inherit from MasterModel - and is the offending line in the controller or in the view?
Yes that's correct, and the CategoriesLandingPage (model) is inheriting from MasterModel. The offending line is in the Nav view.
The model isn't particular adding much as you can see
and the view (part of)
}
@Rusty
Looking at the Bazaar.dll (1.10), the BazaarProductGroupController calls a ViewModelFactory. I'm unsure about the line 'this.ViewModelFactory.CreateProductGroup(model). In this case, what is 'this'?
The customer is injected in at ViewModelFactory
a bit hacky, but if anyone is interested I 'resolved' the issue as follows:
I think that approach is fine - it's the same thing that was done in the factory =)
Although if you wanted to do it 'correctly' then a new method would need to be created within the ViewModelFactory, returing a base model of some sort instead? Not to worry in this instance - if it was a larger application with lots of different document types then I would be more concerned!
is working on a reply...