Rendering Partial View NopCommerce Plugins - partial-views

I'm working on to write a new payment plugin on nopcommerce.
How can I render a new partialview in PaymentInfo.cshtml? The new view locates the same path with PaymentInfo.cshtml.

to render any view in the plugins for nopCommerce it must be embedded resource and it must be written in fully qualified name like
#Html.Partial("Nop.Plugin.Something.Something.Views.Plugin.VIEWNAME", item)

You can create a Custom View Engine and add that to your payment plugin. This so you can add routes to Nopcommerce.
First you create a Custom View Engine
CustomViewEngine.cs
public class CustomViewEngine : RazorViewEngine
{
public CustomViewEngine()
{
PartialViewLocationFormats = new[] { "~/Plugins/Misc.HelloWorld/Views/{0}.cshtml" };
ViewLocationFormats = new[] { "~/Plugins/Misc.HelloWorld/Views/{0}.cshtml" };
}
}
Change paths of the Misc.Helloworld to the path of your plugin.
Change the .Edit to the action in your controller.
Change the other information of the controller and the action to the names in your plugin.
After that, create a RouteProvider.cs
ViewEngines.Engines.Insert(0, new CustomViewEngine());
var route = routes.MapRoute("Plugin.Misc.HelloWorld.Edit",
new { controller = "HelloWorld", action = "Edit", },
new { },
new[] { "Nop.Plugin.Misc.HelloWorld.Controllers" }
);
routes.Remove(route);
routes.Insert(0, route);
Change Misc.HelloWorld to the path of your Payment.Plugin,
After that u can add the following to the embedded source
#Html.Partial("Actionname", item)
For more information, see the blog of Alex Wolf

Related

Passing Data Between Controllers While Navigating

I want to pass data between two controllers (in addition to routing parameters) and I would like to know the correct way to do this.
For example: when I navigate to pattern /order/{id}, I do this in the view controller:
this.getRouter().navTo("order", {
id: sOrderId
});
I want to pass additional JSON object which I don't want to be part of routing parameter.
What should I do in this case?
--edit
Wanted to add what I like to achieve with this
I want pass data from master to detail. Both master and detail page has individual routing patterns assigned. So user can land on master or detail directly. When they land on master - user can choose bunch of detail items, and navigate to first detail item, and from there navigate to other items he/she selected earlier on master. So what I want to pass is this selection from master controller to detail controller.
Note: If the intention is to pass selected keys from the main view to the detail view, see https://stackoverflow.com/a/48870579/5846045 instead.
Using a client-side model
Usually, data are stored separately in models instead of assigned to local variables and passing them around. Model data can be then shared with anything that can access the model (e.g. View for data binding).
Here is an example with a client-side model (JSONModel):
Create a JSONModel which is set on a parent ManagedObject. E.g. on the Component via manifest.json:
"sap.ui5": {
"models": {
"myModel": {
"type": "sap.ui.model.json.JSONModel"
}
}
}
In the controller A, set the object to pass before navigating:
const dataToPass = /*...*/
this.getOwnerComponent().getModel("myModel").setProperty("/data", dataToPass, null, true);
In the controller B, do something with the passed data. E.g. on patternMatched handler:
onInit: function() {
const orderRoute = this.getOwnerComponent().getRouter().getRoute("order");
orderRoute.attachPatternMatched(this.onPatternMatched, this);
},
onPatternMatched: function() {
/*Do something with:*/this.getOwnerComponent().getModel("myModel").getProperty("/data");
},
Using NavContainer(Child) events
There are several navigation-related events such as navigate,
BeforeHide, BeforeShow, etc. which contain both views - the source view (from) and the target view (to).
You can make use of the API data to pass the data.
Here is an example:
In the controller A:
onInit: function() {
this.getView().addEventDelegate({
onBeforeHide: function(event) {
const targetView = event.to;
const dataToPass = /*...*/
targetView.data("data", dataToPass);
}
}, this);
},
In the controller B:
onInit: function() {
this.getView().addEventDelegate({
onBeforeShow: function(event) {
/*Do something with:*/this.getView().data("data");
}
}, this);
},
See also the related documentation topic: Passing Data when Navigating
You can create a local model (usually a JSONModel) and set it to inside your app Component.
// inside Component.js
var model = new sap.ui.model.json.JSONModel({ foo: “bar”});
this.setModel(model);
Inside each controller you can use
var model = this.getOwnerComponent().getModel();
console.log(model.getProperty(“/foo”));

Adding a new navigation tab in CMS (keystone JS)

