silvershop / silvershop-core

SilverShop is an e-commerce shopping cart module for the SilverStripe CMS
http://silvershop.github.io
BSD 2-Clause "Simplified" License
113 stars 119 forks source link

Subclassing Product/Product Controller #709

Closed christohill closed 5 years ago

christohill commented 5 years ago

I'm trying to create some custom product types by subclassing the base product in the core. The goal is to have additional products with different fields, requirements, etc. but when I subclass the ProductController, the new product page is still using ProductController. Example:

class CustomProduct extends Product {

  private static $db = [
    'TestField' => 'Varchar(255)'
  ];

}

This works fine and I'm able to add the new product page.

class CustomProductController extends ProductController {

  public function init() {
    echo "HELLO!"
  }

}

The new CustomProduct page will not use this controller and always uses the ProductController class. I've used the debug_request variable and I get this in return:

Debug (line 262 of RequestHandler.php): Testing '$Action//$ID/$OtherID' with '' on SilverShop\Page\ProductController

Debug (line 270 of RequestHandler.php): Rule '$Action//$ID/$OtherID' matched to action 'handleAction' on SilverShop\Page\ProductController. Latest request params: array ( 'Action' => NULL, 'ID' => NULL, 'OtherID' => NULL, )

Debug (line 186 of RequestHandler.php): Action not set; using default action method name 'index'

Is this a bug or am I missing something?

christohill commented 5 years ago

Closing this as it's a framework/cms issue and not a SilverShop issue. See: https://github.com/silverstripe/silverstripe-framework/issues/6549