Jump to content

Handling Categories on a Product Catalogue


Recommended Posts

This is the code that I'm actually using: 

foreach($pages->find("template=bustotorso-especial") as $p) {

The post hook on save is correctly working as when I save a product in the admin the fullurl field is correctly filled.

The above code is used on the template and should fill automatically the fullurl for all the already created products using that template (as ryan suggested).

Link to comment
Share on other sites

If you are still getting that error, I think we need to see the full code for your hook function too (as well as any other code involved in the process). Is the error you are getting specific to the page $p that you are calling $p->save() on? The error you mentioned indicates that something is changing the output formatting state back to on, as it won't throw that error unless you try to save a page that has output formatting on. I am guessing that you need another ->of(false); in your hook function for $brand, but not certain without seeing the full context. 

Link to comment
Share on other sites

Ok, so it goes like this:
On admin.php I have set up the hook as this:
$pages->addHook('saveReady', null, 'storeFullURL');
function storeFullURL($event) {
  $page = $event->arguments(0); 
  if($page->template == 'manequim') {
    $page->fullurl = "{$page->parent->url}{$page->gama->name}/{$page->tipo->name}/{$page->colecao->name}/{$page->name}" ;
On the product template php file (in this case on manequim.php) I have on the top of the page this:
foreach($pages->find("template=manequim") as $p) {
The fullurl field is correctly filled if I go to a page on the admin and save it. 
I'm not getting any error now, the field for the already created pages just doesn't get automatically filled when I load the template file.
Link to comment
Share on other sites

Yes, I followed Ryan's suggestion. 

<digression>@zyON, am curious as to why you chose to write to admin.php? Is this the one that comes with PW?</digression>

Link to comment
Share on other sites

 * Admin template just loads the admin application controller, 
 * and admin is just an application built on top of ProcessWire. 
 * This demonstrates how you can use ProcessWire as a front-end to another application. 
 * Leave this file as-is, do not remove. 
require($config->paths->adminTemplates . 'controller.php'); 

This is in site/templates/admin.php

Do not remove, doesn't mean you can add code there.

It's a easy way to add admin only auto hooks without creating a autoload module.

  • Like 3
Link to comment
Share on other sites

  • 2 months later...

This addresses the original post. I have built and operated a web shop that did $750 - $1mil in sales per year, so I have some experience in this field. 

You have categories, brands, and product attributes (like size, color, sex). What you don't want to do is mix these things up. Here's how I would approach this....


-- Shoes

---- Heels

---- Tennis Shoes

---- Boots

Your categories do not contain sex or brand, this is stored with the product.

Here's what your product fields would look like...


ProductCategoryPage (page field type)

ProductManufacturerPage (page field type)

ProductAttributesRepeater (repeater field type, there may also be a case for page field type. This is where you save things like color, size and sex, and probably sku depending on how your shop is set up)

Then when you need to find products you have an efficient and flexible way to do so....

Find products in category boots where manufacturer equals brand 


Find all products by brand then display by category


Find all products by color and sex


Find all products by sex and category


I think it was mentioned, but I would also use url segments and a central controller to handle the page requests (a controller to build the product listing depending on values in the url segments).

Just keep an eye your sql queries for performance. In some cases it may be better to use multiple smaller queries and filter the data in your loop. You may also need to use the autojoin feature on some of these fields, but I don't fully understand autojoin yet, so it may not do what I expect. 

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Hi everyone,

Thanks for this discussion, I find this pinned thread really helpful :D

I am setting up a simple shop in Processwire and I am wondering if anyone has idea how to do "Shopify product variant" but in PW style (screenshot from Shopify attach) maybe using combination of repeater / pages fieldtype. I am just wondering :) Thank you



Link to comment
Share on other sites

  • 7 months later...

couldn't you check if the option is already in your "size" category (page which contains all sizes so far typed by users)
if not create a new page inside that category (category chosen by selectbox)
the input can be exploded and then cycled through after posting the data.

your structure should be then

Product Categories









even if the answer is quiet late hope it helps anyway

Link to comment
Share on other sites

  • 4 months later...

this categories& product 

<div class="header_bottom_left">
<div class="categories">
foreach ($pages->get(1022)->children as $c) {
$class = $c->url === $page->url ? " class='active'" : '';
echo "<li $class><a href='$c->url'>$c->title</a></li>";
<div class="header_bottom_right">
<?php foreach ($page->children as $child):?>
<div class="grid_1_of_4 images_1_of_4 product_category">
<a href="<?php echo $child->url; ?>"><img src="<?php echo $child->product_image->first()->url; ?>" alt="" /></a>
<h2><?php echo $child->title; ?></h2>
<div class="price-details">
<div class="price-number">
<p><span class="rupees">Rp <?php echo $child->sc_price; ?></span></p>
<div class="add-cart">
<h4><a href="<?php echo $child->url; ?>">View</a></h4>
<?php endforeach; ?>
<div class="clear"></div>
Link to comment
Share on other sites

@Mass Harry,

  • There is no need to double post. I will delete your other post
  • Please use the 'forum post code function' to format your code. It is really difficult to follow what you've posted
  • Even so, I haven't seen a question in there. What exactly is your question?
Link to comment
Share on other sites

  • 2 weeks later...


Check into the Page Fieldtype

Maybe something like this for organization:


-- Men

---- Product A

---- Product B

---- Product C

-- Women

---- Product A

---- Product B

---- Product C

Brands (these are just the references, no products listed as children)

-- Brand 1

-- Brand 2

-- Brand 3

Collections (these are just the references, no products listed as children)

-- Collection A

-- Collection B

-- Collection C

Create page fields for Brand and Collection, and add them to your "Product" template.

Now you can associate brand and collection with each product.

So to get the output you need:

Shoes > Men   (Any Brand)


Shoes > Brand2

$pages->find("has_parent=/shoes/, brand.title=Brand 2")

Shoes > Brand2 > CollectionB

$pages->find("has_parent=/shoes/, brand.title=Brand 2, collection.title=Collection B")

You could also pass $input values to the selector so this could be generated via use selections.

This setup good enough for a site selling one kind of product.

How about multiple kinds of product ? for example an apparel store, computer store

Link to comment
Share on other sites

You can apply the same concepts to multiple product types. Either nest them under a larger parent /products/ or create additional roots parents for other types /apparel/ and /computers/

You question is a bit too general for me to give a detailed answer. Every product catalog has it's own specific set of requirements, so there isn't really a one-size-fits-all answer.

Link to comment
Share on other sites

  • 6 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...