Extending Modules - Best Practices

Topics: Writing modules
Oct 24, 2012 at 8:32 PM

Hi everyone,

I have an etiquette / best practices question to pose to the community. I recently downloaded and have been playing with Bertrand Le Roy's "Nwazet Commerce" module. It is very good. For me, it's a great place to start. It doesn't have all the features that I need, so I need to add more to it.

For my current project, I could just modify the code and be done with it. But I would like to package up my work into my own module and share it with everyone. So my question is this: Should I

  1. Copy out the code that I need but give credit in the documentation to the original developers, OR
  2. Make that Nwazet module a dependency? Ideally I'd like my additions to be in the same admin menu folder as Nwazet. So I'm not sure of the technical difficulties in this option.

Thanks!

Coordinator
Oct 25, 2012 at 6:13 AM

Both are fine, and pull requests enable you to submit your changes back into the original module. But a fork with attribution is fine, really.

Oct 26, 2012 at 1:42 PM

I might also throw in, check the forks on any modules you are looking at. Sometimes others have made a fork to expand on the functionality and you might see what you want is already done.

In this case, I have forked Nwazet.Commerce and added in quite a bit more functionality - here is a link: https://bitbucket.org/ems/nwazet.commerce

It is possible over time that this will make it's way back into Nwazet.Commerce, but even if it doesn't, you can utilize it for your own needs without the need to re-invent.  You could even fork my fork to extend on it if it has enough in there that you find interesting.  Here are some features/expansions I have made on Nwazet.Commerce:

	Nwazet.History:
		Name: Nwazet History
                  Description: Provides order history tracking for Nwazet Commerce (for logged in users who purchase with PayPal)
		Category: Commerce
		Dependencies: Nwazet.Commerce, Orchard.Fields
	Nwazet.RoleAssignment:
		Name: Nwazet Role Assignment
		Description: Provides for the assignment of user roles based on confirmed purchases
		Category: Commerce
		Dependencies: Nwazet.Commerce
	Nwazet.PayPal:
		Name: Nwazet PayPal
		Description: Provides PayPal order clearing and pushing to Nwazet History
		Category: Commerce
		Dependencies: Nwazet.Commerce
	Nwazet.Promotion:
		Name: Nwazet Promotion
		Description: Provides ability to offer promotions by Percentage Discount or Currency Discount
		Category: Commerce
		Dependencies: Nwazet.Commerce, Orchard.ArchiveLater 

Can't wait to see how you are looking to expand Nwazet.Commerce. If I can be of any help on the coding front, let me know.

Feb 5, 2013 at 12:13 PM
What is the situation now concerning these 2 nwazet.commerce projects.
Seema bad idea to have forked in another repository.
Has Bertrand/Spike intergrated the modifications in ems project ?
Feb 5, 2013 at 12:20 PM
Hi csadnt,

I have a pull request out and Bertrand said he would be combining the project into one. It doesn't look like it has been done as of yet though. You can follow the request here: Pull Request

You can encourage the merge, I would love to see it too as I don't want to see multiple feature sets standing alone. I can't do anything more on my end that I know of though I will keep watching.
Feb 5, 2013 at 2:29 PM
ok jao28, thanks, I will follow it. Bertrand is certainly very busy, hope he will accept your pull asap.
Have you merged with its recent modifications ?
Feb 5, 2013 at 2:45 PM
Edited Feb 5, 2013 at 3:11 PM
Hi csadnt & jao28,

I am still working on the fork. Most of the changes that I am making are client-specific. That is, tailoring it to the way they work.

There are, however, and a couple of things that I could merge back. For example, they use Authorize.Net. So I am creating a feature to use that. I could also simply create a new module, but I think a feature makes sense. Also, the stock Nwazet doesn't include a Order or Customer parts. I am creating those plus Address parts for the customer. I can merge those back in. I am also creating a custom ProductController to offer the greatest amount of flexibility in displaying the product catalog.

Would those be of value?

Also, I haven't worked on a whole lot of community project before. So another question that comes to mind is would one A) write/modify the module in such a way as to merge back and then continue modifying for the client or B) merge back only specific files to achieve the desired functionality?
Feb 5, 2013 at 3:09 PM
Jao28,

In what scenario would one user your feature 'Nwazet.RoleAssignment'?

For your feature 'Nwazet.History', is this PayPal-specific functionality or could I modify this to use anything including Authorize.net?
Feb 5, 2013 at 5:06 PM
Samuelshirley20,

I love to hear what you are working on, those sound like EXCELLENT features, will get on and follow those. All of what you are building makes great sense4 to be a module as I can see a number of clients wanting similar features (my module additions were built for a client also but generic enough for reusability).