I am new in KeystoneJS and was trying to add a new navigation tab in the admin panel , so for the same i made changes in the keystone.js file and added the required navigation tab in the code
"keystone.set('nav', {
....
});"
but after making changes in it and then running the code i get an error Unknown keystone list "newTab"
I don't know the name of your model, but the correct syntax is:
keystone.set('nav', {
'<tab-name>': '<modelname>'
});
Where tab name can be anything, and modelname should be either the exact (case sensitive!) same name as your model name or a lower case plural version of it.
For example:
Your model: Artwork.js
var Artwork = new keystone.List('Artwork', { ... });
Your navigation definition:
keystone.set('nav', {
'art': 'Artwork'
});
OR
keystone.set('nav', {
'art': 'artworks'
});

Get passed data on next page after calling "to" from NavContainer

I am on my way building a Fiori like app using SAPUI5. I have successfully built the Master page, and on item click, I pass the context and navigate to Detail page.
The context path from Master page is something like /SUPPLIER("NAME"). The function in App.controoler.js is as follows:
handleListItemPress: function(evt) {
var context = evt.getSource().getBindingContext();
this.myNavContainer.to("Detail", context);
// ...
},
But I would like to know how I can access this context in the Detail page. I need this because I need to use $expand to build the URL and bind the items to a table.
There is an example in the UI5 Documentation on how to deal with this problem using an EventDelegate for the onBeforeShow function which is called by the framework automatically. I adapted it to your use case:
this.myNavContainer.to("Detail", context); // trigger navigation and hand over a data object
// and where the detail page is implemented:
myDetailPage.addEventDelegate({
onBeforeShow: function(evt) {
var context = evt.data.context;
}
});
The evt.data object contains all data you put in to(<pageId>, <data>). You could log it to the console to see the structure of the evt object.
Please refer the "shopping cart" example in SAP UI5 Demo Kit.
https://sapui5.hana.ondemand.com/sdk/test-resources/sap/m/demokit/cart/index.html?responderOn=true
Generally, in 'Component.js', the routes shall be configured for the different views.
And in the views, the route has to be listened to. Please see below.
In Component.js:
routes: [
{ pattern: "cart",
name: "cart",
view: "Cart",
targetAggregation: "masterPages"
}
]
And in Cart.controller.js, the route has to be listened. In this example, cart is a detail
onInit : function () {
this._router = sap.ui.core.UIComponent.getRouterFor(this);
this._router.attachRoutePatternMatched(this._routePatternMatched, this);
},
_routePatternMatched : function(oEvent) {
if (oEvent.getParameter("name") === "cart") {
//set selection of list back
var oEntryList = this.getView().byId("entryList");
oEntryList.removeSelections();
}
}
Hope this helps.

gwt menu implementation

I want to implement menu in GWT as shown on this website:
http://www.openkm.com/en/
I have created the menu system and I am able to display alerts from menu using following code:
Command cmd = new Command() {
public void execute() {
Window.alert("Menu item have been selected");
}
}
I want to get rid of window.alert() and display my application pages from menu.
Create and load the appropriate page. For example if you use UiBinder then:
MyPage selectedPage = new MyPage(); // creating of your panel
RootPanel.get().clear(); // cleaning of rhe RootPanel
RootPanel.get().add(selectedPage); // adding the panel to the RootPanel
First create an array list of views
public List<UIObject> viewsList = new ArrayList<UIObject>();
Add a view to that list
viewsList.add(addMovieView);
Send the view you want to select to the helper method
public void changeView(UIObject selectedView) {
for(UIObject view : viewsList) {
if(selectedView.equals(view)) {
view.setVisible(true);
} else {
view.setVisible(false);
}
}
}
Are you trying to make the entire page GWT, or just the menu? If it's just the menu, you will need to embed a GWT element into your overall HTML, then call something like
Window.open(linkURL, "_self", "");
from the appropriate menu items, which will navigate to another page.

How to create a simple landing page in MVC2

I'm trying to create a http://domain.com/NotAuthorized page.
went to Views\Shared and added a View called NotAuthorized witch originates the file name NotAuthorized.aspx
in my Routes I wrote
routes.MapRoute(
"NotAuthorized", // Route name
"NotAuthorized.aspx" // Route Url
);
but every time I access http://domain.com/NotAuthorized I get an error
The resource cannot be found.
What am I missing?
How can access this without using View("NotAuthorized") in the Controller, in other words, not passing through any controller.
You can't access views directly without passing through a controller. All pages in the Views folder cannot be served directly. So one way to accomplish what you are looking for is to write a custom[Authorize] attribute and set the error page:
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
{
base.HandleUnauthorizedRequest(filterContext);
}
else
{
filterContext.Result = new ViewResult { ViewName = "NotAuthorized" };
}
}
I still have no idea on how to accomplish it, but what I did was use the Home Controller and create an Action called NotAuthorized
public ActionResult NotAuthorized()
{
return View();
}
And add a route like
routes.MapRoute(
"NotAuthorized", // Route name
"NotAuthorized", // URL with parameters
new { controller = "Home", action = "NotAuthorized" } // Parameter defaults
);
And works fine now, I can easily redirect in any part of my Business Logic to /Notauthorized and that will route fine.