how to hide public views when store is set to closed

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 years ago
Hello,

Hopefully this is a simple question, but I've searched the forums and have not found a solution.

Using various tutorials and guides, I've created a new plugin that has a public facing view (along with an admin interface for management).  Everything works as expected in my testing, except for whenever a store is marked as closed.  The public view can still be rendered.

So my question is what/how is the correct way to ensure that a view respects the store closed setting?

Thanks for any replies in advance
3 years ago
Forgot to add that this was done for version 3.9 of NOP
3 years ago
Just thought about this - maybe adding a new topic and inserting the code from a view into it as a partial view would be a better option?

Is there a way to programmatically add a topic to NOPcommerce via a plugin install?

I'm fairly confident that I can do this manually, but would like to automate it if at all possible.
3 years ago
tkolakow wrote:
Everything works as expected in my testing, except for whenever a store is marked as closed.  The public view can still be rendered.

Depend on how and where is it rendered. If you, for example, insert code to the page which is set to "Accessible when store closed" then it would be shown.

tkolakow wrote:
Is there a way to programmatically add a topic to NOPcommerce via a plugin install?

Sure, that is possible. Just add at the Install() code to insert topic
_topicService.InsertTopic(topic);

Do not forget to add SeName as well.

Regards,
Tom
3 years ago
nop4you wrote:
Depend on how and where is it rendered. If you, for example, insert code to the page which is set to "Accessible when store closed" then it would be shown.

Regards,
Tom


Tom, thanks for the reply!

For now, lets focus on the view since I would like to learn and understand how to control the ability to show or hide a view based off of the store closed flag.

I have no special code in the view that I can tell that would allow for it to bypass the store closed setting if set to true.

Can you give me more insight as to what I need to look for (and where if not in the cshtml file) that could be controlling this?

Some additional testing results are below -

I have set some breakpoints in the code within the StoreClosedAttribute.cs to see what's going on, and for some reason the view I've created is not firing it as the home page does (index.cshtml), but rather more along the lines of the Contact Us page.

It seems that my view is returning out of the OnActionExecuting method of the StoreClosedAttribute.cs due to being flagged as a child action (filterContext.IsChildAction == True), or maybe it's just never calling it correctly?

When comparing how my view is calling the StoreClosedAttribute.cs to the home index page, the one glaring difference is how the class is called from each view, or so it seems.  The home index page seems to call the class initially from its controller (Nop.Web.Controllers.HomeController) on its first pass through while my view never does this.  The subsequent widget calls are made by both pages which kick out on the IsChildAction.

I also checked the Contact Us page to see how it acts, and my page seems to be acting similar to it (it too is visible whenever the store is closed) where no call is being made to the StoreClosedAttribute.cs from its controller.  It looks as if something is missing from the controller for my plugin that may control how the StoreClosedAttribute.cs is utilized, or so it seems.

So, with all of that being said, I'll begin to review the controller code to see what may be needed to have this occur.  If someone can lead me in the right direction, it would be greatly appreciated!!
3 years ago
tkolakow wrote:
begin to review the controller code

Why controller? Just apply code to check store settings of storeclose at the component before view is rendered, or may apply code directly at the view file. It should do the trick.

To understand the code and learn more about particular views, the best is what you have start do - investigate the code. As far as I remember, contactus page is available always by design, that is why it is different than home page which will react accoring to storeclose setting.
You may like to have a look at the topic, which may be define to be accessible or not when store is close.

Regards,
Tom
3 years ago
Tom,

I was able to get the view to not render with the store closed by making the following code change to my plugin's controller where the view was being called -

       
[Nop.Web.Framework.StoreClosed(false)] //Added this line to fix this issue
public ActionResult List(){
        return View();
}


With the call to the StoreClosed class and explicitly telling it to not allow it to bypass the setting by passing the false value, the controller is now calling the class as it should, and everything is working as expected.  I get the store closed message when logged out, and if I log in, since my ACL allows for me to see the site even with the store closed, my view displays correctly.

So, while I've been able to resolve my issue, the question still remains for me - why did I have to do this?  ;-)  It seems that any similar calls to the StoreClosed class are to do the opposite of what I'm doing - they are all passing a true parameter so they can bypass the store closed logic.

I dont understand why I'm having to explicitly tell my view to do something that seems to be the default action for most, if not all other objects.

Thanks again for your help with this.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.