Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Manage Product Specifications

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1121 Views
  • BradPlunkett
    Avatar
    Community Member
    4 Posts

    Manage Product Specifications Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Manage Product Specifications Link to this post

    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;
    }
    }

  • BradPlunkett
    Avatar
    Community Member
    4 Posts

    Re: Manage Product Specifications Link to this post

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

    1121 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.