Jump to content


renobird

Member Since 19 Mar 2012
Offline Last Active Yesterday, 09:15 PM
-----

#35130 Handling Categories on a Product Catalogue

Posted by renobird on 16 May 2013 - 09:47 PM

I think this method will work even if you expand it out. I changed a few things up, but hopefully it makes sense.
Product pages use "template product", all other catalog pages use "template catalog".
 
Catalogue
-- Men 
---- Shoes 
------ Product 1
------ Product 2 
---- Hats 
------ Product 1
------ Product 2
 
-- Women
---- Shoes
------ Product 1
------ Product 2
---- Hats
------ Product 1
------ Product 2
 
Categories (these pages only a template with a title field)
-- Brands
---- Brand 1 (title only template)
---- Brand 2 (title only template)
-- Type
---- Type A (title only template)
---- Type B (title only template)
-- Collections
---- Collection A (title only template)
---- Collection B (title only template)
 
 
catalogue.php template & product.php template (same contents)
<?php

/* There might be a better way to accomplish this. The only reason to have 2 templates is to give find() a way      *  to only return the actual product pages, and not all the parent pages as well.
* 
* update: You may want to look into using the alternative template method:
* http://processwire.com/talk/topic/740-a-different-way-of-using-templates-delegate-approach/
* 
* With this approach you would create a real file (product.php) for the product template,
* catalogue template would have no file associated, but point to product.php under the advanced settings tab.
*/

include("./site/templates/head.inc");
include("./site/templates/product-view.inc");
include("./site/templates/foot.inc");
 
product-view.inc
<?php

$brand = "";
$type = "";
$collection = "";

if ($input->urlSegment1) $brand = ",brand.name=".$input->urlSegment1;
if ($input->urlSegment2) $type = ",type.name=".$input->urlSegment2;
if ($input->urlSegment3) $collection = ",collection.name=".$input->urlSegment3;

if ($input->urlSegment4) { // if Segment 4, then we know what page to get
    $product = $pages->get("name=$input->urlSegment4"); 
    echo $product->title;

} else if ($input->urlSegment1){ // check if we are using URL segments
    
    if ($input->urlSegment1 == "all"){
        $products = $pages->find("has_parent=$input->urlSegment2, template=product");
    } else {
        $products = $pages->find("has_parent=$page->path, template=product, . $brand . $type . $collection");
    }
    
    foreach ($products as $p){
       echo $p->title;
    }

} else {
    $products = $pages->find("has_parent=$page->path, template=product");
    foreach ($products as $p){
       echo $p->title;
    }
}

 

Looking at example URLS to see how the selector would get populated:
 
/catalogue/brand1/
Brand1 is a url->segment1 so the elseif evaluates to true, and the selector gets populated to become:
$products = $pages->find("parent=/catalogue/, template=product, brand.name=brand1");
 
/catalogue/brand1/casual/
elseif evaluates to true, and the selector gets populated to become:
$products = $pages->find("parent=/catalogue/, template=product, brand.name=brand1, type.name=casual");

 

/catalogue/brand1/casual/trendy/
$products = $pages->find("parent=/catalogue/, template=product, brand.name=brand1, type.name=casual, collection.name=trendy");

 

/catalogue/men/
$products = $pages->find("has_parent=men, template=product");

 

/catalogue/all/shoes/
$products = $pages->find("has_parent=shoes, template=product");

 

/catalogue/all/hats/
$products = $pages->find("has_parent=hats, template=product");

 

/catalogue/men/shoes/
no URL segment here, so the if/elseif are false, so we get:
$products = $pages->find("has_parent=/catalogue/men/shoes/, template=product");

 

/catalogue/men/shoes/brand1/
Brand1 is a url->segment1 so the elseif evaluates to true, and the selector gets populated to become:
$products = $pages->find("parent=/catalogue/men/shoes/, template=product, brand.name=brand1");
 
you get the idea. :)
 
Again, untested and coded in the browser — but hopefully thought out enough to get you started.



#35123 Handling Categories on a Product Catalogue

