In this video, we will create a content type for products that are for sale. It will have fields for product name, description, tags, image, availability and price and we'll classify products based on men's, women's and children's departments. So before we create the content type, let's create a vocabulary for our departments.
Create Taxonomy Terms
- Go to "Structure => Taxonomy => Add vocabulary" (admin/structure/taxonomy)
- Name: Department
- (Save)
Add terms
- Click "add terms" for Department
- Name: Men's
- (Save)
- Name: Women's
- (Save)
- Name: Children's
- (Save)
Create Content Type
Now, we'll create the content type for our products.
- Go to "Structure => Content types => Add content type" (admin/structure/types/add)
- Name: Product
- Description: A product that is for sale.
- Submission form settings
- Title field label: Product name
- Publishing options
- [ ] unchecked "Promoted to front page" (We don't want the content to automatically display on the homepage)
- (Save and add fields)
By default, the “Product” content type only has Product name and body fields. We need additional fields for taxonomy terms, image, availability and price. Let’s add those now.
Add existing field:
- Label: Department
- Field to share: Term reference: field_tags (Tags)
- (Save)
- Vocabulary: Department
- (Save Settings)
Add new field:
- Label: Product Image
- Field type: Image
- Widget: Image
- (Save)
- (Save field settings)
- (Save Settings)
Add new field:
- Label: Availability
- Field type: Boolean
- Widget: Check boxes/radio buttons
- (Save)
- Field Settings
- On value: Available
- Off value: Out of stock
- (Save field settings)
- Product Settings
- [x] Required field
- Default Value
- [x] Available (Sets the default value as "Available")
- (Save Settings)
Add new field:
- Label: Price
- Field type: Decimal
- Widget: Text Field
- (Save)
- (Save field settings)
- Product Settings
- [x] Required field
- Prefix: $
- (Save settings)
Then, we will delete the Body field, and create a Description field.
- Click “delete” next to “Body”
- (Delete)
Now, to add the Description field:
Add new field:
- Label: Product Description
- Field type: Long text and summary
- (Save)
- (Save field settings)
- (Save settings)
Now, I’ll rearrange the fields by dragging them to the following order:
- Product name
- Product Image
- Price
- Availability
- Product Description
- Department
- (Save)
Create Content
Finally, let’s create some content.
- Go to "Content => Add content => Product" (node/add/product)
- Product name: Product #1
- Product Image
- Choose File: Image #1
- (Upload)
- Price: 10.00
- [x] Available
- Product Description : (Lorem Ipsum)
- Department: Men's
- (Save)
(I'll go ahead and create 5 more products just like this with various prices, availability, departments and images.)
Alright, I've got my six products created. In the next video, we'll create a view that will display a teaser of each of these products on a single page.