logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
Joe Payne2  
#1 Posted : Monday, June 21, 2021 1:23:25 PM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
I need to render certain admin pages, such as the invoice, into a PDF via a direct url. But the pages cannot be secured, or the PDF engine won't be able to reach them. So I can't create the page in the /Areas/Admin/ portion of the application.

In Able Gold, the solution was relatively simple. I install the ABCPdf library, copy the Invoice page to a root folder like /PdfOutput/, copy the .master layout file as well, and I'm done. I can now render what was originally designed in the admin via a direct url as an anonymous user. As an added bonus, I can now make edits to these pdf-specific pages without impacting the existing admin page or layout.

But in MVC how would I do this? This does not seem to be doable. I can create a shopper-side controller, create a view and copy the original admin invoice view file over. Make a few adjustments and the view content will render on a direct url without requiring permissions. But there are no CSS references in the page source. I suspect that's because I'm returning PartialView() and not View()?

I did set the controller to inherit AbleAdminController thinking that would force the admin CSS to be populated. Returning PartialView() didn't change anything there. But if I change to return View("_whatever", model), that did get me some CSS references. But they look like they're from the store theme, not the admin theme.

I guess what I'm asking is: how do I make a page on the shopper side use the admin theme instead of the store theme?

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

shaharyar  
#2 Posted : Tuesday, June 22, 2021 3:14:47 AM(UTC)
shaharyar

Rank: Advanced Member

Groups: Admin, Developers, Registered, HelpDesk, Authorized User
Joined: 10/5/2018(UTC)
Posts: 703

Thanks: 5 times
Was thanked: 113 time(s) in 112 post(s)
The easiest solution that I would suggest is to create a new area and copy the admin area layout files, style etc.

Everything would be in your hand with a separate URL scheme and that would not impact both the shopper-side and admin side code.
Joe Payne2  
#3 Posted : Tuesday, June 22, 2021 5:42:35 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
That's a great idea. Thanks!
Joe Payne2  
#4 Posted : Tuesday, June 22, 2021 8:57:13 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
Ok, for future reference here are many of the things that can go wrong when you try copying the /Areas/Admin/ to a new area:

Permissions: By default the controllers in the new area permit anonymous access if you inherit from Controller or AbleController. Add an [Authorize] attribute to the main controller class if you require authentication. You can then add [AllowAnonymous] to specific controller methods if you need a mixed environment. Inherit from AbleAdminController if you want to force authentication for all endpoints.

Views: This was the real hassle. The /Views/Shared/_ViewStart.cshtml has the layout path hardcoded. So if you copied the /Areas/Admin/ structure, this has to be changed.

Next is those /Views/Shared/ views. They've got Html.Action methods in them trying to call controller endpoints that existed in /Areas/Admin/ but no longer exist in your new area. Unfortunately the MVC error thrown is very, very misleading. You'll see your controller method get hit and return the main view file, but still get a MVC error about controller not found. Even routeDebugger couldn't tell me the real issue. Eventually I figured out those shared views had Html.Action calls that no longer exist in the new area. Either copy over the methods from the admin controller into your new area controller or remove the Html.Action references.

I'll add more notes to this post if I come across more lessons learned.

Joe Payne2  
#5 Posted : Tuesday, June 22, 2021 1:01:24 PM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
And the next gotcha...

The BundleConfig.cs specifies a bunch of StyleBundle() entries using a generic virtual path name. The problem is, so is the admin theme. If you don't change the virtual path names to include your Area name, your new area pages wind up pulling the first virtual path bundle declared which is from the /Areas/Admin/ path. So you have to modify all the bundle virtual path names to include your area name, then modify _Layout.cshtml to use the new bundle virtual paths.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.