Skip to content

Commit

Permalink
feat: add groupBy prop in recommendation shelf (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
iago1501 authored Mar 21, 2024
1 parent 164a8f1 commit d62ab5a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- GroupBy prop in `shelf.relatedProducts`

## [1.47.4] - 2023-06-30

### Fixed
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Now, you can use all the blocks exported by the `shelf` app. See the full list b
| Prop name | Type | Description | Default value |
| - | - | - | - |
| `recommendation` | `enum` | Type of recommendations that will be displayed on the shelf. Possible values: `similars`, `suggestions`, and `accessories` (these depend on the product information given in the Admin Catalog); and `view`, `buy`, and `viewandBought` (these are automatically generated according to the activity of the store). | `similars` |
| `groupBy` | `enum` | Defines if you are ot nog going to group your recommendations by: `PRODUCT` (only display individual products and not SKUs, limited by 12 products) or `NONE` (if you want to display all registered SKUs, limited by 50 products). | `PRODUCT` |
| `hideOutOfStockItems` | `boolean` | Whether out of stock items should be hidden: (`true`) or (`false`). | `false` |
| `productList` | `ProductListSchema` | Product list schema. See `ProductListSchema`. | - |

Expand Down
4 changes: 4 additions & 0 deletions messages/context.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
"admin/editor.relatedProducts.accessories": "admin/editor.relatedProducts.accessories",
"admin/editor.relatedProducts.viewAndBought": "admin/editor.relatedProducts.viewAndBought",
"admin/editor.relatedProducts.suggestions": "admin/editor.relatedProducts.suggestions",
"admin/editor.relatedProducts.groupBy.title": "admin/editor.relatedProducts.groupBy.title",
"admin/editor.relatedProducts.groupBy.description": "admin/editor.relatedProducts.groupBy.description",
"admin/editor.relatedProducts.groupBy.product": "admin/editor.relatedProducts.groupBy.product",
"admin/editor.relatedProducts.groupBy.none": "admin/editor.relatedProducts.groupBy.none",
"store/shelf.title": "store/shelf.title",
"admin/editor.tabbed-shelf.title": "Component title",
"admin/editor.tabbed-shelf.description": "Component description",
Expand Down
4 changes: 4 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
"admin/editor.relatedProducts.accessories": "Accessories products",
"admin/editor.relatedProducts.viewAndBought": "Who saw this, also bought...",
"admin/editor.relatedProducts.suggestions": "Suggestions",
"admin/editor.relatedProducts.groupBy.title": "Group by",
"admin/editor.relatedProducts.groupBy.description": "Group recommendation list",
"admin/editor.relatedProducts.groupBy.product": "Products",
"admin/editor.relatedProducts.groupBy.none": "Do not group",
"store/shelf.title": "Best Products",
"admin/editor.tabbed-shelf.title": "Tabbed Shelf",
"admin/editor.tabbed-shelf.description": "Tabbed Shelf featured product module",
Expand Down
4 changes: 4 additions & 0 deletions messages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
"admin/editor.relatedProducts.accessories": "Productos de accesorios",
"admin/editor.relatedProducts.viewAndBought": "Quien vio esto, también compró ...",
"admin/editor.relatedProducts.suggestions": "Sugerencias",
"admin/editor.relatedProducts.groupBy.title": "Agrupar",
"admin/editor.relatedProducts.groupBy.description": "Agrupar lista de recomendaciones",
"admin/editor.relatedProducts.groupBy.product": "Productos",
"admin/editor.relatedProducts.groupBy.none": "No agrupar",
"store/shelf.title": "Mejores Productos",
"admin/editor.shelf-properties.title.title": "Título",
"admin/editor.shelf-properties.title.description": "Título del estante",
Expand Down
4 changes: 4 additions & 0 deletions messages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
"admin/editor.relatedProducts.accessories": "Produtos de acessórios",
"admin/editor.relatedProducts.viewAndBought": "Quem viu isto, comprou também...",
"admin/editor.relatedProducts.suggestions": "Sugestões",
"admin/editor.relatedProducts.groupBy.title": "Agrupar por",
"admin/editor.relatedProducts.groupBy.description": "Agrupar listas de recomendações",
"admin/editor.relatedProducts.groupBy.product": "Produtos",
"admin/editor.relatedProducts.groupBy.none": "Não agrupar",
"store/shelf.title": "Melhores Produtos",
"admin/editor.shelf-properties.title.title": "Título",
"admin/editor.shelf-properties.title.description": "Título da vitrine",
Expand Down
16 changes: 15 additions & 1 deletion react/RelatedProducts.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const fixRecommendation = recommendation => {
const RelatedProducts = ({
productQuery,
productList,
groupBy,
recommendation: cmsRecommendation,
trackingId: rawTrackingId,
hideOutOfStockItems,
Expand Down Expand Up @@ -64,8 +65,9 @@ const RelatedProducts = ({
return {
identifier: { field: 'id', value: productId },
type: recommendation,
groupBy,
}
}, [productId, recommendation])
}, [productId, recommendation, groupBy])

if (!productId) {
return null
Expand Down Expand Up @@ -128,6 +130,7 @@ RelatedProducts.defaultProps = {
...ProductList.defaultProps,
titleText: 'Related Products',
},
groupBy: 'PRODUCT',
hideOutOfStockItems: false,
}

Expand Down Expand Up @@ -158,6 +161,17 @@ RelatedProducts.schema = {
'admin/editor.relatedProducts.suggestions',
],
},
groupBy: {
title: 'admin/editor.relatedProducts.groupBy.title',
description: 'admin/editor.relatedProducts.groupBy.description',
type: 'string',
default: RelatedProducts.defaultProps.groupBy,
enum: ['PRODUCT', 'NONE'],
enumNames: [
'admin/editor.relatedProducts.groupBy.product',
'admin/editor.relatedProducts.groupBy.none',
],
},
productList: ProductList.schema,
hideOutOfStockItems: {
title: 'admin/editor.shelf.hideOutOfStockItems',
Expand Down
3 changes: 2 additions & 1 deletion react/queries/productRecommendations.gql
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
query ProductRecommendations(
$identifier: ProductUniqueIdentifier
$type: CrossSelingInputEnum
$groupBy: CrossSelingGroupByEnum
) {
productRecommendations(identifier: $identifier, type: $type)
productRecommendations(identifier: $identifier, type: $type, groupBy: $groupBy)
@context(provider: "vtex.search-graphql") {
cacheId
productId
Expand Down

0 comments on commit d62ab5a

Please sign in to comment.