I would like to add a decimal setting to the Catalog Settings named CustomerEnterPricePercentageSurcharge in nopcommerce 2.65. I followed the instructions on How to Add New Setting Value in Customer settings thread.
However, after following the 3 steps (listed below and modified for Catalog Settings) mentioned in the aforementioned thread, when login into the admin section and save the catalog settings the value is always 0.0000. It seems that it isn't saving (or loading) the "catalogsettings.customerenterpricepercentagesurcharge" settings value. Could someone help me clarify what the value isn't being saved?
Updating Nop.Admin/Models/Setting/CatalogSettingsModel.cs with
[NopResourceDisplayName("Admin.Configuration.Settings.Catalog.CustomerEnterPricePercentageSurcharge")]
public decimal CustomerEnterPricePercentageSurcharge { get; set; }
Updating Nop.Admin/Views/Setting/Catalog.cshtml with
<tr>
<td class="adminTitle">
#Html.NopLabelFor(model => model.CustomerEnterPricePercentageSurcharge):
</td>
<td class="adminData">
#Html.EditorFor(model => model.CustomerEnterPricePercentageSurcharge)
#Html.ValidationMessageFor(model => model.CustomerEnterPricePercentageSurcharge)
</td>
</tr>
Adding:
"catalogsettings.customerenterpricepercentagesurcharge" under (configuration ->setting->AllSetting) and updating the
Your help is very much appreciated.
To be honest, you don't really have to create a new field in Nop.Admin/Views/Setting/Catalog.cshtml
You can avoid all this, and simply:
Add a new value in All Settings.
Then to use it, just add a new field to:
Nop.Core.Domain.Catalog.CatalogSettings
such as
/// <summary>
/// Gets or sets a surcharge
/// </summary>
public decimal CustomerEnterPricePercentageSurcharge { get; set; }
Related
I am using SimpleFormController with a result page looking like this:
<tr>
<td>Name: </td>
<td>${product.name}</td>
</tr>
<tr>
<td>Text: </td>
<td>${product.text}</td>
</tr>
A user can enter a name and some text. I'm trying to implement a delete functionality for each entry (there should be a link next to each entry). I'm having trouble with understanding, if it can be done in the same Controller as for the input or not (am new to Spring) and how. The onSubmit method helps to display data that was added, do I need to implement an extra delete method? If yes, how can I "map" it to my delete link in my jsp?
I suppose you are not wanting to put a delete link even when the user is just entering the name!
Delete links should normally appear when you are displaying data, not creating them.
Here is how you can create a delete link according to associated ids.
<tr>
<td>Name: </td>
<td>${product.name}</td>
<td>delete</td>
</tr>
and this should be in your controller:
#Controller
public class ProductController{
#RequestMapping("/delete/{id}")
public String deleteProduct(#PathVariable("id")Integer id) {
// get product by id
// delete that product
// save database
// or do as you wish
return "redirect:/index";
}
}
Hope that helps :)
I'm a little new to ASP.Net MVC, I have a complex model.
public class BuildingPermit
{
public int ApplicationID { get; set; }
public virtual Person Applicant { get; set; }
public virtual Area ApplicantArea { get; set; }
public virtual ICollection<Owner> Owners { get; set; }
/...
}
Using scaffolding, I created the controller and all the views. However, I want to register all the details in the same page, meaning in the BuildingPermit's Create view, creating the details for Applicant of type Person, the ApplicationArea of type Area and so on. Is there any way I can accomplish this?
If it's not possible, I think it's possible to add a link to create the object. When the user clicks on it, the page goes to that view, creates it, get its information back and shows it in the BuildingPermit's view.
I'd appreciate your help.
You could achieve this by creating an editor template for Person, Area, Owner etc in:
~/Views/Shared/EditorTemplates/Person.cshtml
~/Views/Shared/EditorTemplates/Area.cshtml
~/Views/Shared/EditorTemplates/Owner.cshtml
The editor template will want to be strongly typed and should give the editor layout for the type:
#model Models.Person
<h2>Person</h2>
<p>
#Html.LabelFor(model => model.Name)
#Html.EditorFor(model => model.Name)
</p>
<p>
#Html.LabelFor(model => model.Address)
#Html.EditorFor(model => model.Address)
</p>
// And so on
Once you've done this calling #Html.EditorFor(model => model.Applicant) will pick up your template and display within your Edit view.
If you are wanting to display all of this information together then you will probably want to also create display templates for these types. These work just like the editor templates except you keep your templates in a DisplayTemplates folder.
~/Views/Shared/DisplayTemplates/Person.cshtml
~/Views/Shared/DisplayTemplates/Area.cshtml
~/Views/Shared/DisplayTemplates/Owner.cshtml
That's no problem, just make sure you initialise your complex object somehow to avoid null reference exceptions:
public BuildingPermit()
{
this.Applicant = new Person();
this.ApplicantArea = new Area();
...
}
Then in your controller action method create an instance of the model and pass it to your view:
public ActionResult Create()
{
BuildingPermit model = new BuildingPermit();
View(model);
}
For the view:
#model MyNamespace.BuildingPermit
#Html.LabelFor(m => m.Applicant.FirstName)<br />
#Html.TextBoxFor(m => m.Applicant.FirstName)<br />
...
<input type="submit" value="Create new building permit" />
Then look into examples online on how to handle a HttpPost in your MVC controller.
If you want to create specific UI partials for each object type, then you can looking into EditorFor and DisplayFor templates. From what you mention in your original post, this might be what you're looking for also.
Hope this helps.
I want to add new setting value in Customer settings Page(/Admin/Setting/CustomerUser) after installed nopcommerce 2.5.How can I do?I got nopcommerce 2.5 source code.I'm finding the ways to customize Customer settings Page to add new seeting value.
you can add it in AllSetting section under configuration (configuration ->setting->AllSetting)
you need to add new property in CustomerSettingsModel e.g
//Nop.Admin/Models/Setting/
public bool ZipCodeEnbale{get;set}
then add control for it in CustomerUser.cshtml
//Nop.Admin/Views/Setting/
<tr>
<td class="adminTitle">
#Html.NopLabelFor(model => model.CustomerSettings.ZipCodeEnbale):
</td>
<td class="adminData">
#Html.EditorFor(model => model.CustomerSettings.ZipCodeEnbale)
#Html.ValidationMessageFor(model => model.CustomerSettings.ZipCodeEnbale)
</td>
</tr>
after run the application you will see new property will add under Admin/Customer setting page in CustomerSeeting tab.
Note: if you ant to set default value to property while installing nopcommerec then you need to some additional chnages in InstallationService.cs in (Nop.Service)
add new property value in CustomerSettings under InstallSettings method. e.g
EngineContext.Current.Resolve<IConfigurationProvider<CustomerSettings>>()
.SaveSettings(new CustomerSettings()
{
ZipCodeEnbale= true,
}
I'm working in MVC3 with Entity Framework. I've got an entity called Product that has two properties I'd like to validate when a user adds a new record. To do this, I've created a buddy class, as so:
using System;
using System.ComponentModel.DataAnnotations;
namespace Rpm.Data.Partials
{
[MetadataType(typeof(ProductMetadata))]
public partial class Product
{
}
}
The metadata class is as so:
using System;
using System.ComponentModel.DataAnnotations;
namespace Rpm.Data.Partials
{
public class ProductMetadata
{
[Required]
public string ProductName { get; set; }
[Range(200, 1000, ErrorMessage = "You must select a valid Account Type")]
public int AccountTypeId { get; set; }
}
}
The view that allows users to add a new record is like this:
#model Rpm.Data.Product
#{
ViewBag.Title = "Product"
}
<script type="text/javascript">
$(document).ready(function() {
//There should be no selection in the drop-down box when the form is first displayed.
document.getElementsByTagName("select")[0].selectedIndex = -1;
}
function formSubmit() {
var form = $("form");
if (form.valid()) {
(event.preventDefault) ? event.preventDefault() : event.returnValue = false;
document.getElementById("frmNewProduct").submit();
return true;
}
else {
return false;
}
}
</script>
<h2>Add New Product</h2>
#using (Html.BeginForm("Create", "Product", new { id = new Product() }, FormMethod.Post, new { id = "frmNewProduct" }))
{
#Html.ValidationSummary(true)
<table>
<tr>
<td>
Product Name
</td>
<td>
#Html.TextBoxFor(m => new Product().ProductName)
#Html.ValidationMessageFor(m => new Product().AccountTypeId)
</td>
</tr>
<tr>
<td>
Account Type
</td>
<td>
#Html.DropDownListFor(m => new Product().AccountTypeId, new SelectList(Lookup.Instance.AccountTypes, "AccountTypeId", "AccountTypeName"))
#Html.ValidationMessageFor(m => new Product().AccountTypeId)
</td>
</tr>
<tr>
<td />
<td>
<input type="image" src="#Url.Content("~/Content/images/savebutton.png")" onclick="return formSubmit()" />
</td>
</tr>
</table>
}
(Of course, the above is quite simplified just to avoid overloading the post with code that's not really relevant.)
The problem is that, when the user clicks the Save button, the validation for the ProductName fires just fine and displays the validation message if the field is blank; however, the message for AccountTypeId is never displayed, even if the drop-down is left without a selection (selectedIndex == -1). I know the RangeAttribute on AccountTypeId is being picked up, because when EF tries to save changes to the entities, it throws a DbEntityValidationException, and the text of the ErrorMessage is the custom error message I specified in the metadata. I just can't seem to get it to display on the page and cause the form to fail validation, preventing the user from saving.
Any suggestions as to what I'm doing wrong would be most appreciated!
TIA,
Jeff
When you do this:
#Html.TextBoxFor(m => new Product().ProductName)
#Html.ValidationMessageFor(m => new Product().AccountTypeId)
You're create two entirely different Product() instances, and you create additional Product instances for each property. this might work, since MVC is just using the lambda to create a layout format, but it's in general not very efficient and wastes memory.
Your model type is already product. You should just be using m => m.ProductName
This might be confusing the validation system. I'd just do as I suggest and see if the problem continues.
You also don't need the javascript to set the dropdownlist type. Just do this:
#Html.DropDownListFor(m => new Product().AccountTypeId,
new SelectList(Lookup.Instance.AccountTypes,
"AccountTypeId", "AccountTypeName"), "Select")
And make sure AccountTypeId is nullable int, and you put a [Required] attribute on it. The validator will make sure there's a value.
I'm also not sure why you're using the formSubmit code. image inputs are already submit types, so they submit the form when you click on them. You don't appear to actually be doing anything other than submitting the form again.
I'm working on my first ASP.NET MVC 3 application and I'm trying to show ingredients of a particular ice cream on a create page.
I've got a viewmodel for the page which has a structure something like this:
public class IceCreamViewModel
{
...
public IEnumerable<IngredientViewModel> Ingredients { get; set; }
}
(there are other properties but they aren't germane to the discussion)
Ingredients gets populated by the Create action on the controller and I've verified that it contains the data I want.
The IngredientViewModel has the following structure:
public class IngredientViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsChecked { get; set; }
}
In the Create view I have tried to display the collection of ingredients to allow the user to check which are in the recipe (e.g., peanuts, egg, etc.) and I'm doing something like this:
#Html.EditorFor(m => m.Ingredients)
I've written and editor template for this that looks like so:
#model IceCream.ViewModels.Ingredients.IngredientViewModel
<div>
#Html.HiddenFor(m => m.Id)
#Html.LabelFor(m => m.Name)
#Html.CheckBoxFor(m => m.IsChecked)
</div>
What I'd expect to show up is a bunch of labels and checkboxes for each of my ingredients, but what shows up is the correct number of label/checkbox entries but they all say "Name" rather than the ingredient name that is in the IngredientViewModel. So I'm certainly doing something wrong here. It obviously knows that it has N items to iterate through but it isn't picking up the properties of those items. Guidance?
Update
So, all I ended up doing was switching my LabelFor to a TextBoxFor and my values showed up... as they would, of course. (tired, long day) - #LabelFor uses the name of the property, or the annotated DisplayName for the property. Things work fine now... move along, nothing to see here...
You're trying to create a label for the Name property (as if you wanted the user to edit the Ingredient Name), instead of actually showing the name as the label for the checkbox.
How about changing:
#Html.LabelFor(m => m.Name)
... to:
#m.Name
Or, better yet:
#model IceCream.ViewModels.Ingredients.IngredientViewModel
<div>
#Html.HiddenFor(m => m.Id)
<label for="#m.Id">#m.Name</label>
#Html.CheckBoxFor(m => m.IsChecked)
</div>