Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Product Portfolio

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 3684 Views
  • animasola
    Avatar
    Community Member
    121 Posts

    Product Portfolio Link to this post

    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!

  • UncleCheese
    Avatar
    4085 Posts

    Re: Product Portfolio Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Product Portfolio Link to this post

    I would also add:

    _config.php

    SortableDataObject::add_sortable_class('PortfolioItem');

  • maryfran
    Avatar
    Community Member
    12 Posts

    Re: Product Portfolio Link to this post

    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/?

  • maryfran
    Avatar
    Community Member
    12 Posts

    Re: Product Portfolio Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Product Portfolio Link to this post

    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.

  • AlfalfaAnne
    Avatar
    Community Member
    1 Post

    Re: Product Portfolio Link to this post

    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?

  • paul.mcilwaine
    Avatar
    Community Member
    21 Posts

    Re: Product Portfolio Link to this post

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

    3684 Views
Page: 1 2
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.