How to - extending nopCommerce (1.X versions)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
It seems there has been quite a few posts on here about how to extend nopCommerce since we switched to using Entity Framework.

I have blogged about extending nopCommerce covering

1) adding a new property to an existing entity
2) adding a new entity

You can read the post at http://blogs.planetcloud.co.uk/mygreatdiscovery/post/How-to-extend-nopCommerce.aspx

Andrei, perhaps you can put this as a sticky?

UPDATE:
This article is about extending nopCommerce 1.80
13 years ago
Ben,

Thanks. Very good article
13 years ago
Thanks, for this. Ive seen  some topics about this which I didn't understand..
Now it makes things readable ;)

Q.
Isn't there a simple function to create a class from the table?

Q.
Why did nop use all fields in the create, ... functions? backwards compatibility? Can't they add an overload later on?
13 years ago
ajhvdb wrote:
Thanks, for this. Ive seen  some topics about this which I didn't understand..
Now it makes things readable ;)

Q.
Isn't there a simple function to create a class from the table?

Q.
Why did nop use all fields in the create, ... functions? backwards compatibility? Can't they add an overload later on?


1) Yes there are tools out there that can do this (for example CodeSmith). However, since I always start with my domain, this isn't much benefit. I would like to see use EF code only (lose the edmx) in which case we can generate the database from our model.

With all that said, creating a normal class only takes 30 seconds or so.

2) If you're talking about the existing methods, then yes you could add yet another overload, but for me this is code smell and should only be done if you have a default value for your new property (in my example this wouldn't have made sense since we only call the update/insert methods from the CategoryInfo control anyway) As far as passing in variables, if it's a new entity, I would always chose to pass in the domain object rather than have constructor soup. It gives you much greater flexibility should you ever change your entities.
13 years ago
Thank you for this artical.

To add access sp throug asp.net4 ,consider this link http://weblogs.asp.net/kencox/archive/2009/11/25/using-a-stored-procedure-in-entity-framework-4.aspx
13 years ago
I would not recommend using stored procedures. We are trying to move away from them completely.
13 years ago
I have added the FAQ table to the model and now my Namespaces seem to be all messed up.  'Ambiguity between Business logic and Data.....' I followed the above article closely.  I am using VS2010 and  SQL Server 2008 R2.

Is there a specific way to rebuild after changing the edmx?
13 years ago
please help me with this - https://www.nopcommerce.com/boards/t/6968/i-need-help-in-adding-extra-product-fields-in-database.aspx
13 years ago
super wrote:
I just replied to that, and was coming here to mention my post.  I added some info that wasn't obvious from the original tutorial, and perhaps it could be added to it:

How it works - the fact that your reopening a 'partial' class.

The paths to the Object, ObjectManager, and NopModel.edmx files.  I managed to find them all via search, but it would be nice if they were mentioned in the article.

The article also doesn't seem to mention doing the assigns in the insert/update methods (although that should be obvious to most).

It's a great article, and I thank you for it.  I'm not criticizing it, just trying to help you improve it.

ps: If I got anything wrong in the other thread, please point it out, as I'm quite new myself.
13 years ago
aGorilla,

I explain at the start of the article that I am extending the partial class:

"In this example, I’m going to add a new property “Stylesheet” to my categories, that allows me to assign a specific CSS style sheet to each category.
So to begin with we should add our property. Rather than adding the property to the existing Category.cs file, I recommend you keep your extensions separate. Since the entity classes in nopCommerce are all partial classes, we can put our extension in a separate file.

We create our Category extension class in our extensions directory. We need to make sure that it sits in the same namespace as the existing category class so that the two are compiled together:"


Super,

If you follow the concepts of the article you should not have any problems extending one of the existing entities. I had a quick look at your post and you mentioned 1.4. Just to clarify this applies to 1.7 onwards (using entity framework). As aGorilla commented on your post, if you are extending an existing class (i.e. adding new fields to the table) then you need to make sure your class name is the same, is partial and is in the same namespace. Also you should update the existing insert/update methods to take in the extra parameters (again covered in my article).

If you are adding a new entity  you can take a more domain driven approach and just pass in the object itself (we will be using this approach in 1.9).

axsbrad,

If you are getting errors about "Ambiguity between Business logic and Data...." then it sounds like you have turned on code generation on the edmx. We are using POCOs in nopCommerce so when you "update model from database" this does not actually generate the classes. We then use NopObjectContext to map our POCO classes (like I do in the second part of my article).

Hope this helps.

Ben
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.