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.

Customising the CMS /

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

Holders within Holders


Go to End


4 Posts   1525 Views

Avatar
trevwilcox

Community Member, 7 Posts

15 April 2009 at 2:00am

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

Avatar
bummzack

Community Member, 904 Posts

15 April 2009 at 5:10am

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

Avatar
trevwilcox

Community Member, 7 Posts

15 April 2009 at 12:26pm

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

Avatar
trevwilcox

Community Member, 7 Posts

15 April 2009 at 12:49pm

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!