These snippets of code was what held the multiple parents support together. Somewhere in there, or in TreeMultiselectField itself, it was broken, and so we didn't fix this for the initial 0.5 ecommerce release.
Sam: Maybe you could take a look at, and attempt to get it working. Keep in mind that it's broken in many subsequent releases of SilverStripe for one reason or another. And some of these methods may be deprecated, and not even required?
Cheers,
Sean
// getCMSFields() on Product.php
$fields->addFieldToTab("Root.Content.Main", new TreeMultiselectField("Parents", "Product Groups","SiteTree"));
/**
* Sets the ParentID for the component set
* which handles our "multiple parents"
*/
function setParentID($id) {
// if ParentID exists, delete it from the Product_Parents table
if($parentToDelete = $this->getField('ParentID')){
$this->Parents()->remove($parentToDelete);
}
// Add the new parent to the Product_Parents table
$parents = $this->Parents();
$parents->add($id);
// Set the ParentID on the SiteTree object for new and reorganise behaviour
$this->setField('ParentID', $id);
}
/**
* Called when we try and set the Parents() component set
* by Tree Multiselect Field in the administration.
*/
function onChangeParents(&$items) {
// This ensures this product can never be a parent of itself
if($items){
foreach($items as $k => $id){
if($id == $this->ID)
unset($items[$k]);
}
}
return true;
}
/**
* Return the classes to appear on this node in the CMS tree.
* We add 'manyparents' to indicate that this node may appear more than
* once in the tree.
*/
function CMSTreeClasses($controller) {
return parent::CMSTreeClasses($controller) . ' manyparents';
}
/**
* If this object is reorganised in the CMS, we need to update the Parents field,
* otherwise the order will be messed up when we next press save
*/
function cmsCleanup_parentChanged() {
$parents = $this->Parents();
foreach($parents as $parent) $parentIDs[] = $parent->ID;
$parentVal = implode(",", $parentIDs);
return parent::cmsCleanup_parentChanged() . " $('Form_EditForm').elements.Parents.treeDropdownField.setValue('$parentVal');";
}