Hi all,
I have created a ProductPage Template that I want to be able to use in a site.
Code example below;
class ProductPage extends Page {
public static $db = array(
'Price' => 'Currency',
'SalePrice' => 'Currency',
'ProductCode' => 'Text'
);
public static $has_many = array(
'ProductImages' => 'ProductImage'
);
public static $has_one = array(
'ProductPage' => 'Homepage'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('Price', 'Price'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('SalePrice', 'SalePrice'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('ProductCode', 'ProductCode'), 'Content');
$tablefield = new DataObjectManager(
$this,
'ProductImages',
'ProductImage',
array( 'Thumbnail' => 'Image', 'Title' => 'Title'),
'getCMSFields_forPopup'
);
$tablefield->setPageSize(100);
$tablefield->setAddTitle( 'A Image' );
$fields->addFieldToTab( 'Root.Content.ProductImages', $tablefield );
return $fields;
}
}
Now I would like to gather all these products and give the user the oppurtunity to display them on the homepage in a list. I had a thought, I can use HasManyDataObjectManager. So I have written the HomePage like this;
class HomePage extends Page {
public static $db = array(
);
public static $has_one = array(
);
public static $has_many = array(
'Specials' => 'ProductPage'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$manager = new HasManyDataObjectManager(
$this,
'Specials',
'ProductPage',
array('Title' => 'Title'),
'getCMSFields_forPopup'
);
$perms = array();//Don't want to be able to Remove, Delete, View, Add from here.
$manager->setPermissions($perms);
$fields->addFieldToTab( 'Root.Content.Specials', $manager );
return $fields;
}
}
Now it all works sweet with one small exception, I can't select the item in the admin. I can see the checkbox but it is disabled.
The problem doesn't appear to be DataObjectManager Specific as I removed it and went back to the standard method with the same result.
Any help would be greatly appreciated.