Jump to content

Filter Pages Arrays with information from other Pages (something like a join in SQL)


zyON
 Share

Recommended Posts

I've been working with ProcessWire in the last few weeks trying to come up with this kind of structure and getting used to the way PW works. 

I must say I'm pretty impressed with it... The flexibility and ease of use that it provides is mind boggling. 

Picking up on this example and the suggestions of how to structure all of this in PW, 

I've went with way of creating BRANDS and COLLECTIONS as stand alone pages that can be reused with Page selects within the PRODUCT templates.

Now, as I'm not defining BRANDS and COLLECTIONS as children of the Categories like MEN or WOMEN whats the best way to get the used BRANDS and COLLECTIONS within those Categories?

Ex: 

/catalogue/men/suits/

All the BRANDS and COLLECTIONS are available under:

/catalogue/brands

and

/catalogue/collections

How can I get the used BRANDS (brands that are assigned under /men/suits) and only those?

I guess I could use selectors to get 2 page arrays (one with the men suits and other with all the brands) and then compare and extract only the used ones, but that seems kind of costly... Is there another simple way to do it?

I know that I can also use straight SQL but before jumping on that I just wanted to get some opinions from the experts .

Thanks.  

Link to comment
Share on other sites

zyON,


 


Welcome to PW!


 


Please write down your site pages hierarchy here.  E.g:


 


Home


Products


Stuff


Other stuff


Even more stuff


Etc.


 


It is easier to see their relationships that way. I have tried to look at the other tried and am not sure what you finally selected. We can then take it from there :)


Link to comment
Share on other sites

kongondo,

Thanks, l was reffering to another topic where I discuss that hierarchy. Anyway its somehting like this:

- Products

-- Brands

-- Collections

-- Man

--- Product1

--- Product2

-- Women

--- Product1

--- Product2

So in this case, A product (like product1) is displayed like:

site.com/products/man/brand/collection/product1

In this case, brand and collection are shared categories.

Link to comment
Share on other sites

Just to clarify, do you mean you want brand and collection to also appear in the URL or you are wondering how to use them in your selectors? If the latter, then you can use Page Reference Fields. Depending on your setup, these can be single Page Reference Fields or Multiple. For instance, I assume a product can only belong to one brand? Can a product belong to multiple collections? 

Edited by kongondo
Link to comment
Share on other sites

Assuming 1 product => 1 brand
 
Brands

Armani (child pages of brands)

Canali

Magee

Lambretta

 

Men

Suit 1 (child page of Men)

Suit 2

Suit 3

 
Suit pages will have a single Page Reference Field referencing their brand, e.g. 
 
Suit 1 => Armani
Suit 2 => Lambretta, etc.
 
Is this what you want? I'm not sure I got you correctly. 
 
You then want to search and display, e.g. all men's suits by, e.g. Armani? Not tested but I think either of these should work

$pages->find("template=suittemplate, parent=123, brand=armani");// brand is the Page Reference Field; 123 = ID of men page

// OR

$pages->find(123)->children("brand=armani");//123 = ID of men page

Edit;

Selector above, is of course wrong, brand=armani...will not give you what you want. You will want to create a variable that can reference armani (title of the value of the brand page reference field.)

Edited by kongondo
  • Like 1
Link to comment
Share on other sites

Yes, both brand and collection are to appear on the URL. 

I've them set up as Page Reference Fields, what I'm looking for is a good way to get for example in 

site.com/products/man/brand1/

All the Man collections of brand1. But I only want the display the collections that have products in them (some can be defined but empty or with products from another category).

A product can only belong to one brand and collection.

Just to clarify, do you mean you want brand and collection to also appear in the URL or you are wondering how to use them in your selectors? If the latter, then you can use Page Reference Fields. Depending on your setup, these can be single Page Reference Fields or Multiple. For instance, I assume a product can only belong to one brand? Can a product belong to multiple collections? 

Link to comment
Share on other sites

If you want an url structure that is not mapped 1:1 with the pages-hierarchy, you should use url segments:

http://processwire.com/api/variables/input/

You need to enable url segments in the template of the pages man/women.

When viewing site.com/products/man/brand1/, your first urlSegment contains brand1, so you could filter your products according to that:

// In template of men/women...
if ($input->urlSegment1) {
  
  $brandName = $input->selectorValue($input->urlSegment1);
  
  // Get the brand
  $brand = $pages->get("template=brand, name={$brandName}");
  
  // Brand does not exist, throw 404
  if (!$brand->id) throw new Wire404Exeption();
  
  // Brand exists. Get all the products with the brand
  $products = $page->children("brand={$brand}");

} else {
  // No url segments... display normal page content e.g. all products under men
}

  • Like 2
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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