eCommerce URLs

I asked this on another list but seeing how I will be using coldbox I figured I would ask it here as well…

Dan,

addRoute(pattern=“product/:action/”);

addRoute(pattern=“category/:action/”);

addRoute(pattern=":handler/:action/");

It would be nice if ColdBox allowed us to define these routes at the hander level.

No your not following… Say I ran a clothing store

http://www.oldnavy.com/men
http://www.oldnavy.com/men/tshirts

http://www.oldnavy.com/some-really-cool-tshirt

How do I map those and where do i map them?

You would need to check all your categories against the beginning URL, and then go down to products if it doesn’t match.

I don’t see any other reasonable way to do it.

Depending on how many categories you have, you could hard code them into a mod_rewrite rules.

Mark

Looking at the example below, you can cheat a little. Categories don’t have ‘-’ in them :slight_smile:

Mark

You are brilliant! I do have 2 main top level categories.

I have 2 top level categories and everything else under these 2 would be sub categories

top level category
http://www.oldnavy.com/products/men

http://www.oldnavy.com/products/women

sub categories

http://www.oldnavy.com/products/men/shirts
http://www.oldnavy.com/products/men/shirts/tank
http://www.oldnavy.com/products/men/shirts/dress/short-sleeve
http://www.oldnavy.com/products/men/shirts/polo

single product (this works because its not men||women)

http://www.oldnavy.com/products/some-cool-tshirt

Routes

// CATEGORY
addRoute(pattern=“products/men/:category?/:category?”,handler=“Catalog”,action=“listByCategory”);
addRoute(pattern=“products/women/:category?/:category?”,handler=“Catalog”,action=“listByCategory”);

// PRODUCT
addRoute(pattern=“products/:product?”,handler=“Catalog”,action=“view”);

Now the only issue I seem to have is this. If they visit /products/men or /women than its directed to listByCategory action without a category name. So to take care of this I added a custom variable to the route called category. If category does not exist it will default to men or women, if it does it will just overwrite it!

// CATEGORY
addRoute(pattern=“products/men/:category?/:category?”,handler=“Catalog”,action=“listByCategory”,category=“men”);
addRoute(pattern=“products/women/:category?/:category?”,handler=“Catalog”,action=“listByCategory”,category=“women”);

FRACKING AWESOME! You rock coldbox!

Does this look good peeps?

Sounds good to me :slight_smile:

Mark

one quick correction for those following along at home… the product can’t be optional, so the route would look like this

// PRODUCT
addRoute(pattern=“products/:product”,handler=“Catalog”,action=“view”);

I helped a client migrate to ColdBox who had a similar issue. There was not simple convention like “if it has a dash, its X” logic. Their previous system had a string in a database called URLNAME that needed to be referenced. For them, I grabbed all of the records, cached the query and performed a query of queries.

You could keep your handlers/routes organized as Andrew suggested and use the routes.cfm PathInfoProvider() method to rewrite the URL before the SES interceptor does it’s thing. You might prepend “products/” to the CGI.PATH_INFO returned by the PathInfoProvider() method to allow ColdBox to instantiate the “Products” handler.

For example, on my favorite video site, we need to support quite a few routes that all end up in the same handler:

  • /watch/:show/:episode/
  • /de/watch/:show/:episode/
  • /m/de/watch/:show/episode/
  • And so on…
    I use the PathInfoProvider() method within the routes.cfm file to set some values into my Event object to communicate the language and if the request is mobile, clean up the route and return “/watch/{show}/{episode}”. While this example is not solving your problem I hope it helps demonstrate the power of adding a PathInfoProvider() method to your routes.cfm file. It basically allows you to rewrite the URL within ColdFusion so you can apply application logic and returns a string that is evaluated by the SES Interceptor. Without such a function the SES interceptor simply uses the CGI.PATH_INFO to evaluate your route.

Here is the method signature to help save a trip to the docs.

string function PathInfoProvider(Event)
{
var rc = Event.getCollection();
var prc = Event.getCollection(private=true);

var path = CGI.PATH_INFO;
// Do your thing here
return modifiedPath;
}

Aaron Greenlee
http://aarongreenlee.com/

Good stuff Aaron, thanks!