Documentation
Feedback
Guides
Learning Center

Learning Center
Learning Center
Product page
View in Portuguese
This content was migrated from the VTEX Learning Center and is no longer being actively maintained. For the most accurate and up-to-date information, please check the official documentation.

Introduction

Once the store's homepage is done, we can start working on a new store template: the product page. Product pages are the templates with the most blocks, which makes them highly flexible and customizable.

Product Page

Let's build a minimal product page, with only the bare essentials:

  • images;
  • prices;
  • names;
  • buy button

{"base64":"  ","img":{"width":3054,"height":1226,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":367608,"url":"https://user-images.githubusercontent.com/18701182/69375575-6b632780-0c87-11ea-85d2-41e1e858a33e.png"}}

Product blocks

Unlike content blocks, most product blocks are inserted into a specific context, making them a bit "plug-n-play": placing product images on the product page automatically renders images on that page, the same being true for price and name.

This doesn't mean that these blocks are less customizable, quite the opposite, actually, as we'll soon see.

Activity

Build a product page using the following blocks in product.jsonc and declare it in the store/blocks folder: product-images, product-price, product-name, and buy-button. We expect the structure to contain the following:

  1. A row in store.product;


    _10
    {
    _10
    "store.product": {
    _10
    "children": ["flex-layout.row#main"]
    _10
    }
    _10
    }

  2. That row should have two columns;


    _10
    "flex-layout.row#main": {
    _10
    "props": {
    _10
    "marginTop": 6
    _10
    },
    _10
    "children": [
    _10
    "flex-layout.col#left",
    _10
    "flex-layout.col#right"
    _10
    ]
    _10
    }

  3. The left column must contain a product-images;


    _10
    "flex-layout.col#left": {
    _10
    "children": [
    _10
    "product-images"
    _10
    ]
    _10
    }

  4. The right column must contain the product-name, product-price, and buy-button:


    _10
    "flex-layout.col#right": {
    _10
    "children": [
    _10
    "product-name",
    _10
    "product-price",
    _10
    "buy-button"
    _10
    ]
    _10
    },

In addition, we want:

  1. the right column to be vertically aligned to the center (see the verticalAlign and preventVerticalStretch props in the Flex Layout Column documentation):


    _10
    "flex-layout.col#right": {
    _10
    "props": {
    _10
    "preventVerticalStretch": true,
    _10
    "verticalAlign": "middle"
    _10
    },
    _10
    "children": [
    _10
    ...
    _10
    ]
    _10
    },

  2. the product-price to show the total savings and list price (showSavings and showListPrice):


    _10
    "product-price": {
    _10
    "props": {
    _10
    "showSavings": true,
    _10
    "showListPrice": true
    _10
    }
    _10
    }

After finishing the previous steps, you can search for a product in the search bar, on the top right of the page.

{"base64":"  ","img":{"width":516,"height":71,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":3893,"url":"https://user-images.githubusercontent.com/19495917/90903507-682ad280-e3a4-11ea-9781-77a9b111218b.png"}}

If you are on the appliancetheme account, try searching for a coffee machine, for example:

{"base64":"  ","img":{"width":401,"height":527,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":48853,"url":"https://user-images.githubusercontent.com/19495917/90903699-b049f500-e3a4-11ea-9e3e-6ad5f6a41333.png"}}

When clicking on the second one, the Red Retro Coffee Maker, you'll go to its product page, and you can see the blocks on it.

{"base64":"  ","img":{"width":1637,"height":647,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":461739,"url":"https://user-images.githubusercontent.com/19495917/90905481-9f9a7e80-e3a6-11ea-99c4-6a546e0000a3.png"}}

Note: Some of the products will not have the savings, since there are no discounts based on the list price.

Note: Remember to access the Product Images, Product Price, Product Name, and Buy Button documentation in case you have any questions during your activity.

Answer sheet

See answer sheet for product.jsonc
product.jsonc

_28
// store/blocks/product.jsonc
_28
{
_28
"store.product": {
_28
"children": ["flex-layout.row#main"]
_28
},
_28
"flex-layout.row#main": {
_28
"props": {
_28
"marginTop": 6
_28
},
_28
"children": ["flex-layout.col#left", "flex-layout.col#right"]
_28
},
_28
"flex-layout.col#left": {
_28
"children": ["product-images"]
_28
},
_28
"flex-layout.col#right": {
_28
"props": {
_28
"preventVerticalStretch": true,
_28
"verticalAlign": "middle"
_28
},
_28
"children": ["product-name", "product-price", "buy-button"]
_28
},
_28
"product-price": {
_28
"props": {
_28
"showSavings": true,
_28
"showListPrice": true
_28
}
_28
}
_28
}

On this page