query on ADDING NEW FIELD in database - URGENT

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Thank you once again.

The most recent example was learning that the UIHint data tag on a model property will allow you to specify a custom editor.

Lost me there!!!!

This is the first application of this nature I have developed but it inspiring to see the capabilities of what can be produced and then tailored made.

Its weird its taken me 3-4 days to connect that string with help but I have just created 4 new fields and populated then on the front end. I was going to use the shared rootpopout.cshtml for the display but I think I may just write my own. :)

Hope you enjoy the weekend...

Monday we are bringing the data over If you remember me saying 13,000 products daily replicated data (after major testing).. Its good I'm bald already lol :)

Richard
12 years ago
Hi Andy

Quick question if you the time. I have added all nessercary feilds I need to connect to our in house Db. But when testing values/data its not displaying correctly on the front end.

For example I have created a feild called RRP - Recomended Retail Price. The data type is money and the strings are below in the db and on the front end they are displaying for example - RRP: £2.3000 as you can see there is multiple 000 that we don't need.

Nop.Core/Domain/Catalog/Product.cs
public virtual decimal RRP { get; set; }


Nop.Data/Catalog/ProductMap.cs
this.Property(p => p.RRP).IsConcurrencyToken();


I have applied the modification and executed the stored procedure.

Apllied the Model/View/Controller classes.

Model

public decimal RRP { get; set; }


Controller

//RRP
model.RRP = product.RRP;


View etc.

I have created 3 new fields that involve currency RRP MRP and Wholesale Price all money data types and used as decimal strings.

I searched W3School for Sql Data types to see If could apply an inclosed bracket as for example with decimal(18, 4) etc I'm wondering if that is the correct procedure??

Richard
12 years ago
Sounds right, the Price column on ProductVariant is also decimal(18,4)
12 years ago
Hi Job done.

Converted the data type to


ALTER TABLE [Nop].[dbo].[Product]
ALTER COLUMN Weig decimal(18,2)


Displays to two decimal place's within the specific fields needed.

Thanks
12 years ago
Hi Andy

Sorry for disturbing you again I'm aware you are busy!

I inserted the data today and the Product table that now contain's over 19,000 products. But they are not displaying on the front end yet. I have asked on the forum and been advised to insert into both the product table and the productvariant table.

As you maybe able to tell I don't want to use the PV table but is it nesercary for the display. When previously writing on here I was using 50 products for testing purposes and populated both PV and Product table. Is there a work around so I don't have to use the PV table or go ahead with the insert into both. My concern with this is that Ill have to map both tables. Just to one.

The main reason for asking this is in the CategoryTemplateGridorList.CSHTML I would like to use some of the fields I created in the dbo.product to display. Also use the QTY and to cart function. Is this at all possible.

When I feel it would be easier to just use the one table ie adding the colunms.?

Sorry for disturbing you once again

All help highly regarded. NEARLY THERE!!!!!!!

Rich
12 years ago
Hey can you please tell me how you resolved it?
Am trying to add new column to customer table -
Am following below URL -
https://www.nopcommerce.com/docs/73/updating-an-existing-entity-how-to-add-a-new-property.aspx

But, it's giving following error -

Invalid column name 'AreaCode'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'AreaCode'.

Source Error:

Line 240:                        where c.Email == email
Line 241:                        select c;
Line 242:            var customer = query.FirstOrDefault();
Line 243:            return customer;
Line 244:        }


Source File: D:\Projects\Ekam\ekam\Libraries\Nop.Services\Customers\CustomerService.cs    Line: 242 "
"
Am a newbie, so i don't know how to apply these to points as mentioned in that link

Recreate the database. Either your own custom SQL script or use the nopCommerce installer (blog coming soon).
Stop the development web server between schema chagnes. It caches stuff and will cause a headache.

Can anyone briefly explain the steps?

Thanks
12 years ago
I wrote this document up myself/with help and references from people online  - English isn't great but hey - If your updating the customer display instead of looking at the Product.cs reference the Customer.cs throughout every area. I hope this helps. Mind you I'm not sure about the stored procedure in your case I think that is for product display - don't quote me on that I don't know YET.. Also I was hit with the error you had I just restarted the Visual Studio and the Server itself..


Updating existing Entity Framework Adding New fields to dbo.Product.
For connection and Replication Purposes These Fields are in  ccc dbo.stock!