Posted by renobird on 16 May 2013 - 07:34 PM

Hi zyON,

 

That is almost what I meant.

 

For your page tree:

 

Shoes

-- Men 

---- Product 1 (product template)

---- Product 2 (product template)

-- Women

---- Product 1 (product template)

---- Product 2 (product template)

 

Categories (these pages only a template with a title field)

-- Brands

---- Brand 1 (title only template)

---- Brand 2 (title only template)

-- Type

---- Type A (title only template)

---- Type B (title only template)

-- Collections

---- Collection A (title only template)

---- Collection B (title only template)

 

You client will only ever look at /categories if they need add new items. They will interact with it completely from the pageField in the product template.

 

If your client needs to see additional information about each product in the page list, that's where you could use the Page List Better Label module

If they need even more detailed views, you might be able to make use of Diogo's Admin Custom Pages Module

 

Product Template:

include("./site/templates/head.inc");

$brand = "";
$type = "";
$collection = "";

if ($input->urlSegment1) $brand = ",brand.name=".$input->urlSegment1;
if ($input->urlSegment2) $type = ",type.name=".$input->urlSegment2;
if ($input->urlSegment3) $collection = ",collection.name=".$input->urlSegment3;

if ($input->urlSegment4) { // if Segment 4, then we know what page to get
    $product = $pages->get("name=$input->urlSegment4"); 
    echo $product->title;

    }

} else if ($input->urlSegment1){ // check if we are using URL segments
    $products = $pages->find("parent=$page->path . $brand . $type . $collection");
    foreach ($product as $p){
       echo $p->title;
    }

} else {
// do something else for pages without URL segments
}

include("./site/templates/foot.inc");



#35120 Handling Categories on a Product Catalogue

Posted by renobird on 16 May 2013 - 06:32 PM

zyON,

 

If your client needs to add additional brands, collections, types, then they will need access to those pages.

To make it less confusing, you can set them up underneath a parent page.

 

Categories

-- Brands

---- Brand 1

---- Brand 2

---- Brand 3

 

-- Types

---- Type A

---- Type B

---- Type C

 

-- Collections

---- Collection 1

---- Collection 2

---- Collection 3

 

If you set the parent page /categories to hidden, then it will show as a lighter color in the page tree, and searches won't return any of those pages.

 

I tend to use something like /tools/ or /config/ to keep things like this all grouped in one nice location.




#35109 Handling Categories on a Product Catalogue

Posted by renobird on 16 May 2013 - 02:30 PM

haha. I'm sure I have many on that wall as well. :)




#35107 Handling Categories on a Product Catalogue

Posted by renobird on 16 May 2013 - 01:53 PM

diogo,

 

I'm not following your example. (sorry).

Wouldn't the parent always be either /shoes/men/ or /shoes/women/?

The other parts of the selector are looking for pageField values — and there could be multiple.

 

Maybe I'm being dense and just not getting it.




#35104 Handling Categories on a Product Catalogue

Posted by renobird on 16 May 2013 - 01:06 PM

Hi zyON,

 

I think $input->urlSegments would work here. Although, you may need to up the maximum allowed number of segments in your /site/config.php — I think the default is 4, so you might be OK.

 

Anyhow, for a URL like:

http://sitename.com/...ction1/product1

 

In this case you are already specifying the exact page you want, so you can do a simple:

$pages->get("name=$input->urlSegment4");

 

Putting it all together:

$brand = "";
$type = "";
$collection = "";

if ($input->urlSegment1) $brand = ",brand.name=".$input->urlSegment1;
if ($input->urlSegment2) $type = ",type.name=".$input->urlSegment2;
if ($input->urlSegment3) $collection = ",collection.name=".$input->urlSegment3;

if ($input->urlSegment4) { // if Segment 4, then we know what page to get
    $product = $pages->get("name=$input->urlSegment4");

} else if ($input->urlSegment1){ // check if we are using URL segments
    $products = $pages->find("parent=$page->path . $brand . $type . $collection");

} else {
    // do something else for pages without URL segments
}

 

