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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

E-Commerce Categories


Go to End


8 Posts   2562 Views

Avatar
Nathan Cox

Community Member, 99 Posts

9 November 2007 at 10:46am

Hi, I'm working on a shop using the e-commerce module that needs products to be in multiple categories at once...I figured the exisiting ProductGroup hierarchy isn't going to work here.

It says in the e-commerce docs that multiple categories are a "proposed feature", were there any plans about how you would implement it?

Avatar
Willr

Forum Moderator, 5523 Posts

9 November 2007 at 5:33pm

we have done a site that had products in multiple categories. I believe you need to use stageChildren and liveChildren. Read http://doc.silverstripe.com/doku.php?id=recipes:customising-the-hierarchy that gives an overview at least of how it would work

Avatar
Sam

Administrator, 690 Posts

12 November 2007 at 9:04pm

The multi-category support is shown here, it's been deleted in the most recent trunk version as it was buggy.

http://open.silverstripe.com/changeset/43521

Sean - what was buggy about it?

Avatar
Sean

Forum Moderator, 922 Posts

13 November 2007 at 9:15am

Edited: 13/11/2007 9:17am

The multiple categories function was a TreeDropdownField to select multiple parent product categories, which is fine - however, there were multiple methods in there to support it. These methods were relying on a specific version of SilverStripe < 2.0.2, and so it was an intense process getting it working on newer versions.

I removed the multiple categories support in our first version of ecommerce as much as it was a hack and difficult to fix, but in favour of leaving it out to find a better solution.

Sean

Avatar
Sam

Administrator, 690 Posts

13 November 2007 at 9:51am

Can you provide some more specifics? What were the methods in there to support it? What broke in the newer versions of SS?

Avatar
Sean

Forum Moderator, 922 Posts

13 November 2007 at 1:05pm

Edited: 13/11/2007 1:07pm

I would if I could get on http://open.silverstripe.com/ and check the old revisions. ;-)

EDIT: Seems there's too many connections sometimes, it appears to be working again. I'll post more details here when I find them about the multiple categories support.

Sean

Avatar
Sean

Forum Moderator, 922 Posts

13 November 2007 at 1:16pm

Edited: 13/11/2007 1:16pm

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');";
}

Avatar
Nicolaas

Forum Moderator, 224 Posts

21 November 2007 at 2:23pm

Hi

Would it work to just have a "virtual page" in the CMS / I think it is called a redirector page.... So you have the product only in one category and you redirect it...

Not perfect, but perhaps an easy solution.

Cheers

Nicolaas