0

I am creating a product catalog using this Silverstripe Module:

https://github.com/luisdias/silverstripe-productcatalog Which is based on this module https://github.com/arambalakjian/DataObject-as-Page

I have an issue that friendly URLs are appearing as: www.mysite.com/product-page/category/1 or www.mysite.com/product-page/show/1/1 as apposed to their title or url segment. www.mysite.com/product-page/show/my-category/my-product

I've tried changing the code from Product.php to

//Return the link to view this category
public function Link() {
    $Action = 'show/' . $this->ID . '/' . $this->URLSegment;
    return $Action;    
} 

from

//Return the link to view this category
public function Link() {
    $Action = 'show/' . $this->ID . '/' . $this->CategoryID;
    return $Action;    
} 

Which works, but not for the category titles and is the url has spaces it generates %20 instead of _.

It seems like a simple change which I can't work out..


I also want to be able to have sub-categories. So everything in a category can be divided into say their "Size". At present All products are divided just once. Products > Categories I would like Products > Categories > Sub-Categories can any one help me achieve this? thanks

pinkp
  • 445
  • 2
  • 12
  • 30

1 Answers1

2

1) For the spaces in the URL issue:

URLSegment is a field on the product DataObject which is manually entered in the CMS, correct? If so, you'll have to type in the URLSegment as a URL friendly string, something like my-awesome-product.

If you want the URLsegment auto-generated, the DataObject As Page module you mentioned handles that. I would add that method, and the associated onBeforeWrite method to a DataObject that extends Product. You may be able to accomplish this with some DataExtension magic.

2) For the category URLSegment in the URL issue:

You'll have to overload the Link() method on your Category class as well. You'll need to change that (or overload that method in a custom DataObject that extends Category):

$Action = 'category/' . $this->URLSegment;

And add the generateURLSegment method and onBeforeWrite call as you did in #1.

Community
  • 1
  • 1
Benjamin Smith
  • 877
  • 1
  • 9
  • 24