Custom relational data for a product

TheTheraghaut
Visitor
1 0 2

This is quite a head-scratcher.

 

I'm building an e-commerce website for a bookstore. A product (i.e. a book) has additional fields. One such field is the "author". An author can have multiple books. A book can also have multiple authors. Essentially, it's a many-to-many relationship in a relational database system.

 

When a user clicks on a book, it should display all of the book's authors. An individual author should have a clickable link to see other books (products) written by the same author.

 

Images attached for better explanation.

 

How can I produce this many-to-many relationship in my Shopify storefront? This seems like a very common scenario for a typical online store. I would be VERY surprised if Shopify couldn't handle the above mentioned use case.


example-1.png

example-2.png

example-3.png

Replies 6 (6)

Rouz
Shopify Partner
6 0 0

I have the same question. Any insights on this topic?

Cristina_92
Shopify Partner
41 0 15

Hi @Rouz ! You can do it using Tags.

 
Please read our article about this topic.
ISBNExpress: Books Importer - import books by ISBN into your bookstore.
Rouz
Shopify Partner
6 0 0

Hi Cristina, thanx for your comment. It was really useful.

Now our products have (besides authors) also other many-to-many relations. So since tags would be used to store authors, are there any other fields I could use for the other relations?

 

Cristina_92
Shopify Partner
41 0 15

Hi Rouz,

 

If you'd like to attach a list of values to a product, you'd have to create a custom field: text as a list custom field type.

 

Screenshot 2023-11-28 at 19.58.15.png

The only problem with custom fields is that they are not searchable or linkable.

 

Thank you.

ISBNExpress: Books Importer - import books by ISBN into your bookstore.
Rouz
Shopify Partner
6 0 0

The fields not being searchable or linkable indeed is a problem.
We need the same kind of behavior like we had with the authors.

I wonder if there is a solution?

I heard you could create an app that stores these kind of relations in the database. But then I don't know if and how it is possible to pass the data to the frontend, as you don't want to make 2 different requests

Cristina_92
Shopify Partner
41 0 15

Hi Rouz,

 

I'm not sure if there is a good solution other than using tags.

 

But a workaround could be to store the list of values as comma separated values in the vendor or product type fields (which are linkable and searchable): for example "value1,value2,value3". Then split these values using custom liquid code when displaying them on the storefront.

 

 

ISBNExpress: Books Importer - import books by ISBN into your bookstore.