query on ADDING NEW FIELD in database - URGENT

1 2 3 Next
Posted: 2 years ago Quote #61278
Hi,

We have downloaded the NOPCOMMERCE code for testing purpose like checking the features and funcationlities. While testing, we tried adding 1 new field in the databse. We did that through code and deleted the existing DB from local system and re-installed the db. After reinstallation, we start seeing the field which now can be used on further pages.

Our question is: if we buy the code from NOPCOMMERCE and if need to any field or table in the database then also we need to perform the same activitiy. Like deleting the database and reinstalling.

I believe this should not be the case. If we buy the code then we can change anything on front end or back end.

Please suggest.

Regards,
Sunil Aswani
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: 2 years ago Quote #61280
SunilAswani wrote:
if we buy the code from NOPCOMMERCE

nopCommerce source code is available for free

Sure, you can always add an appropriate column to your database manually. In this case you don't have to recreate the database
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Interested in the dedicated Premium support services provided by core developers? Please visit http://www.nopcommerce.com/supportservices.aspx

Best Regards,
Andrei Mazoulnitsyn
Posted: 2 years ago Quote #61912
Hi Andrei

Quick question I know you are busy,

I have added a new feild in the dbo.product.

ALTER TABLE [Nop].[dbo].[Product]
ALTER COLUMN PacksPerLayer nvarchar(400)
GO


In the model created a public String

public string PacksPerLayer { get; set; }

In both ProductTemplate_Grids.chtml

<div class="Packs Per Layers">
                         @T("Packs Per Layers")<text>:</text>
                         @Model.PacksPerLayer
                    </div>

Whilst updating the CSS code appropriately.

In the Product.details.info overview My PacksPerLayer Div is displaying fine on the front end.

But my the data isn't displaying in the table I'm using the number 8 for testing purposes.

I have tested it as Public - decimal, string, Int and bool.

Int displays 0
bool display false
string displays nothing
decimal displays 0

On manually change the sku code in the Db that works fine

I'm hoping you would be able to advise me briefly on this on what I'm missing.

Kind regards

Richard
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: 2 years ago Quote #61944
Are you populating the model from the entity in your controller?  Usually if you add a new field you have to wire that part as well.
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
StackOverflow - http://stackoverflow.com/users/113988/andymckenna
http://bitshiftweb.com - FirstData payment plugin and contract development services
Posted: 2 years ago Quote #61949
Hi

I don't know

I have updated the following but I'm still having the data display issue. It either displays 0 or Nothing?

ALTER TABLE [Nop].[dbo].[Product]
ALTER COLUMN PacksPerLayer nvarchar(max)
GO


NopCore/Domain/Catalog/Product.cs

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

NopData/Mapping/ProductMap.cs

   this.Property(p => p.PacksPerLayer);

In the Web side updated the Stored Procedure... ProductLoadPage

--return products (returned properties should be synchronized with 'Product' entity)
(added)
p.PacksPerLayer

In the Model  I have it as a string

public string PacksPerLayer { get; set; }

View

<div class="Packs Per Layers">
                    @T("Packs Per Layers")<text></text>
                    @Model.PacksPerLayer
                    </div>
CSS etc

I don't know what to write in the controller to be honest.

All help would be highly regarded. Also was it necessary for me to change the CORE area just wondering?? For future reference.

Richard
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: 2 years ago Quote #61982
Yes.  More info here: http://www.nopcommerce.com/docs/73/updating-an-existing-entity-how-to-add-a-new-property.aspx

Simplified explanation of each area:
-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 just a chunk of 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.  

So the part you are missing is that the Core object has the new field and the Model has the new field, but you need to modify the Controller to say, "this field in the Model should be filled with this value from the Core object".  

I believe Product has a ToModel() function that it uses most of the time.  You probably just need to add your field there.
This post/answer is useful
2
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
StackOverflow - http://stackoverflow.com/users/113988/andymckenna
http://bitshiftweb.com - FirstData payment plugin and contract development services
Posted: 2 years ago Quote #62045
Hi Andy

I followed the link the only area as you said missing was the controller I went through the CatalogController.cs

I added the following code

public class ProductModel : BaseNopEntityModel
    {
        public ProductModel()
        {
            ProductPrice = new ProductPriceModel();
            DefaultPictureModel = new PictureModel();
            PictureModels = new List<PictureModel>();
            ProductVariantModels = new List<ProductVariantModel>();
            SpecificationAttributeModels = new List<ProductSpecificationModel>();
            PacksPerLayer = new int();
            
        }

#region Utilities
[NonAction]
        private ProductModel PrepareProductOverviewModel(Product product, bool preparePriceModel = true, bool preparePictureModel = true)

//PacksPerLayer

            model.PacksPerLayer = new int();

[NonAction]
        private ProductModel PrepareProductDetailsPageModel(Product product)

//PacksPerLayer
            
            model.PacksPerLayer = new int();

//product details page
        public ActionResult Product(int productId)

//PacksPerLayer
            model.PacksPerLayer = new int();


I deleted the stored procedure in the MSSQL and re excuted it the new feild is visable but its still displaying as 0 whereas for genric testing purposes I set the colum value to 8.

Kind regards

Richard
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: 2 years ago Quote #62047
Setting model.PacksPerLayer to a new int just initializes it to to 0.  Change that line to

model.PacksPerLayer = product.PacksPerLayer;
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
StackOverflow - http://stackoverflow.com/users/113988/andymckenna
http://bitshiftweb.com - FirstData payment plugin and contract development services
Posted: 2 years ago Quote #62057
Yes

Thank works a charm now I can go through creating all the feilds and work on a strongly typed partial view pop out.

Whilst doing other things.

:)))) Thanks Andy

Until next time - which I know there will be.

Thank you.
This post/answer is useful
0
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
Posted: 2 years ago Quote #62073
I'm glad you got it working.  I got most of the stuff that I've modified in nopCommerce to work by mimicking the code of another area.  The most recent example was learning that the UIHint data tag on a model property will allow you to specify a custom editor.
This post/answer is useful
1
This post/answer is not useful

Please login or register
to vote for this post.

(click on this box to dismiss)
StackOverflow - http://stackoverflow.com/users/113988/andymckenna
http://bitshiftweb.com - FirstData payment plugin and contract development services
1 2 3 Next
nopCommerce on facebook