-The Core defines what the object is.
-The Data defines relationships and how it maps to the DB
-The Service interacts with the data layer.  Whenever you want to Get or Save something, it goes through the service
-The Model is an object that is passed back and forth between Controller and View.  It's data that the View uses to do its thing without worrying about how the data got there.
-The View is the user interface.  It's your HTML and where you want certain fields to show up.  It's your buttons.
-The Controller handles web requests and runs the show.  It figures out what View to show and creates the Model for it.  It fills the Model with data it gets from the Services.

Step by step guide to creating new fields and updating the existing entity through its Core to the Web Services.

This document will deconstruct and layout the process of updating our entity framework using one of the fields from below. For this example I will be using Packs Per Layer as my example.

Added Fields.

Packs per Layer   int  Is Null
Packs per Pallet  int  Is Null
Layers per Pallet  int  Is Null
RRP  decimal  Is Null
MRP  decimal  Is Null
Retail Barcode  int  Is Null
Weight  int  Is Null
Stock Code.  nvarchar(max)  Is Null
Pack Size  nvarchar(max)  Is Null
QTYINSTOCK  nvarchar(max)  Is Null
Size  Nvarchar(max)  Is Null
WholeSale Price  Nvarchar(max)  Is Null




1. MSSQL –dbo.Product

Alter Statement – on creating a new field in Sql 2008 use the following syntax. Creating a new column and data type example as above.

ALTER TABLE [Nop].[dbo].[Product]
ADD PacksPerLayer int


  

1.  Nop.Core/Domain/Catalog/Product.cs

In the following object it is nessecary to update the virtual String so that the object service provider can make calls from the data to the web services. With the data type created in SQL will vary the string. Eg Int is Int – decimal is decimal and nvarchar is a string.

        /// <summary>
       /// Gets or sets the PacksPerLayer
       /// </summary>
       public virtual int PacksPerLayer { get; set; }


2.  Nop.Data/Catalog/ProductMap.cs

In the data object the C# files defines the table/field properties and how it          used with the web service. I have placed two examples below one that uses int (Packs per Layer) and one that uses nvarchar (Stockcode) as it defines the difference using Unicode characters.

        this.Property(p => p.StockCode).HasMaxLength(400);
       this.Property(p => p.PacksPerLayer);

3.  Updating the Stored Procedure.

Simply modify the stored procedure directly in the programmability file in MSSQL. To modify the procedure and the new fields on line
284. On execute it updates (CARL this something I’m working on to find out how it woks it doesn’t need deleting just modify and execute)

       p.PacksPerLayer,

After completion of this process we move on to MVC.
Model, View and Controller.

4.  Nop.Web/Models/Catalog/ProductModel.cs

The Model is an object that is passed back and forth between Controller        and View.

public class ProductModel : BaseNopEntityModel
    {
        public ProductModel()

        public int PacksPerLayer { get; set; }



5.  Nop.Web/Controllers/CatalogController.cs

The Controller handles web requests.  It figures out what View to show and creates the Model for it.  It fills the Model with data it gets from the Services.
Below shows Product Details page Controller. That display’s our Data.

//product details page
        public ActionResult Product(int productId)
        {
            var product=_productService.GetProductById(productId);
            if(product==null||product.Deleted||!product.Published)
                return RedirectToAction("Index", "Home");

            //prepare the model
            var model = PrepareProductDetailsPageModel(product);

               //PacksPerLayer
            model.PacksPerLayer = product.PacksPerLayer;



6.  Html (Im creating a view or this but we still can see until done so). Also CSS to last bits of the equation.

Using Razor engine and blocks of code it compiles through source code and Html code to reference display and data functions. @ Routes to the model to display data

HTML
<div class="Packs Per Layers">
                         @T("Layers Per Pallet")<text>:</text>
                         @(Model.LayersPerPallet)
                    </div>
CSS
.product-details-info .overview .PacksPerLayers,
{color:#555;margin-bottom:.3em;font-size:1.1em;}
12 years ago
Thanks a lot for your reply. :) I followed the same steps as you said, but, I couldn't find stored procedure for customer.  do you know where it located?
12 years ago
There isn't for customers I think its just for ProductLoadPage.

Can you go into a little bit more info about what you are trying to achieve?
12 years ago
Hey actually what am trying to do is, I want area code text box beside phone number in billing and shipping address during checkout. Before that I want to add area code text box in register page to input. Later I want this to get retrieve during checkout. Any idea about this?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.