Child related to multiple parents

Hi,
I am working on a shop in Kirby. I am pretty new to Kirby but I love it so far.
I am building a shop, based on your starter kit example. The shop will have multiple categorie pages and products.
This is the layout currently in the panel to give you an idea.

The problem I have, is the url flow.
One product can be related to multiple categories. Therefor I have my category pages and in the product you can select multiple categories with tags. This works, but the ULR of course is like
domain/categories/shop

The flow of the pages is supposed to be:

  • Shop page: Categories
    Showing all categories with an image :heavy_check_mark:

  • Shop page: All products
    When you click on one category you will go to another shop page where you will see all products with a preselected tag
    Showing all Products with a filter on top to select the different categories (depending on the category the user clicks (in the screen before) this tag is preselected :heavy_check_mark:

  • Shop page: Product
    And if you press your product you will go to your product.
    Showing the product that the customer can buy the product :heavy_check_mark:

My problem is, that the category page and the all products page are on the same level, otherwise I need a subpage in each category. And the worst, all products can be in multiple categories as well.
In the panel I use tags in the product to assign them to the category. Which is working great. :heavy_check_mark:

All this is working individually but what I want:

My pages should have the following url scheme:

  • Homepage
  • Homepage/Shop (Category Page with images)
  • Homepage/Shop/All Products (All Products with preselected Category)
  • Homepage/Shop/All Products/Selected Product (Product Page to buy the Product)

Right now they are all at:

  • Homepage/Shop/Categories
  • Homepage/Shop/All Products
  • Homepage/Shop/Product

I have not really an idea how to solve this, in a way that it is easy for the customer and for the client to set up the products, categories and recreate/add/change the pages.
Any help and or ideas are appropriate.

Cheers

There are different ways to do that.

I probably wouldn’t create the categories as pages.

If you have a shop page, all products could be children of this shop page (or of a separate products page but the question is if this is really necessary.

You can define the categories in a structure field in the shop page blueprint, then assign these to your products. This structure field can have subfields for the title, image, description.

On the shop page, you output the categories from the structure field.

So the structure would look like this:

content/
  - home/
  - error/
  - shop/
    - product-a
    - product-b

When user click on a category, the URL changes to shop/category/product-a. This URL is handles via a route that returns the shop page with a filter parameter:

Thanks for the super quick answer. The structure is a really good idea and I like it more then the child pages. I overlooked the structure field.

For the routing I will try to find my way. I will basically do it like the routing example but instead of removing a parent, I will add a parent? Is this how it works?

Yep, exactly. See how far you get and if you get stuck, we are here to help

1 Like

I got most of it to work - thank you. The routing made the trick. But I have more questions regarding this topic.

  1. Breadcrumbs do not follow this rule, do they? Or is there a way to configure it somehow?
  2. The same question basically, for the sitemap.xml, I need to put the logic inside the virtual page route to change them individually, right?
  3. In my menu, I highlight the shop if a user is on the shop page. I do this with isOpen(). This works, but only for the actually shop page of course. Is there an option to check if the page (depending on the url) is a child of the actual page to highlight the “Shop”-Menu Button even if the user is in “/shop/categories/products/tag:Something”?

Hm, for the breadcrumbs or sitemap to work out of the box with these links, you would actually need a more complex setup with “real” virtual pages, for which you would have to create page models.

Then the categories can be virtual children of the shop, and the products would be virtual children of their respective category.

You are crazy fast. Thank you.

I See, to keep the speed up high (regarding load times), I assume a css file would be similar fast? And it is not possible to display and/or create them in the panel as well, right?

I will give this a try as well. Thank you.

One last question about the menu parent page issue. Any ideas?

I will mark this as solved, because the main question is answered, but and the virtual pages are a complete new chapter :wink:.

The menu would work if the subpages were real children or real virtual children, but there is no way that isOpen() would recognize this when you are using routes, because they don’t create child pages