Sitecore Blog: Getting to Know Sitecore

Extending Sitecore E-Commerce - Order Lines

By Adam Conn, January 26, 2011 | Rating:  | Comments (1)

Sitecore E-Commerce

A couple weeks ago I described how to extend the pricing model used by Sitecore E-Commerce Fundamental Edition.  That was a relatively simple example, because I needed to replace the component that is responsible for calculating a price.  This was a matter of extending functionality.  What about extending the data model?

When you buy a product online, often times additional products are offered to you based on that product.  For example, if you buy a camera you might be offered an extended warranty.  If your order consists of a single camera and a single extended warranty, the relationship is pretty clear and it's probably safe to assume the warranty applies to the camera.

But what if you buy two cameras at once, and you want a 5-year extended warranty on one camera and a 2-year extended warrantry on the other?  In that case, it becomes much more important to be able to associate the camera with its warranty. 

This requires that the data model be extended in order to accomodate the additional information (in this case, the fact that one order line is related to another).  This post explains how to do this using the example of product add-ons.

This is what the finished example should look like:

As I started writing this post it quickly became obvious that a blog post isn't the most effective way to communicate this example.  While no single piece of the example is too complicated, there are many pieces to consider:

  1. Creating new products to represent the add-ons.  For example, products that define different support options (online, phone and onsite) are needed.
  2. Creating a relationship in the product repository.  For example, it needs to be specified that the online, phone and onsite support are available for the D3X camera.
  3. The ShoppingCartLine needs to be extended.  When an add-on is added to a shopping cart, the add-on must be associated with another product.  This information needs to be stored in the ShoppingCartLine.
  4. The ShoppingCartManager needs to be extended.  This is the class that is used to add a product to a shopping cart.  The webshop user interface interacts with this class in order to get a product in the shopping cart.  In addition to knowing which product to add to the cart, this class also needs to know if the product is associated with another product.
  5. The OrderLine needs to be extended.  This represents a product that is a part of an order.  The OrderLine needs be able to express that the OrderLine is associated with another OrderLine.
  6. The OrderLineManager needs to be extended.  This class transforms the contents of a shopping cart into an order.  Since both the ShoppingCartLine and the OrderLine need to be extended, it should make sense that this class needs to be extended as well.
  7. The OrderLineMappingRules needs to be extended.  This class describes where the OrderLine data should be stored.  In this example, an OrderLine becomes a Sitecore item.  Since a new value is being stored on an OrderLine, this new value must be mapped to a field in a data template.  Which means that...
  8. The OrderLine Data Template needs to be extended.  This allows the association of an add-on to a product to be stored in Sitecore.
  9. The presentation components need to be extended.  The presentation control need to display the available add-ons, provide a customer to add add-ons to his cart, etc.

Rather than breaking this example up in a long series of separate posts, I created a guide that explains how to do this.  You can get the document in the SEFE documentation section on SDN (look for the document named E-Commerce Extending Order Lines).  You can get the finished source code from the SEFE Extensions project in Sitecore's Shared Source Library.

And if you have any questions, you can post them in the comments.  Or better yet, in the SEFE discussion forum.

Tags: e-commerce, API

Comments

  • please tell me how to extend SES 2.0 order line

    - Alexey Smoljanko
    May 24, 2013 at 12:02 AM

*{0} must be filled in.
*{0} must be filled in.
*{0} must be filled in.