Drupal Association members fund grants that make connections all over the world.
The relationship between bundle displays and bundle products is very similar to the way Commerce treats product displays and products. Fig. 1.0 outlines this relationship. You will note there are two additional levels, Product Groups, and Bundle Items. Product Groups allow us to support product attributes, and bundle items allow us to set pricing per product in the bundle.
Fig. 1.0 Relationship between Bundle Displays and products in the bundle.
Creating Product Bundles
First identify the groups of products that will make up your bundle. Example, if you want to create a bundle consisting of a Polo shirt, Concert Shirt, and CD, then your bundle will have three groups. These groups might look something like Fig. 1.1.
Fig. 1.1. The grouping of products for an example bundle that consists of a Polo Shirt, Concert Shirt and CD. Note that grouping is by product type, and the number of products in a group depends on the number of attributes (e.g. size, color) that product type has.
Now that your bundle groups have been identified, we need to group them together using the ‘Bundle Group’ product type provided by the module (see Fig. 1.2).
Fig. 1.2. Bundle Group product type provided by the Commerce Bundle module.
You will need a Bundle Group product for each of your groups. So for the example we’ll make three: Polo Shirt Group, Concert Shirt Group, and CD Group.
Bundles works off a pricing hierarchy in the following order
- Group Price
- Bundle Item Price
- Product Price
Thus if Group Price is set, all prices below it are ignored, and the line item will be set at Group Price. If Group Price is not set, then Bundle Item Price is inspected, and the logic repeats. This gives you fine grained control to set prices at the product or group level. Currently setting the price of the total bundle is not supported.
Unit Quantity defines the number of products in a group required for a bundle quantity of 1. If, for example, you had a bundle consisting of 100 business cards, and 20 pens, then for the two groups you would set the unit quantities at 100 and 20, respectively. As well, if a customer added 2 of these bundles to her cart she would see a business card line item with quantity 200, and a pens line item with quantity 40 in her cart view.
The Group products we’ve created are shown in Fig. 1.3.
Fig. 1.3. The three product groups required for creating our example bundle (to show the group prices in the product list you simply need to edit the View, add the group price field (arrange it so it's above the default product price), then in Format: Settings set the 'Group Price' column to 'Price').
Creating Bundle Displays
Now we need to create a display for our bundle. Doing this is very similar to how standard product displays work in Commerce (i.e. add a product reference field to a content type). The difference with bundles is that we must make sure the formatter for the product reference field is set to ‘Bundle Add to Cart form’. See Fig. 1.4.
Fig. 1.4. Setting your product reference field formatter to use the Bundle Add to Cart form.
Instead of referencing individual products, you’ll be referencing the product groups we created earlier. The product display defines the bundle at the highest level. Commerce Bundle supports product attributes, thus if a product group in your bundle has 3 attribute fields, then you can expect to see 3 attribute list widgets created on the bundle display for that group. This allows your customers to specify the particular bundle configuration they would like to add to the cart.
Managing Product Bundles in the Cart view
Customers can update bundle quantities, and/or remove bundles in their cart. Changes to bundles are treated as a group, and thus you cannot break a bundle into it’s standalone product components, e.g. if the ‘Remove bundle’ button is clicked, all line items for that bundle configuration will be removed. Fig. 1.5 highlights our example bundle in the cart.
Fig. 1.5. An example cart view containing one standalone product, and one bundle.
Note the quantity forms have been disabled for bundle line items, and instead quantity updates are changed in the bundle control row.