Forum for discussing general topics related to Couch.
6 posts Page 1 of 1
I am currently at the early stages of creating an online store through Google Checkout. As of this writing, my current couch implementation plan is as follows:

store.php:
Image
This is the storefront where all the products(picture, name, and price) are displayed. It is not clonable. It has sidebar links for viewing the products by category and manufacturer. These filters are only meant to be used separately, not together. The list tag of the currently selected category or manufacturer is bolded and has a different background color. "All Products" is the default selection for this page.

products.php:
This page is clonable and has dynamic folders enabled. It has both folder views and page views within it. The list view of this page however redirects to store.php.
Code: Select all
<cms:template title='Products' clonable='1' dynamic_folders='1'></cms:template><cms:if k_is_page >
Page View Here
<cms:else /><cms:if k_is_folder >
Folder View Here
<cms:else /><cms:redirect url="<cms:link 'store.php' />" permanently='1' /></cms:if></cms:if>

An example of how a cloned page currently is being placed using the folders is as follows:
"http://www.example.com/products/category-1/company-1/item-name.html"

In the folder view I have been listing the categories as so:
Code: Select all
<cms:folders depth='1'><li><a href="<cms:show k_folder_link />"><cms:show k_folder_title /></a></li></cms:folders>

How could I specify a class or id for the currently selected category? I have not managed to come up with functioning code for the manufacturers list either. I'm starting to think my implementation is fundamentally flawed. At the moment I can only show the manufacturer's products within the context of a category(http://www.example.com/category-1/company-1/), not excluding the category(http://www.example.com/company-1/). I also can't account for the scenario whereby there is a manufacturer with products in more than one category. This would seemingly generate duplicate manufacturer listings.

Apologies if my explanation has been somewhat haphazard, I have been racking my brain for many hours trying to come up with solutions for some of the problems mentioned and unmentioned that I have encountered. I am probably over-complicating this and missing a simpler method. I would greatly appreciate it if KK or anybody with a fresh perspective could give me some suggestions. Either way I will restart my efforts tomorrow, I'm sure sleep will help. :P
Hi,

From what I could gather, each of your 'product' is a associated with one 'category' and one 'manufacturer'.

Your current design seems to be using folders for both 'category' as well as 'manufacturer'.
So, for example if there are two categories and two manufactures, the folder structure would be -
Code: Select all
Shoes
   Nike
   Adidas
Sport Jackets
   Nike
   Adidas

which is leading to the duplication of the manufacturers, as you noticed.

My take on this problem would be -
1. Use folders for only categories e.g.. 'Shoes' and 'Sport Jackets' in the example we are using.
2. Use another clonable template for manufacturers. For example, we can use a template named 'manufactures.php'.
Create clonable pages - one for each manufacturer e.g. 'Nike' and 'Adidas'.

So now when we create a product, we already have a drop-down list showing the folders (categories). The question is how to relate the product to a manufacturer.

This is how -
Create an editable region of type dropdown in 'products.php' and populate it with the manufactures -
Code: Select all
   <cms:editable 
      name="manufacturers"
      label="Manufacturer"
      desc="Select one from these"
      opt_values='Nike=nike | Adidas=adidas | Reebok=reebok'
      type='dropdown'
   />

This much is straightforward.
The task of manually feeding all the names of the manufacturer in the snippet above is not.
To make the task easy, Couch has feature where we can dynamically populate an editable region. What we'll do is populate the dropdown above dynamically with names of the manufacturer by listing the cloned pages of 'manufacturers.php'.

Create a snippet named 'list_manufacturers.htm' and place it in 'couch/snippets' folder (important to place it in this folder only).
Put the following code within it -
Code: Select all
<cms:pages masterpage='manufacturers.php'>
   <cms:show k_page_title  />=<cms:show k_page_name  />|
</cms:pages>

You can see that if you embed this snippet in any template, it will simply list all the manufactures in the format:
Nike=nike | Adidas=adidas | Reebok=reebok

We can associate this snippet with our editable region so that the output of the snippet becomes an input for the region. To do so modify the definition of the dropdown as follows -
Code: Select all
   <cms:editable 
      name="manufacturers"
      label="Manufacturer"
      desc="Select one from these"
      opt_values='list_manufacturers.htm'
      dynamic='opt_values'
      type='dropdown'
   />

We changed the 'opt_values' parameter to point to 'list_manufacturers.htm' and made known to Couch that the 'opt_values' parameter is dynamic i.e. the snippet specified needs to be executed to get the values, by setting dynamic='opt_values'.

At this point, your 'product' edit screen should show you names of all the manufactures in a dropdown,
Create products, choosing a category and a manufacturer for each.

LISTING PRODUCTS
------------------
Products need to be listed in two ways -
1. Category wise
2. Manufacturer wise.

To list them according to categories, you're already using the standard 'folder-view' so no problem there.

To list them according to manufactures, we'll have to use the 'manufacturers.php'.
The list of manufacturers of your home page can be created using the standard
<cms:pages masterpage='manufacturers.php'>..</cms:pages>

Each of the listed item will lead to the page-view of a cloned manufacturer page e.g.
http://www.examplesite.com/manufacturers/nike.html

In the page-view of manufactures.php, we can list all products (from products.php) that are associated with the manufacture being visited.
Sample code:
Code: Select all
<h1>Manufacturer</h1>

<cms:if k_is_page>
   <!-- Single manufacturer info -->
   <h2><cms:show k_page_title /></h2>
   
   <!-- Show products that are associated with this manufacturer -->
   <h3>Products</h3>
   <cms:pages masterpage='products.php' custom_field="manufacturers==<cms:show k_page_name />" >
      <cms:show k_page_title /><br />
   </cms:pages>

<cms:else />
   <!-- List all manufacturers here -->
</cms:if>

Notice how in the page-view of 'manufacturer.php', we are actually listing 'products.php'.
The key is how we list only those products that have the name of the current manufacturer in their editable region named 'manufacturers'
custom_field="manufacturers==<cms:show k_page_name />"

- if the name of the page being visited was 'nike', the snippet above will evaluate to
custom_field="manufacturers==nike"

I am leaving for now the other problem you mentioned about hilighting the current category.
Please try and implement the proposed solution and let me know if it suffices. We'll get to the other issues after this.

Hope this helps.
Regards.
Wow, thank you. The method you described is just perfect. It is great that all the components of this are dynamic, so I won't need to manually edit any of these files at a future date. I was ultimately able to implement everything you described. I got the breadcrumbs styled and functioning properly for every page. It took me a little bit of time to figure out how to retrieve the manufacturer title and link while on the products page-view, but I got them to work by using the pages tag's page_name parameter, and pointing it to the manufacturer variable. I was also able to style the currently selected category or manufacturer correctly in the sidebar.

(products.php code below):
Code: Select all
<cms:set category_title=k_folder_title />
...
<cms:folders orderby='title' order='asc'><li><a href="<cms:show k_folder_link />"<cms:if k_folder_title = category_title > id="active"</cms:if>><cms:show k_folder_title /></a></li></cms:folders>

(manufacturers.php code below):
Code: Select all
<cms:set manufacturer_title=k_page_title />
...
<cms:pages orderby='page_title' order='asc'><li><a href="<cms:show k_page_link />"<cms:if k_page_title = manufacturer_title > id="active"</cms:if>><cms:show k_page_title /></a></li></cms:pages>

I don't believe there is anything wrong with the code I have posted as it is currently functioning properly, but do let me know if there is. Hopefully this thread in general will be of use to others in the future. Thanks again KK!
I am glad you found the solution useful :)
Your method of highlighting the selected page is exactly the way it should be. No changes required.
4 years later I come along, impressed with myself that I implemented a solution really close to what KK recommended! :D
However I have used a method where categories.php has hard coded folders in its editable tags, like CLOTHING, COMPUTERS, FOOD, PHONES.
Then when I make a clone of the categories page, I give it a name like LAPTOPS, and laptops falls under the COMPUTERS folder.
And then from my products page I have relational tags linking each product to multiple categories like a kids educational laptop could come under toys, computers AND children..
---
You live many times, but only ever remember your lives.length - 1
---
Image
Simmons, this solution was for an earlier version of Couch. Although it'll still work with the latest version, using 'relations' would be the preferred method now to relate templates (e.g. the 'manufactures' with 'products' in this case).
6 posts Page 1 of 1
cron