The one thing I did wrong was change too much without requesting a merge, it would hvae been easier for Bertrand if I had done one feature at a time then request a merge so my recommendation is that you add features for merge rather than a whole bunch of features to be merged. This makes it easier for the original author (Bertrand in this case) to decide what features should be core and what should be left as addons (i.e. I could pull from your source).

Regarding "Nwazet.History", it uses interfaces so it can be used by ANY payment provider, just fulfill the interfaces and it will work for you (I only have fulfilled PayPal at this time but everything was built to stand on it's own with any future payment provider.

The "Nwazet.RoleAssignment" module allows a user to be assigned into a role as a result of buying something online. I use it like this, client wants to sell electronic content / access to a certain part of the site. So the user purchases this product and when payment from PayPal clears, they are automatically put into this "Orchard Role" which provides them the extra access they need to visit a page or download an electronic product. Does that make sense? It is dependent on the "History" module and a user must be logged in to use it as it assigns the role on the username.

You can tap into almost all of the code I have as I use interfaces a lot as I figure you may want to inject your own business requirements.

Love to hear of the things you are doing and can't wait to test them out.
Feb 5, 2013 at 5:26 PM
Edited Feb 5, 2013 at 5:27 PM
Good to see this activity.
I let some comments in this thread, sorry http://orchard.codeplex.com/discussions/432032
Feb 7, 2013 at 10:23 AM
Hello jao28,
I just noticed that product recommendations on the end of shoppingcart are listing products already in the shoppingcart, if they are marked as always promote or is it a bug I introduced merging ?
Feb 7, 2013 at 3:10 PM
Hello csadnt,

It isn't a bug, you want to change your "Recommendations for this product" to be: "Recommend if Not in Cart" or "Recommend if Not in Cart and Not Purchased". That way they won't be recommended if they are already in the persons shopping cart. Let me know how that works out.
Feb 7, 2013 at 3:19 PM
Ok, I realized this sometimes after posting, sorry :)
I am on ProductRecommendations now, I see that the display shape is not created in the driver, it relies on product, ?
Feb 7, 2013 at 3:24 PM
I am not looking at the code, but that makes sense to me. The product already knows how to build itself so my Product Recommendations driver doesn't re-invent the wheel, it only builds up a list of recommended stuff. As I recall it is even more flexible in that it is looking for anything with a Product Part so you could technically create multiple content types that each have Product Part. From there, they could have different fields / parts associated with them. For example, let's say you are selling flowers and trees, you could have a "Tree Product" and a "Flower Product". As long as they both have the Product Part, my tool doesn't care, you can recommend any of these different content types. When the list renders, it will display properly because the shape is driven by the drivers already defined. This provides maximum flexibility and minimal code duplication - does that make sense?
Feb 7, 2013 at 3:36 PM
Yes this is an interesting feature.
Couldn't we have same feature with a Contentype ProductRecommendation, containing the ProductPart ?


I am integrating in a dedicated theme based on bootstrap, and I have huge work on the styling totally different.
My problem is on display, it is taking too much space now (I am on the begenning), may be I will try to add a product.Summary.chtmsl to have a reduced view.
I have another problem with the shoppingcart, when adding a product, the cart is automatically displayed, and actually I don't understand the orders of the shapes/models called to have it (->css problems due to missing includes)
Feb 7, 2013 at 3:41 PM
Ah yes, I use Placement.Info to trim down what I don't want though let me know how a summary view works out for you - that might also be the ticket.

I don't think we could have it wrapped as a "Content Type of ProductRecommendation" as it uses a native Orchard List shape and that doesn't contain ContentTypes - think you will need to use another technique to gain control of styling.

If you don't want the "Cart" automatically displayed, just don't have the "Cart" Widget on the same page - no "Cart" Widget, no display and the user will need to go to their shopping cart to see the information (url is /cart) and cart history (/cart/history) - I just throw a cart icon in the top of the site so it is on every page.
Coordinator
Feb 10, 2013 at 6:05 AM
Just so you know, the merge will happen. It's just that I'm currently working on some new features of my own for Nwazet.Commerce (in particular, Stripe support), and I'm finishing this before I take the pull requests.

Thanks so much for contributing...
Feb 26, 2013 at 2:38 AM
I really think that Nwazet is deserving of it's own discussion board.

Can we create a Codeplex page for it so discussions can be had?
Feb 26, 2013 at 2:41 AM
Also, I decided in the end not to fork the code. I cloned the project and I will work on my features within that and when done will contribute back.

