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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Product Portfolio


Go to End


12 Posts   6780 Views

Avatar
animasola

Community Member, 121 Posts

18 April 2010 at 6:10pm

Hi,

I'm trying to create a website for an Antique shop and was wondering how SilverStripe can handle product portfolios. I do not know of an existing module which can do this but I guess we have to use the DataObjectManager to create one ourselves? Can anyone help me start with this?

I really like what this one user did with his site: http://www.spiro.se/portfolio/
(http://silverstripe.org/template-questions/show/253191#post253191)

But I think it would be better if clicking the image will bring it to a separate page for each product/item.

Thanks! :)

Avatar
UncleCheese

Forum Moderator, 4102 Posts

19 April 2010 at 3:58am

Edited: 19/04/2010 4:00am

Yeah, that's really easy to do with DOM. In this example, I'll assume you want to upload your own thumbnail rather than letting Silverstripe generate it for you..

PortfolioPage.php

class PortfolioPage extends Page
{
static $has_many = array (
'PortfolioItems' => 'PortfolioItem'
);

public function getCMSFields() {
$f = parent::getCMSFields();
$f->addFieldToTab("Root.Content.Portfolio Items", new ImageDataObjectManager($this,'PortfolioItems','PortfolioItem','Thumbnail'));
return $f;
}
}

class PortfolioPage_Controller extends Page_Controller
{
public function show()
{
if($this->urlParams['ID'] && is_numeric($this->urlParams['ID'])) {
return array (
'PortfolioItem' => DataObject::get_by_id("PortfolioItem", $this->urlParams['ID']
);
}
return false;
}
}

PortfolioItem.php

class PortfolioItem extends DataObject
{
static $db = array (
'Title' => 'Text',
'Caption' => 'Text'
);
static $has_one = array (
'PortfolioPage' => 'PortfolioPage',
'Thumbnail' => 'Image',
'FullSize' => 'Image'
);

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

public function getCMSFields()
{
return new FieldSet(
new TextField('Title'),
new TextareaField('Caption'),
new ImageField('Thumbnail'),
new ImageField('FullSize','Full size image')
);
}

public function Link()
{
return Controller::join_links($this->PortfolioPage()->Link(),'show',$this->ID);
}
}

PortfolioPage.ss

<ul>
<% control PortfolioItems %>
<li><a href="$Link">$Thumbnail.SetWidth(200)</a> 
<a href="$Link">$Title</a> $Caption</li>
<% end_control %>
</ul>

PortfolioPage_show.ss


<% if PortfolioItem %>
<% control PortfolioItem %>
<h2>$Title</h2>
<p>$Caption</p>
<div>$FullSize.SetWidth(500)</div>
<% end_control %>
<% else %>
That portfolio item was not found.
<% end_if %>

Might be some syntax errors in there, but that's what you get for a 90-second code sprint. :)

Enjoy.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

19 April 2010 at 4:04am

I would also add:

_config.php

SortableDataObject::add_sortable_class('PortfolioItem');

Avatar
maryfran

Community Member, 12 Posts

8 May 2010 at 7:19am

Could you then group the items by category? And add a little description to the category? Like in this template http://net.tutsplus.com/articles/news/free-website-template/?

Avatar
maryfran

Community Member, 12 Posts

11 May 2010 at 4:23pm

So, I got the portfolio page to display the items in categories on the page, what I can't figure out is how to then display them on their own pages. With the code provided I am getting a page that says this page does not exist...

My set up is this PortfolioHolder >PortfolioPage >PortfolioProject

There is one PortfolioPage for each category, with a DOM on each that manages the PortfolioProjects. I think that because I added this extra layer the show function is incorrect. Is there a right way to make the link go to portfolio/web-design/id ?

Any help is appreciated - I could build this in my sleep in WordPress and I am sure this is something I am over-thinking as with the categories.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

11 May 2010 at 4:43pm

In that case, you just move everything down a level. The show() function goes on your PortfolioCategory page, and you create a _show template for the ProductCategory page, as well. Should be exactly the same code, just in a different class.

Avatar
AlfalfaAnne

Community Member, 1 Post

11 June 2010 at 2:58am

This code is great - thanks Uncle Cheese!

Question- I keep getting this error code when I try to upload my larger image:

Call to a member function write() on a non-object in /home/content/g/o/u/gourmetsquare/html/chocolachocola.com/silverstripe/sapphire/forms/FileIFrameField.php on line 209

Here's what I found on line 209 - $this->form->getRecord()->write();

Help please?

Avatar
paul.mcilwaine

Community Member, 21 Posts

29 July 2010 at 6:23pm

Did this error ever get fixed ? Im running into it now, seems to only happen when creating a new record seems fine afterwards though.

Go to Top