This is untested, and written in the browser (there may also be easier methods, this is just off the top of my head while on lunch break.) 

...and of course, it may not work at all. Try it out and let me know.  ;)




#35004 Handling Categories on a Product Catalogue

Posted by renobird on 15 May 2013 - 10:26 AM

I think changing the structure (like I suggested) would make it more efficient — even just from a product entry standpoint.

Grouping by the largest set first (Men/Women) and then creating any references from there. You could setup the template to show brand / collection in the page list, or you could get all fancy with Page List Better Label




#34942 Handling Categories on a Product Catalogue

Posted by renobird on 14 May 2013 - 07:50 PM

zyON,

Check into the Page Fieldtype

 

Maybe something like this for organization:

 

Shoes

-- 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)

$pages->get("/shoes/men/")

 

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.




#34544 Comments module outgoing message customization

Posted by renobird on 09 May 2013 - 08:18 PM

Hi Ryan,

 

This seems great! I'll give it a test tomorrow.

 

For the project I'm working on I needed to mimicking some functionality from Basecamp where users can select people to notify of a new comment via checkboxes. In this case it's a list of 5-8 people who have a particular role.

 

In order to make it work, I needed multiple custom messages based on $page->template — while leaving the default message in place for existing pages with comments. I also needed an additional field to store the list of email address that need notified of the comment.

 

I happened across this thread and decided to give it a shot. It was pretty easy to add the additional field to the DB and update the module in a few places. I now have an additional field ($comment->notifications) that is output as a hidden field and populated with email addresses via JS. The security concerns are low since all users are trusted and authenticated. ;)

 

The whole thing is pretty specific to the needs of this project, but (as always) I was shocked at how easy it was to get working.

 

:)




#34423 Newbie overwhelmed...

Posted by renobird on 07 May 2013 - 07:59 PM

To all of you who are new to ProcessWire...

 

1. Welcome. :)

 

2. Ask lots of questions, the community here is friendly and very willing to assist.

 

3. Just start building something—the learning curve isn't nearly as steep as you might think.

 

4. It's worth it. Once it starts to click you'll never look back.




#34318 Karena Savannah Cramer

Posted by renobird on 06 May 2013 - 07:21 AM

Welcome to the world Karena! Nice work Ryan. :)




#34283 Admin Custom Pages Module

Posted by renobird on 05 May 2013 - 06:40 PM

Diogo,

 

Can't wait to test this tomorrow morning. If it does what I think it does, I'll be on the first plane to Portugal to buy you all the beer you can drink.

 

:)




#33928 Page-specific permissions?

Posted by renobird on 30 April 2013 - 02:09 PM

Hi Ryan,

 

Is your module working with 2.3?

Everything works admin side (field is added, and I can select roles), but I can still view the page on the frontend.

 

I've tried the obvious (making sure I didn't have the role, logging out, etc...) — no luck.

 

False alarm. The page wasn't actually viewable. I got confused because it is still showing in my nav (using MarkupSimpleNavigation).




#33657 MarkupSimpleNavigation

Posted by renobird on 24 April 2013 - 11:36 AM

I'm using Font Awesome, and wanted to be able to add icon markup to parent pages only.

Soma mentioned using "xtemplates", but in my case parent and child pages all use the same template.

 

So after I flew to Switzerland to hand Soma a beer, he suggested I use a hook.

 

This may be useful to someone else, so here's what I did:

 

1. add a text field called "icon" to your template.

2. add the code below before you call $treeMenu->render();

function addIcon(HookEvent $event){
$page = $event->arguments[1];
    if ($page->icon){
        $event->return = "<a href='{$page->url}'><i class='icon icon-{$page->icon}'></i> {$page->title}</a>";
    }
} 

$treeMenu->addHookAfter('getTagsString', null, "addIcon");



#33086 Simply Interesting for ProcessWire

Posted by renobird on 16 April 2013 - 09:04 AM

Ryan,

 

ROFL!  *repeatedly pressing the like button*

 

Phew, that got me.