Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Manage Product Specifications


Reply

3 Posts   1149 Views

Avatar
BradPlunkett

3 June 2010 at 4:04am Community Member, 4 Posts

I'm working on a site for a client where they would like to manage a list of their product lines, as well as the individual products (floorplans) inside each line. Each floorplan has a similar (though can vary) list of specifications and associated values.

I'd like to be able to set up a list of specs for a certain product line, and on each floorplan (if possible), allow for selection of whichever specs may apply and then input the values specific to that floorplan. I'm assuming the DataObjectManager is the right tool for this, and while I have a decent grasp on relationship models, I have no clue how I might accomplish this task. If anyone is able to point me in the right direction, or provide some sort of tutorial (with explanations - I prefer to know what I'm doing and why, rather than just blindly following instructions), I would greatly appreciate it.

I could easily accomplish this stuff if I were building the site from scratch, but I need to be sure the client is able to maintain their product list within the CMS rather than having to come to me for changes.

Avatar
UncleCheese

3 June 2010 at 3:35pm 4085 Posts

Well, I would start here:

http://doc.silverstripe.org/tutorial:5-dataobject-relationship-management

The way I would set it up is, on the ProductLine object, have a $has_many "Specifications" managed with a DOM, and then, depending on what you want to do with your FloorPlan object, if it's a Page, then you can select the specs using a CheckboxSetField.

You could eliminate a step, however, depending on what kind of experience you want for your users.. You could set up a many_many relation of FloorPlan to Specification, and manage that with a ManyManyDataObjectManager. That way, you can create/edit/delete Specifications in the same place you assign them to a FloorPlan.

The code for that would look like this, give or take a few syntax errors..

Specification.php

class Specification extends DataObject
{
static $db = array ('Title' => 'Varchar');
static $belongs_many_many = array ('FloorPlans' => 'FloorPlan');

static $summary_fields = array('Title' => 'Title');

public function getCMSFields() {
return new FieldSet(new TextField('Title'));
}
}
FloorPlan.php
class FloorPlan extends Page
{
static $many_many = array ('Specifications' => 'Specification');
public function getCMSFields() {
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Specs", new ManyManyDataObjectManager($this,'Specifications','Specification'));
return $f;
}
}

Avatar
BradPlunkett

4 June 2010 at 1:03am Community Member, 4 Posts

Thanks for that. I will give that code a try later today and see where I can take it.