Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Holders within Holders

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

Page: 1
Go to End
Author Topic: 762 Views
  • trevwilcox
    Avatar
    Community Member
    7 Posts

    Holders within Holders Link to this post

    Hi all

    I'm brand new to silverstripe, but have been cramming in tons of info thanks to this forum. I've even ALMOST got my site going bar this one problem. Following on from Tutorial 2's "Staff Section", I'm trying to create a product section in a similar vain.

    The basic idea was:

    PRODUCTS (Product Category Holder)
    PRODUCT CATEGORIES
    PRODUCTPAGE

    The idea being that user would click on main products link, it would take them to a page listing all the categories of products available (possibly even with a picture), and then when user clicks on desired category, they'd get a list of all the products within that category.

    So...

    Adapting the code from Tutorial 2, I came up with 3 php files, code as follows:

    <?php

    class ProductCatsHolder extends Page {
    static $db = array(
    );
    static $has_one = array(
    );
       
    static $allowed_children = array('ProductCats');
    }

    class ProductCatsHolder_Controller extends Page_Controller {
       
    }

    ?>

    <?php

    class ProductCats extends Page {
    static $db = array(
    );
    static $has_one = array(
    'Photo' => 'Image'
    );

    static $allowed_children = array('ProductPage');
    }

    class ProductCats_Controller extends Page_Controller {
       
    }
    ?>

    <?php

    class ProductPage extends Page {
    static $db = array(
    );
    static $has_one = array(
    'Photo' => 'Image'
    );
       
    function getCMSFields() {
    $fields = parent::getCMSFields();
       
    $fields->addFieldToTab("Root.Content.Images", new ImageField('Photo'));
       
    return $fields;
    }
    }

    class ProductPage_Controller extends Page_Controller {
       
    }
    ?>

    And this actually worked fine... with breadcrumbs and all. I could upload an image on the product pages, though they wouldn't show. Which I then figured might have been a CSS issue not set properly according to what I'd done.

    Then I moved on to the next part of Tutorial 2, which was to create the associated .ss files. And as soon as I did, the whole product section crashed and burned. I didn't even get to do all the .ss files... it crashed and burned after I did the following for ProductCatsHolder.ss:

    <% include Menu2 %>

    <div id="Content" class="typography">
    <% include Breadcrumbs %>
    $Content

    <ul id="ProductList">
    <% control Children %>
    <li>
    <div class="productcatname"><a href="$Link">$Title</a></div>
    <div class="productcatphoto">$Photo.SetWidth(50)</div>
    <div class="productcatdescription"><p>$Content.FirstSentence</p></div>
    </li>
    <% end_control %>
    </ul>
    </div>

    I don't know if I'm giving enough information - but any help is very much appreciated.

    Thanks!
    Trevor

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Holders within Holders Link to this post

    Hi Trevor

    Hm. On first sight I can't spot any errors in your code. However, I was wondering how anybody would add a Photo to a "ProductCats" Page, since the getCMSFields() method isn't implemented there.
    Other than that, everything looks fine... I guess you'll have to be a bit more specific what "it crashed and burned" means. Did you get any meaningful error messages? What happened exactly?

    Best - Roman

  • trevwilcox
    Avatar
    Community Member
    7 Posts

    Re: Holders within Holders Link to this post

    Thanks for the reply Roman.

    I've since found this thread (http://www.silverstripe.org/data-model-questions/show/258030#post258030) linking to http://allentrading.co.nz/die-cast-toys/

    I've half abandoned my original idea in favour of this type of catalogue setup. I just have no idea how to do it without manually making tables in HTML on each page.

    Trev

  • trevwilcox
    Avatar
    Community Member
    7 Posts

    Re: Holders within Holders Link to this post

    Duh! The solution had been staring at me in the face all along - the e-commerce module! I don't need the actual e-commerce bits - only want to display products in certain categories. But that looks pretty easy to do now.

    Thanks!

    762 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.