#Hero Products filter from Products collection

5 messages · Page 1 of 1 (latest)

jagged pecan
#

Hi. I'd like to select Hero Products from a Products collection to render to a Hero Products page (1 product from each category displayed as a block on the home page).
I've created a Products and Categories collection, how do I go about creating a Hero-Products collection & block that selects 1 product from each category?

Figma: https://www.figma.com/file/dnMTMTXcZRMDXgOLPIXObM/Melex?type=design&node-id=0-1&t=zhDZFIAvEWTIyoQu-0
Repo: https://github.com/taunhealy/Melex_Mono_1

Products collection:

import { slugField } from '../../fields/slug'

export const Products: CollectionConfig = {
  slug: 'products',
  admin: {
    useAsTitle: 'title',
  },
  fields: [
    {
      name: 'title',
      type: 'text',
      required: true,
    },
    {
      name: 'description',
      type: 'text',
      required: true,
    },
    {
      name: 'priceJSON',
      label: 'Price JSON',
      type: 'textarea',
    },
    {
      name: 'categories',
      type: 'relationship',
      relationTo: 'categories',
      hasMany: true,
      admin: {
        position: 'sidebar',
      },
    },
    slugField(),
  ],
}
GitHub

Contribute to taunhealy/Melex_Mono_1 development by creating an account on GitHub.

royal ravine
#

@jagged pecan did you figure this out

jagged pecan
#

Not yet, haven't tackled it yet. I guess create a collection Hero Products and have it relate to Products to select the heroes, then use front-end logic within a block to render the hero products.

If you're unsure of how blocks work, search the community-help forum and you should find the logic there

jagged pecan
#

I don't know if blocks is even necessarty, on second thoughts. You could just fetch the data from the Hero Collection and render a component to that page, as far as I know. Sorry I'm inexperienced, I can't be of much help.

#

When I've finished it I'll share the repo link.