Commerce Module Tuesday: Commerce Product Add-on
Welcome to another Commerce Module Tuesday! Today we are looking at Commerce Product Add-on, maintained by Matt Robison who is the Vice President of Louisville Web Group. While I was at Drupalcon Portland, I was approached by two different individuals looking to do something that this modules makes very easy: Add a product as a checkbox on the add-to-cart form for another product.
How simple is it? Fantastically simple. All you need to do is add an entity reference field, target the product type you want to have as “add ons” and boom! you have a set of products that are displaying within the add-to-cart form. Matt has done a great job at making something so powerful exactly that easy. Make a donation product for your favorite charity and allow your users to choose a donation before adding to cart. Or perhaps you are selling event tickets and would like to add on an inexpensive training the day before.
Enabling the module
Getting this module up and running with a bare-bones Drupal Commerce install was as easy as enabling the module and making sure you have the entityreference field installed (most sites will have this already installed). There isn’t a configuration screen for the module in general, but it does enhance the entity reference field and adds a display format for “addons”
Adding a Product Type
Go to admin/commerce/products/types/add (standard Commerce), or admin/commerce/config/product-variation-types/add (Commerce Kickstart 2). Call it “Donations” (or anything you want). Add two products with different prices. admin/commerce/products/add
Adding a Field
Go to the product type (not product display) that you want to have access to addons. Choose to add an “Entity Reference” field. You’ll want to change “node” to “Commerce Product”. Pick the bundle “Donations” or whatever you chose to call it.
Edit your product
Edit your product to reference your addons, and then view your final product and the checkboxes. Note that the design could definitely use some CSS love to make it look a little more fancy.
Changing the Display Format
Let’s simplify the experience a bit by tweaking the display of our addons and our products that display them. View the final result by going back to your product.
Comments or thoughts on what Commerce Module we should feature in next week’s Commerce Module Tuesday? Let us know in the comments!