Book Image

Building E-commerce Sites with Drupal Commerce Cookbook

By : Richard Carter
Book Image

Building E-commerce Sites with Drupal Commerce Cookbook

By: Richard Carter

Overview of this book

<p>Get to grips with Drupal Commerce, the new ecommerce framework based on the Drupal CMS , one of the most popular and powerful open source content management systems available.<br /><br />"Building E-commerce Sites with Drupal Commerce Cookbook" takes you through the installation, configuration, and customisation of your Drupal Commerce store. With clear, practical recipes with plenty of screenshots and tips this book will help you build attractive and profitable eCommerce sites.<br /><br />This book starts by showing you how to install and configure your Drupal Commerce store. Once your shop is up and running, you’ll then learn how to customise and optimise it to make it stand out and display your products better.<br /><br />Going further into customisation, you will learn to add custom product types before creating a stylish new Drupal theme for your store. Packed with tips, this book will also help guide you through common problems, as well as optimising and managing your store on a day to day basis.<br /><br />"Building E-commerce Sites with Drupal Commerce Cookbook" will guide you through everything you need to know to get your online store up and running and selling your products, with easy step-by-step guides and screenshots to help walk you through everything.</p>
Table of Contents (17 chapters)
Building E-commerce Sites with Drupal Commerce Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a t-shirt product type


As you have seen, Drupal Commerce provides a lot of flexibility when it comes to products. By adding additional fields to your installation's product's display, you can customize your store to support a custom "t-shirt" product type with size and color attributes. In this recipe, you will be learning about creating a t-shirt product type for your Drupal Commerce store.

Getting started

Before you begin, it's a good idea to have a list of the attributes that you want to have for the custom t-shirt product type. This example will add the following fields:

  • Size: From a selection of small, medium, and large

  • Color: From a selection of blue, red, yellow, and purple

How to do it...

Log in to your Drupal Commerce administration panel, navigate to Products | Variation types, and follow these steps to create a custom product type for t-shirts in your store:

  1. Click on the Add product variation type button:

  2. Give the new product type a title by entering a suitable value in the Name field:

  3. Leave the Default product variations of this type to be saved as new revisions when edited checkbox checked, if you want Drupal Commerce to save a new revision of the variation each time you edit it.

  4. Check the Create matching product display type checkbox if you want to create a Drupal Commerce product display type to display the products created using this product variation type.

  5. Click on the Save and add fields button:

  6. You will now see the Product variation type saved message, and a list of fields associated with your new t-shirt product type:

  7. Using the Add new field block, you can begin to customize this product type.

  8. Populate the Label field with T-shirt size, and then select List (text) from the Type of data to store field, leaving the Form element to edit the data field as Select list:

  9. Now click on Save, and you'll be presented with the Allowed values list field on the Field settings tab; enter one value per line, using a vertical pipe (|) to separate a value from a label. For example, enter the following:

    Medium-sized t-shirt | Medium

    Entering the preceding value will present the customer with the option of Medium on the frontend of your store, while internally in the Drupal Commerce administration panel it will appear as Medium-sized t-shirt. The label is optional, so you can just enter one value per line if you prefer. The settings in the example are as follows:

    • Small

    • Medium

    • Large

    The preceding values means that you will see the relevant label (that is, Small, Medium, or Large) displayed both in the Drupal Commerce administration panel and as a customer on the frontend of your store. This system means you can provide your customers, with slightly different information to help them make an informed choice about the product they're buying.

  10. Click on the Save field settings button to save your changes.

  11. Leave the Default value set as None to prevent customers from ordering the wrong sized t-shirt:

  12. Check the Attribute field settings checkbox so it is enabled, which allows the dropdown to be shown on the "add to cart" features of Drupal Commerce, so customers can pick their t-shirt size:

  13. Leave the Number of values field set to 1 in the T-shirt size field settings block (you only want customers to pick a t-shirt of one size), and click on the Save settings button again:

  14. You'll be returned to the Manage fields tab, where you can repeat steps 3 to 13 to add a color attribute for your t-shirts.

  15. Once you've done that, you should be able to see the new T-shirt colour field listed in the Manage fields tab:

  16. Your new product type is now ready, and you can add products of this type. Navigate to Products | Add a product.

  17. Next, select the T-shirts link that will appear in alphabetical order at the bottom of the list:

  18. Populate the form that appears next, entering a SKU, Title, and Price for the product and selecting the T-shirt size and T-shirt colour values:

  19. Ensure that the Status field is set to Active so that you (and the customers on your store) are able to view the products.

    Note

    Note that store administrators will still be able to view disabled products.

  20. Click on the Save variation button, and add more products for each size/color combination that your store are available in your store for selling.

  21. Now navigate to Store settings | Variation types, and select the manage fields option for the Tshirts content type that you created in the previous steps:

  22. That's it! Your t-shirt product type is up and running.

How it works...

Drupal Commerce allows you to add your own custom fields to product types so that you can assign your own attributes to different types of products within your store. So, using the preceding method, your store could sell t-shirts using a t-shirts product type that allows customers to select the size and color of their t-shirt. It could also sell teapots using a teapot product type, and allow customers to pick the capacity of the teapot they are buying instead.

The new t-shirt product type that you just created will display the products to your customers in a similar way:

Note the drop-down list that allows customers to pick their preferred size of t-shirt. If you change this to Small, the values that are different in the small t-shirt product variation will change too:

In particular, you can see that the product image has changed, and the price is updated.