I plan on working on the Authorize.Net feature, adding a Client/Customer part, adding an Order part, and a WebShop controller (not necessarily that name) to allow for fully customizable displaying of the product catalog. I haven't decided yet whether I am going to rely on Taxonomy or roll my own.
Coordinator
Feb 26, 2013 at 6:21 AM
Just so you know and we don't duplicate efforts, I'm implementing Stripe, and as part of that I will implement orders. I won;t do customers yet however, and I've given up on Authorize.Net, to which I prefer Stripe.
Feb 26, 2013 at 7:21 AM
Edited Feb 26, 2013 at 7:35 AM
I am working on an extension which manages pricelists, currencies and Money.
Its at 80% fonctional now and I will push it on Bitbucket.
I have managed to create another module, dependant from nwazet, and not work directly on it.
May be working on different project dependant of Nwazet is the best approach ?

We know that the extension code is valid until a nwazet revision but how to check this ?


Roughly:
A PriceList has a stardate, endate and active flag.
A CurrencyPart is based on an internal currency which contains all std iso codes and precision, from .Net internals, valid currencies goes in DB as a part, site may be mono or multi currencies.
Money is an extension that allow managing correctly decimal according each money (I don't thank NHibernate which is unable to store something based on 2 ints and a string). Each money has a currency and coherence control is made on each operation, there are repartition function managing ideally rounding. Code from an opensource project.

The important object is the Product-PriceList-Currency (Part) which is unique and contains a Price (Money) for a PriceList, a Currency and a Product.
The Price property of Product is no more used (driver overriden)
There is a new selector which allows user to choose its Pricelist and have adapted pricing.
I have added an Admin Menu extension to manage currencies/ pricelist and ProductPricelist.
I also added a global Commerce Site Settings which allow to select:
  • Mono or multi currency
  • Default Currency
  • List of valid price lists
  • List of valid shopping (invoicing) countires
  • List of valid Shipping Areas
  • Max order Amount
  • Min Order Amount
  • flag to allow CB transaction
  • global e-commerce Active switch
Let me know if interested I will push it sooner, being busy now on some implementation.

May I ask a question, on the Spyke's Skywalker Blog, there are some parts similar but some of thme are not includes, what is the history and status.
Coordinator
Feb 26, 2013 at 7:30 AM
Sounds nice. I don't intend to implement any of those, so that looks nicely complementary to my own efforts.
Feb 26, 2013 at 7:32 AM
Ok, I will push it next week-end and let you know. Thanks.
Feb 26, 2013 at 1:44 PM
I haven't heard of Stripe before now. I REALLY like it! I'm looking forward to it's completion in Orchard!! I'll use it for my own website. :-)

My client uses Authorize.Net, so I need to finish it. I'll let you know when it's done.

Bertrand, what do you think about a Codeplex page for Nwazet? I think it's a project that deserves it's own discussion board.
Feb 26, 2013 at 2:10 PM
Bertrand, If you're holding off on Customers for now, I'll finish that.
Coordinator
Feb 26, 2013 at 4:01 PM
OK. Unfortunately, Bitbucket, which is where the source code is, doesn't have forums. I will probably, however, create a forum using Nick's module on my own web site. I don't know when, but I'll open a Nwazet.Commerce section there when it exists.
Mar 7, 2013 at 5:21 PM
Hey Bertrand,

Thanks! Looking forward to having a forum to discuss this great project.

Since we're discussing Nwazet here, I have a question regarding how you display the products. In the Product Admin section there are four command links, one of which is 'View'. The href url for my particualr product is "http://orchardshop.local/stone-chandelier-earrings". On first glance I'd day this is the result of a projection or something. But it doesn't look like it is.

How are products displayed to the user (outside the admin section)? Via a controller or projection? I don't see any evidence of these though.
Coordinator
Mar 7, 2013 at 7:56 PM
mm, no, products are just regular content items. I'm not sure what you mean. There is nothing specific about displaying them except for the specific parts that the module introduces.
Mar 14, 2013 at 9:45 AM
Edited Mar 14, 2013 at 9:46 AM
Hello,
I installed my work on bitbucket, here
https://bitbucket.org/csurieux/datwendo.commerce/overview


Working:
currencies,
money (need more work but every double has been transformed in Money type)
price lists
customers (with an open question on how to deal with existing site users and transform them as customers)


also managed to include some adds from https://bitbucket.org/ems/nwazet.commerce/src/496500e56c9f?at=default which where made directly on Nwazet causing pb until the pull is committed.
included and adapted recommendedProducts
partially included userpromotions (work in progress)


Here they are in a separate module which will necessitate the actual version of Nwazet to work.
Hope to have a working sample next week.



Thanks for feed back.
CS
Coordinator
Mar 14, 2013 at 5:52 PM
Nice. thanks.