thanky UncleCheese for your interest:
ecommerce/code/products/Product.php:
<?php
/**
* This is a standard Product page-type with fields like
* Price, Weight, Model/Author and basic management of
* groups.
*
* It also has an associated Product_OrderItem class,
* an extension of OrderItem, which is the mechanism
* that links this page type class to the rest of the
* eCommerce platform. This means you can add an instance
* of this page type to the shopping cart.
*
* @package ecommerce
*/
class Product extends Page {
public static $db = array(
'Price' => 'Currency',
'Weight' => 'Decimal(9,2)',
'Model' => 'Varchar',
'FeaturedProduct' => 'Boolean',
'AllowPurchase' => 'Boolean',
'InternalItemID' => 'Varchar(30)'
);
public static $has_many = array(
'Variations' => 'ProductVariation',
'Resources' => 'Resource',
'ImageAtts' => 'ImageAtt'
);
public static $many_many = array(
'ProductGroups' => 'ProductGroup'
);
public static $belongs_many_many = array();
public static $defaults = array(
'AllowPurchase' => true
);
public static $casting = array();
static $default_parent = 'ProductGroup';
static $add_action = 'a Product Page';
static $icon = 'cms/images/treeicons/book';
function getCMSFields() {
$fields = parent::getCMSFields();
// Standard product detail fields
$fields->addFieldsToTab(
'Root.Content.Main',
array(
new TextField('Weight', _t('Product.WEIGHT', 'Weight (kg)'), '', 12),
new TextField('Price', _t('Product.PRICE', 'Price'), '', 12),
new TextField('Model', _t('Product.MODEL', 'Model/Author'), '', 50),
new TextField('InternalItemID', _t('Product.CODE', 'Product Code'), '', 7)
)
);
$manager = new FileDataObjectManager(
$this, // Controller
'Resources', // Source name
'Resource', // Source class
'Attachment', // File name on DataObject
array(
'Name' => 'Name',
'Description' => 'Description',
'Category' => 'Category'
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);
$fields->addFieldToTab("Root.Content.Resources", $manager);
$imageAtt = new ImageDataObjectManager(
$this, // Controller
'ImageAtts', // Source name
'ImageAtt', // Source class
'ImageAtt', // File name on DataObject
array(
'Name' => 'Name',
'Description' => 'Description'
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);
$fields->addFieldToTab("Root.Content.Images", $imageAtt);
// Flags for this product which affect it's behaviour on the site
$fields->addFieldsToTab(
'Root.Content.Main',
array(
new CheckboxField('FeaturedProduct', _t('Product.FEATURED', 'Featured Product')),
new CheckboxField('AllowPurchase', _t('Product.ALLOWPURCHASE', 'Allow product to be purchased'), 1)
)
);
$fields->addFieldsToTab(
'Root.Content.Variations',
array(
new HeaderField(_t('Product.VARIATIONSSET', 'This product has the following variations set')),
new LiteralField('VariationsNote', '<p class="message good">If this product has active variations, the price of the product will be the price of the variation added by the member to the shopping cart.</p>'),
$this->getVariationsTable()
)
);
$fields->addFieldsToTab(
'Root.Content.Product Groups',
array(
new HeaderField(_t('Product.ALSOAPPEARS', 'This product also appears in the following groups')),
$this->getProductGroupsTable()
)
);
return $fields;
}
...
mysite/code/ImageAtt.php:
<?php
class ImageAtt extends DataObject
{
static $db = array (
'Name' => 'Text',
'Description' => 'Text'
);
static $has_one = array (
'ImageAtt' => 'File',
'Product' => 'Product'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Name'),
new TextareaField('Description'),
new FileIFrameField('ImageAtt')
);
}
}
// EOF